Control a COGNEX Barcode Scanner via RS-232

622 Views Asked by At

I have a RS-232 Barcode scanner. I'm using a serial port to communicate with the instrument, I don't have a problem communicating with the instrument, the problem I have is that every time I read the scanner response, exist this "extra characters" that I need to remove from my string. I think could be because the way I'm reading the response?

This is what I read from the scanner: "b'0937J094ZP'" When in theory, the scanner should read only "0937J094ZP"

Do not why the string has an "b" and " ' "

cognex = serial.Serial('COM4', 9600, timeout=5)
time.sleep(.5)
cognex.write(b'0')
time.sleep(1)
response = cognex.read(10)
cognexsn = response
print(cognexsn)
>>>b'0937J094ZP'

Thanks for stop by and your help is appreciate.

0

There are 0 best solutions below