连接到通讯端口时,我在文本框中收到垃圾值是因为我的比特率错误,那么我如何识别正确的比特率?我正在使用 VB6 从连接微控制器的通信端口获取数据
在这里,我编写了用于以 19200 的比特率接收数据的代码。我只是想知道如何避免垃圾值,但似乎我的微控制器的比特率是 19200
Private Sub Command1_Click()
If (MSComm1.PortOpen = False) Then opening port
MSComm1.PortOpen = True
End If
Command1.Enabled = False
Command2.Enabled = True
End Sub
Private Sub Command2_Click()
If (MSComm1.PortOpen = True) Then
MSComm1.PortOpen = False
End If
Command1.Enabled = True
Command2.Enabled = False
End Sub
Private Sub Form_Load()
With MSComm1
.CommPort = 1
.RThreshold = 1
.RTSEnable = True
.Settings = "19200,N,8,1"
.InputLen = 1000
.SThreshold = 1
.PortOpen = True
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
If (MSComm1.PortOpen = True) Then
MSComm1.PortOpen = False
End If
End Sub
Private Sub MSComm1_OnComm()
Dim Buffer As String
Select Case MSComm1.CommEvent
Case comEvReceive
Text1.Text = " "
Buffer = MSComm1.Input
Text1.Text = Text1.Text & Buffer
End Select
End Sub