通过此代码,串口未返回任何数值
Ports.Add("COM8")
With Ports("COM8")
.Close()
.BaudRate = 921600
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
.Encoding = Encoding.Unicode
.Open
End With
Ports("COM8").Write("BB 00 28 00 00 28 7E ")
Dim s As String
For i As Integer = 1 To 30
s = Ports("COM8").ReadExisting()
Output.Show(s)
Next
Ports("COM8").Close()
此主题相关图片如下:代码.png
通过串口调试软件是可以获取到返回数据
返回数据需要使用16进制显示
需要向串口发送此代码才能读取数据:“BB 00 28 00 00 28 7E ”
此主题相关图片如下:串口调试软件.png
Dim Val() As Byte = New Byte() {BB,00, 28, 00, 00, 28, 7E}
Ports("COM8").Write(Val, 0, Val.Length)
[此贴子已经被作者于2024/12/31 16:57:51编辑过]
此主题相关图片如下:微信截图_20241231164342.png
调整后代码(可以正常发送命令)Ports.Add("COM8")
With Ports("COM8")
.Close()
.Parity = Parity.None
' .Handshake = Handshake.None
.StopBits = StopBits.One
.BaudRate = 921600
.DataBits = 8
' .ReadBufferSize() = 4096
' .WriteBufferSize() = 2048
.Encoding = Encoding.Unicode
.Open
End With
Dim zl1 As UInteger = HexToDec( "BB")
Dim zl2 As UInteger = HexToDec("00")
Dim zl3 As UInteger = HexToDec("27")
Dim zl4 As UInteger = HexToDec( "00")
Dim zl5 As UInteger = HexToDec( "03")
Dim zl6 As UInteger = HexToDec("22")
Dim zl7 As UInteger = HexToDec( "FF")
Dim zl8 As UInteger = HexToDec( "FF")
Dim zl9 As UInteger = HexToDec( "4A")
Dim zl10 As UInteger = HexToDec("7E")
Dim Val() As Byte = New Byte() {zl1, zl2, zl3, zl4, zl5, zl6, zl7, zl8, zl9, zl10}
Ports("COM8").Write(Val, 0, Val.Length)
Ports("COM8").Close()