Reputation: 133
Ok, so I am a complete noob to pySerial. I am trying to communicate to a piece of lab equipment, but am having trouble just sending the STX (Start of Text) command. So far, my basic code looks like:
ser = serial.Serial(0, 19200, timeout=1,parity=serial.PARITY_ODD, rtscts=0)
ser.write(0x02) #ASCII STX is 0x2 in hex
But when I look at the 232 data on my scope, the STX I'm trying to send, doesn't look anything like a STX command sent in Hperterminal.
Any ideas? I am sure this is incredibly straight forward and I am just overlooking something trivial.
Thanks!
Upvotes: 2
Views: 4872
Reputation: 14993
The write function in serial class accepts bytes or strings. You are passing an integer so the result is unknown, maybe is casting it to str so you are sending the char '2'.
The correct way to do it is :
ser = serial.Serial(0, 19200, timeout=1,parity=serial.PARITY_ODD, rtscts=0)
ser.write(chr(0x02)) #ASCII STX is 0x2 in hex
Upvotes: 6
Reputation: 104168
Are you sure that the same configuration is used for HyperTerminal and PySerial. You should make sure that the following are same:
Upvotes: 0