I've been writing a script that pulls data from a serial device at regular intervals. I've got everything working, except that the responses I receive from the device contain many question marks. Since the formatting is correct on what I'm getting according to documentation for the device (correct number of characters, placement of commas etc.) I'm pretty sure that my code is interpreting the characters wrong somehow. Here is my code:
import serial, time
ser = serial.Serial(
'/dev/cu.usbserial',
baudrate = 9600,
bytesize = 8,
timeout = 3,
stopbits = serial.STOPBITS_ONE,
parity = serial.PARITY_ODD,
)
if(ser.isOpen() == False):
ser.open()
print 'Enter your commands below.\r\nInsert "exit" to leave the application.'
while 1 :
# get keyboard input
input = raw_input(">> ")
if input == 'exit':
ser.close()
exit()
else:
ser.write(input + chr(13) + chr(10))
out = ''
time.sleep(3)
while ser.inWaiting() > 0:
out += ser.read(1)
if out != '':
print '>>' + out
and sample output from the user manual:
ENTER COMMAND? KRDG?
RESPONSE: +273.15
ENTER COMMAND? *IDN?
RESPONSE: LSCI,MODEL331S,123456,020399
and what the output looks like:
COMPUTERNAME$ python serialTest.py
Enter your commands below.
Insert "exit" to leave the application.
>> KRDG?
?>??4?2?8
>> KRDG?
?>??4?2??
>> *IDN?
?>L?CI,?O?EL??1?,??????,12?4?7
Of specific note is that fact that on the last line in my output, the '>>' from my code which is concatenated with the output read from the serial device is changed to '?>', which is a little perplexing. For reference, the manual specifies that ports should be configured as follows:
*Baud Rate: 9600 *Character Bits: 1 Start, 7 Data, 1 Parity, 1 Stop *Parity: Odd *Terminators: CR(0DH) LF(0AH)
I've tried every reasonable permutation of port settings. It looks like it might be a parity issue (as I've seen other with similar looking output which is attributed to parity errors online), but I've tried all available parity settings. I'm wondering if it might be something to do with the start bit, since this is the only thing I'm unable to control via Pyserial.
Sorry for the long winded post, and thanks in advance for any/all help!