VB Mscomm 无法接收
代码如下PrivateSubForm_Load()MSComm1.CommPort=1MSComm1.Settings="19200,N,8,2"MSComm1.Inpu...
代码如下
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "19200,N,8,2"
MSComm1.InputLen = 0
MSComm1.InputMode = comInputModeText
MSComm1.PortOpen = True
If MSComm1.PortOpen = True Then
Label1.Caption = "打开串口"
End If
End Sub
Private Sub MSComm1_OnComm()
If MSComm1.CommEvent = comEvReceive Then
getData = MSComm1.Input
getData_len = UBound(getData)
For J = 0 To getData_len
read = read & Right("00" + Hex(getData(J)), 2)
Next J
Text2 = read
End If
End Sub
接收Modbus协议发送过来的数据,tex2无法显示出来,问题在哪里呢?可以有偿解决!谢谢 展开
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "19200,N,8,2"
MSComm1.InputLen = 0
MSComm1.InputMode = comInputModeText
MSComm1.PortOpen = True
If MSComm1.PortOpen = True Then
Label1.Caption = "打开串口"
End If
End Sub
Private Sub MSComm1_OnComm()
If MSComm1.CommEvent = comEvReceive Then
getData = MSComm1.Input
getData_len = UBound(getData)
For J = 0 To getData_len
read = read & Right("00" + Hex(getData(J)), 2)
Next J
Text2 = read
End If
End Sub
接收Modbus协议发送过来的数据,tex2无法显示出来,问题在哪里呢?可以有偿解决!谢谢 展开
展开全部
首先,你确定是19200,N,8,2;而不是N,7,2;另外,你那种接收方式应设置串口接收模式为二进制而不是文本模式。你可getData = MSComm1.Input后插入一句tex2=getData测试下。
追问
你好,通讯格式改为了 和下位机一样的9600,N,8,1,接收模式改为了二进制模式,
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
Text2.Text = MSComm1.Input
End Select
这样写了后 text2显示了1个字节的乱码
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询