使用 SerialPort 将整数发送到 COM1
我在将整数发送到串行端口时遇到困难...我正在尝试这样的东西,它运行良好,但我没有在端口上拾取任何东西。
Private Sub fireToPort()
Dim sPort As New SerialPort("COM1", 56000, Parity.None, 8, StopBits.One)
sPort.Open()
sPort.Write(New Byte() {Hex(1), 255}, 0, 0)
sPort.Close()
End Sub
有什么建议吗?
I'm having difficulty sending an integer to a serial port... I'm trying stuff like this, which run fine but I'm not picking anything up at the port.
Private Sub fireToPort()
Dim sPort As New SerialPort("COM1", 56000, Parity.None, 8, StopBits.One)
sPort.Open()
sPort.Write(New Byte() {Hex(1), 255}, 0, 0)
sPort.Close()
End Sub
Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
sPort.Write 的最后一个参数不应该是您要发送的字节数吗?
例如
Shouldn't the last argument to sPort.Write be the number of bytes you want to send?
e.g.
获取Mark Russinovich(前 SysInternals)的 PortMon。
这将帮助您确认端口是否已打开、正确配置并写入。
您应该会看到进程执行
IRP_MJ_WRITE
操作,结果为SUCCESS
。如果一切正常,那么问题可能是您连接到 COM1 的任何内容都需要不同的波特率。
Get hold of PortMon By Mark Russinovich (formerly of SysInternals).
This will help you confirm that the port is being opened, configured correctly and written to.
You should see your process making an
IRP_MJ_WRITE
operation with a result ofSUCCESS
.If that is all working then the issue is probably that whatever you have attached to COM1 is expecting a different baud rate.
试试这个
Try this
最后一个参数应该是
255
,这是您将发送的数据的长度。The last argument is supposed to be
255
which is the length of data that you will send.