不能多次写入同一个端口(pyserial) [英] Can't write multiple times to same port (pyserial)

查看:53
本文介绍了不能多次写入同一个端口(pyserial)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已解决:dsrdtr=True 不应该用于软件,只能用于正在使用的硬件

Solved: dsrdtr=True shouldn't have been used for software, only on the hardware being used

我正在尝试将电报写入串行端口,并且可以成功发送.如果我发送不止一个没有任何反应.在成功接收到第一个电报时必须关闭脚本.

Hi I'm trying to write telegrams to serial port and can send one successfully. If I send more than one nothing happens. The script has to be closed at which point the first telegram is successfully received.

制造商建议在电报之间间隔 50 毫秒,即使间隔超过 5 秒,它仍然会失败.

The manufacturer suggests a break of 50ms between telegrams, even with breaks >5s it still fails.

s = serial.Serial(
port='COM3',
baudrate=9600,
parity=serial.PARITY_ODD,
stopbits=serial.STOPBITS_ONE,
timeout=0,
bytesize=serial.SEVENBITS,
dsrdtr=True             
)

buttonUP=b'\x54\x30\x34\x0D'

s.write(buttonUP)
time.sleep(0.05)
s.write(buttonUP)
time.sleep(0.05)
s.write(buttonUP)

如果我写了

s.write(buttonUP)
s.close()
s.open()
s.write(buttonUP)

这是可行的,但由于关闭/打开导致的延迟对于我们的要求来说太长了.

This works but the delay caused by closing/opening is too long for our requirements.

有人对可能导致此问题的原因有任何想法吗?非常感谢您的帮助

Does anyone have any ideas about what could be causing this issue? Thank you very much for your help

推荐答案

如果您尝试使用 readline() 函数从端口读取,这可能是一个问题,您不这样做't 用换行符终止每条消息.尝试将其更改为

If you are trying to read from the port by using a readline() function, it might be a problem that you don't terminate each message with a newline. Try changing it to

buttonUP=b'\x54\x30\x34\x0D\n' 

您可以阅读更多这里

这篇关于不能多次写入同一个端口(pyserial)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆