PySerial - 无法发送 STX
好吧,所以我对 pySerial 完全是菜鸟。我正在尝试与一台实验室设备进行通信,但在发送 STX(文本开始)命令时遇到问题。到目前为止,我的基本代码如下所示:
ser = serial.Serial(0, 19200, timeout=1,parity=serial.PARITY_ODD, rtscts=0)
ser.write(0x02) #ASCII STX is 0x2 in hex
但是当我查看示波器上的 232 数据时,我尝试发送的 STX 看起来与 Hperterminal 中发送的 STX 命令完全不同。
有什么想法吗?我确信这是非常简单的,我只是忽略了一些微不足道的事情。
谢谢!
Ok, so I am a complete noob to pySerial. I am trying to communicate to a piece of lab equipment, but am having trouble just sending the STX (Start of Text) command. So far, my basic code looks like:
ser = serial.Serial(0, 19200, timeout=1,parity=serial.PARITY_ODD, rtscts=0)
ser.write(0x02) #ASCII STX is 0x2 in hex
But when I look at the 232 data on my scope, the STX I'm trying to send, doesn't look anything like a STX command sent in Hperterminal.
Any ideas? I am sure this is incredibly straight forward and I am just overlooking something trivial.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Serial 类中的 write 函数接受字节或字符串。您正在传递一个整数,因此结果未知,可能会将其转换为 str,以便您发送字符“2”。
正确的做法是:
The write function in serial class accepts bytes or strings. You are passing an integer so the result is unknown, maybe is casting it to str so you are sending the char '2'.
The correct way to do it is :
您确定超级终端和 PySerial 使用相同的配置吗?您应该确保以下各项相同:
Are you sure that the same configuration is used for HyperTerminal and PySerial. You should make sure that the following are same: