Working on send commands to a temperature monitor. Fiddled a bit and got the following. Not sure what it means or how to convert to usable data (if there is any). Any ideas?
import serial
ser.close()
ser = serial.Serial(port='COM5',\
baudrate=9600,\
parity=serial.PARITY_NONE,\
stopbits=serial.STOPBITS_ONE,\
bytesize=serial.EIGHTBITS,\
timeout=2)
print("connected to: " + ser.portstr)
#ser.close()
count=1
while True:
#line = ser.readline()
#print(str(count) + str(': ') + str(line))
#count = count+1
cmd = input("Enter command or 'exit':")
# for Python 3
if cmd == 'exit':
ser.close()
quit()
else:
ser.write((cmd+'\r\n').encode('utf-8'))
out = ser.read()#.decode('utf-8')
print(out)#.decode('utf-8'))
ser.close()
Output is
connected to: COM5
Enter command or ‘exit’: KRDG? 1
b’\xab’
Just a note that Serial.read has a default read size of 1.
Maybe try adding a timeout to the Serial setup and doing a longer
read. You might get a more intelligible result. BTW do you know about
what temperature you expect to get?
There’s also Serial.read_until which could be useful if you’re
expecting a “line” of data as a response.
But Matthew’s point is important: what does the documentation say you
should get?
Alexander, my man!! I really should have caught the parity and byte params. Matched them up in the device manager, too. Now to get it to return a string, rather than single characters. Thanks bud!!