Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共9 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:如何获取串口数据

1楼
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

Ports("COM8").Close()
图片点击可在新窗口打开查看此主题相关图片如下:代码.png
图片点击可在新窗口打开查看
2楼
wanglin3033 发表于:2024/12/31 15:41:00
通过串口调试软件是可以获取到返回数据

返回数据需要使用16进制显示

需要向串口发送此代码才能读取数据:“BB 00 28 00 00 28 7E ”
图片点击可在新窗口打开查看此主题相关图片如下:串口调试软件.png
图片点击可在新窗口打开查看
3楼
wanglin3033 发表于:2024/12/31 15:50:00
请老师指点,我这个代码怎么编辑 
4楼
有点蓝 发表于:2024/12/31 16:11:00
到监视器里接收:http://www.foxtable.com/webhelp/topics/1967.htm
5楼
wanglin3033 发表于:2024/12/31 16:24:00
向串口用16进制发送指令 这个代码不知道怎么编辑

6楼
有点蓝 发表于:2024/12/31 16:31:00
http://www.foxtable.com/webhelp/topics/1977.htm

Dim Val() As Byte = New Byte() {BB,00, 28, 00, 00, 28, 7E}
Ports
("
COM8").Write(Val0Val.Length)
[此贴子已经被作者于2024/12/31 16:57:51编辑过]
7楼
wanglin3033 发表于:2024/12/31 16:44:00

图片点击可在新窗口打开查看此主题相关图片如下:微信截图_20241231164342.png
图片点击可在新窗口打开查看
8楼
有点蓝 发表于:2024/12/31 16:58:00
Dim Val() As Byte = New Byte() {BB,00, 28, 00, 00, 28, 7E}
Ports
("
COM8").Write(Val0Val.Length)
9楼
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()

共9 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .03125 s, 2 queries.