I have a USB Barcode Scanner and plug into my Ubuntu PC. The Scanner is working properly, since when I used it, it will output the result of barcode on every cursor I put (such as terminal, vscode, etc.) but the received_string variable is always empty. There are no erros. Do you have any idea?
import serial
import time
SerialObj = serial.Serial("/dev/ttyS0", 9600)
time.sleep(3)
SerialObj.timeout(3)
print("Starting")
while True:
received_string = SerialObj.readline()
print("Received: ", received_string)
SerialObj.close()
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''.
UPDATE
here are output when i did sudo dmesg | tail without plug the scanner in
[85989.229043] usb 1-10.1: USB disconnect, device number 15
[85995.490066] usb 1-10.1: new full-speed USB device number 16 using xhci_hcd
[85995.606922] usb 1-10.1: not running at top speed; connect to a high speed hub
[85995.608536] usb 1-10.1: New USB device found, idVendor=060e, idProduct=7800, bcdDevice= 2.54
[85995.608538] usb 1-10.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[85995.608539] usb 1-10.1: Product: USB Barcode Scanner HID
[85995.608540] usb 1-10.1: Manufacturer: USB Barcode Scanner HID
[85995.615660] input: USB Barcode Scanner HID USB Barcode Scanner HID as /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10.1/1-10.1:1.0/0003:060E:7800.0010/input/input43
[85995.674330] hid-generic 0003:060E:7800.0010: input,hidraw6: USB HID v1.01 Keyboard [USB Barcode Scanner HID USB Barcode Scanner HID] on usb-0000:00:14.0-10.1/input0
[87124.076792] usb 1-10.1: USB disconnect, device number 16
and here are output when i did sudo dmesg | tail with plug the scanner in
[85995.674330] hid-generic 0003:060E:7800.0010: input,hidraw6: USB HID v1.01 Keyboard [USB Barcode Scanner HID USB Barcode Scanner HID] on usb-0000:00:14.0-10.1/input0
[87124.076792] usb 1-10.1: USB disconnect, device number 16
[89435.842374] usb 1-10.2: new full-speed USB device number 17 using xhci_hcd
[89435.963057] usb 1-10.2: not running at top speed; connect to a high speed hub
[89435.964477] usb 1-10.2: New USB device found, idVendor=060e, idProduct=7800, bcdDevice= 2.54
[89435.964479] usb 1-10.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[89435.964480] usb 1-10.2: Product: USB Barcode Scanner HID
[89435.964481] usb 1-10.2: Manufacturer: USB Barcode Scanner HID
[89435.970627] input: USB Barcode Scanner HID USB Barcode Scanner HID as /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10.2/1-10.2:1.0/0003:060E:7800.0011/input/input44
[89436.030645] hid-generic 0003:060E:7800.0011: input,hidraw6: USB HID v1.01 Keyboard [USB Barcode Scanner HID USB Barcode Scanner HID] on usb-0000:00:14.0-10.2/input0