开发者

I have problem in sending a data via serial port using python

开发者 https://www.devze.com 2023-03-06 02:14 出处:网络
I am trying to ON my application by sending a command called ON via serial port using PYTHON..I 开发者_如何学运维already wrote a program in my controller that when ever i receive a command via serial

I am trying to ON my application by sending a command called ON via serial port using PYTHON..I 开发者_如何学运维already wrote a program in my controller that when ever i receive a command via serial port it has to perform some operations.

this is my code:

import serial
s=serial.Serial(0)

s.write('^ON') #this is my string to ON

s.close()

but the thing is it can able to read the data send by the controller but it cant able to write the data in to the controller


Your microcontroller might be expecting "hardware flow control", using the RTS/CTS or DSR/DTR pins on the connector. That is, to receive, it may expect the transmitter to "raise" a certain pin, to alert the controller to prepare for a transmission. This hardware flow control seems to be getting less common, and so is disabled by default in PySerial.

Try this line:

s=serial.Serial(0, rtscts=True)

Or, if that doesn't work, try:

s=serial.Serial(0, dsrdtr=True)

If neither works, try this:

s=serial.Serial(0, rtscts=True, dsrdtr=True)

I hope one of those works for you! (It might not: a lot of hobby projects' cables hard-wire the flow control pins. But, we'll see!)

0

精彩评论

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