I have a USB Barcode Scanner and plug into my Ubuntu PC. The Scanner is work propperly, since when I used it, it will output the reuslt of barcode on every cursor i put (such as terminal, vscode, etc.) but the received_string variable is always empty. The script is not give any error. Do you have any idea?

import serial
import time

SerialObj = serial.Serial("/dev/ttyS0", 9600)




while True:
    received_string = SerialObj.readline()
    print("Received: ", received_string)


I want to retrieve the data using Serial with the code, so the variable received_string will be assign with the value of the scanner data, but I always get Received: b''.

New contributor

Arif Agustyawan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.