I have a program that is communicating with another machine that sends (or is supposed to send) ASCII characters, the code below is how I write and read code to the machine. def writeCode(send): address = 'COM4'
ser = serial.Serial(
port=address,
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
ser.close()
ser.open()
message=send
message=message+str(checksum(message))+"\r"
ser.write(bytes(message, "ascii"))
time.sleep(1) # give com time to respond
out=''
while ser.inWaiting() > 0:
out+=ser.read(1).decode('ascii')
if out != '':
ser.close()
return out
I get the error on the "out+=ser.read(1).decode('ascii') line. I looked online but most of the advice seems to be based around if you aren't using the proper decoding library. However, for this machine I know that the ASCII library should be correct as it says so in the manual (https://www.idealvac.com/files/manuals/PfeifferGauge_MPT200_1.pdf page 16). What am I missing here? Any help would be much appreciated.