各位前辈,大家好,我是初级菜鸟,想用VB发送1个字节到我的单片机,于是在FORM中添加了一个命令控件,
代码如下,确无法运行,总是提示实时错误442,希望能够得到大家的帮助,另外也希望有兴趣的朋友一起讨论,谢谢!Private Sub CmdTest_Click()
If MSComml.PortOpen = False Then
MSComm1.CommPort = 1
MSComm1.Settings = "56000,n,8,1"
MSComm1.PortOpen = True
MSComm1.OutputMode = comOutputModeBinary
MSComm1.InputMode = comInputModeBinaryElse
MsgBox "串口已被占用", vbAbortRetryIgnore, "错误提示"
End IfMSComm1.OutBufferCount = 0
MSComm1.InBufferCount = 0Dim ByteArray() As Byte
ReDim ByteArray(1)
ByteArray(0) = 51
MSComm1.Output = ByteArrayEnd Sub
代码如下,确无法运行,总是提示实时错误442,希望能够得到大家的帮助,另外也希望有兴趣的朋友一起讨论,谢谢!Private Sub CmdTest_Click()
If MSComml.PortOpen = False Then
MSComm1.CommPort = 1
MSComm1.Settings = "56000,n,8,1"
MSComm1.PortOpen = True
MSComm1.OutputMode = comOutputModeBinary
MSComm1.InputMode = comInputModeBinaryElse
MsgBox "串口已被占用", vbAbortRetryIgnore, "错误提示"
End IfMSComm1.OutBufferCount = 0
MSComm1.InBufferCount = 0Dim ByteArray() As Byte
ReDim ByteArray(1)
ByteArray(0) = 51
MSComm1.Output = ByteArrayEnd Sub
解决方案 »
- 为什么使用MSFlexgrid的textmartrix方法时总是出错: 下标越界?
- 急问,在使用笔记本触摸板时,如何用VB程序记录下手指移动的次数
- VB如何制作电子地图
- 一个TOOLBar的奇怪问题
- DataGrid控件是否可以选多条记录
- 转卖计算机书籍
- 用VB发送邮件时,有什么不办法不出现登陆框,直接用代码登陆?
- 请问WIN2000下IME是怎么向RichTextBox发送字符的?或者说2000下怎么拦截RichTextBox的WM_IME_CHAR消息?
- VB控制Datamax打印条码
- 关于WillChangeRecordset事件中的adStatus参数
- VB如何实现每隔1分钟运行某个程序,该程序运行到59秒后,自动关闭
- vb autocad GetReal
Private Sub CmdTest_Click()
'If MSComml.PortOpen = False Then'MSComml错,应为MSComm1
If MSComm1.PortOpen = False Then
MSComm1.CommPort = 1
MSComm1.Settings = "57600,n,8,1"
MSComm1.InputMode = comInputModeBinary
'MSComm1.OutputMode = comOutputModeBinary'没OutputMode属性
MSComm1.PortOpen = True
End If
MSComm1.OutBufferCount = 0
MSComm1.InBufferCount = 0
Dim ByteArray() As Byte
ReDim ByteArray(0) '定义ByteArray(1),有2字节
ByteArray(0) = 51
MSComm1.Output = ByteArray
End Sub
Private Sub CmdTest_Click()
'If MSComml.PortOpen = False Then'MSComml错,应为MSComm1
If MSComm1.PortOpen = False Then
MSComm1.CommPort = 1
MSComm1.Settings = "57600,n,8,1"
MSComm1.InputMode = comInputModeBinary
'MSComm1.OutputMode = comOutputModeBinary'没OutputMode属性
MSComm1.PortOpen = True
End If
MSComm1.OutBufferCount = 0
MSComm1.InBufferCount = 0
Dim ByteArray() As Byte
ReDim ByteArray(0) '定义ByteArray(1),有2字节
ByteArray(0) = 51
MSComm1.Output = ByteArray
End Sub