简体   繁体   中英

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

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!)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM