I wrote code to simulate some of the hardware that I work with, and uploaded it to the Arduino board. This code works. I know this because I get the expected response from HyperTerminal.
However, when I try to connect using PySerial, the connection is not an error, but I do not receive a response to the commands that I send.
Why could this be?
Python code
import serial def main(): sp = serial.Serial() sp.port = 'COM4' sp.baudrate = 19200 sp.parity = serial.PARITY_NONE sp.bytesize = serial.EIGHTBITS sp.stopbits = serial.STOPBITS_ONE sp.timeout = 0.5 sp.xonxoff = False sp.rtscts = False sp.dsrdtr = False sp.open() sp.write("GV\r\n".encode('ascii')) value = sp.readline() print value sp.write("GI\r\n".encode('ascii')) value = sp.readline() print value sp.close() if __name__ == "__main__": main()
NB: the Arduino code sends back \r\n at the end of the response to the command.
HyperTerminal Configuration:

Edit
I found that if I increase the timeout to 10 seconds and add sp.readline() before sending anything, then I get answers to both commands.
How long is a hardware handshake usually between PySerial and Arduino or USB RS-232 ports?
Matt ellen
source share