在vb中如何实现串口数据的读取

2024-12-21 08:03:34
推荐回答(1个)
回答1:

未见串口打开语句,你的MSComm1_OnComm事件代码有些冲突,你究竟想以二进制接收还是以ASCII码接收:
Private Sub MSComm1_OnComm()
''
Dim Buffer As Variant
Select Case MSComm1.CommEvent
Case comEvReceive
MSComm1.InputLen = 0
MSComm1.InputMode = comInputModeBinary‘此处及后3句用前2句不用后2句,反之亦然
Buffer = MSComm1.Input
MSComm1.InputMode = comInputModeText
Buffer = AscB(MSComm1.Input)
Text1.Text = Buffer
Case Else
End Select
''
End Sub