以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 如何获取串口数据 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=194640) |
-- 作者:wanglin3033 -- 发布时间:2024/12/31 15:38:00 -- 如何获取串口数据 通过此代码,串口未返回任何数值 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 |
-- 作者:wanglin3033 -- 发布时间:2024/12/31 15:41:00 -- 通过串口调试软件是可以获取到返回数据 返回数据需要使用16进制显示 |
-- 作者:wanglin3033 -- 发布时间:2024/12/31 15:50:00 -- 请老师指点,我这个代码怎么编辑 |
-- 作者:有点蓝 -- 发布时间:2024/12/31 16:11:00 -- 到监视器里接收:http://www.foxtable.com/webhelp/topics/1967.htm |
-- 作者:wanglin3033 -- 发布时间:2024/12/31 16:24:00 -- 向串口用16进制发送指令 这个代码不知道怎么编辑 |
-- 作者:有点蓝 -- 发布时间:2024/12/31 16:31:00 -- 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编辑过]
|
-- 作者:wanglin3033 -- 发布时间:2024/12/31 16:44:00 -- 此主题相关图片如下:微信截图_20241231164342.png |
-- 作者:有点蓝 -- 发布时间:2024/12/31 16:58:00 -- Dim Val() As Byte = New Byte() {BB,00, 28, 00, 00, 28, 7E} Ports("COM8").Write(Val, 0, Val.Length) |
-- 作者:wanglin3033 -- 发布时间:2024/12/31 18:13:00 -- 调整后代码(可以正常发送命令) 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() |