开发者

serial port: have to send \n

开发者 https://www.devze.com 2023-01-15 05:26 出处:网络
[edit] Initially I thought this was a pyserial problem but it\'s not. Basically it\'s a system problem: Sending anything over the serial port (/dev/ttyS0) would need a \"\\n\" or \"\\r\" or else it\'l

[edit] Initially I thought this was a pyserial problem but it's not. Basically it's a system problem: Sending anything over the serial port (/dev/ttyS0) would need a "\n" or "\r" or else it'll just be buffered. Below is the original question. Is it a limitation of Linux driver or is there some settings I can change?

Hello there,

I'm trying to use pyserial to write some test code. In reality I'll be transmitting binary data but that's not my problem. My problem is that: it looks like pyserial write() command will only actually send the data when it sees "\n".

Take the following c开发者_如何学Pythonode for sending pure text file.

for l in file:
    print "Sending %s" % l
    s.write( l )
    s.flush()
    time.sleep(2)

Unless I insert s.write("\n") after s.write( l ), nothing would be seen on the other side. Is there a way I can make pyserial to send whatever I want whenever I want it?

Thanks,


from the documentation for pyserial http://pyserial.sourceforge.net/pyserial_api.html that does not seem to be the case. which version are you using?

to clarify, which pySerial and which python seem to be relevant.

0

精彩评论

暂无评论...
验证码 换一张
取 消