python – Why does sending this 9-bit command to barcode scanning module via UART from Raspberry Pi 3 fail?

I am trying to communicate between a Raspberry Pi 3 and barcode scanner by Waveshare via a UART command, but I always receive a blank response. The command is 9-bits long, which might be the issue. I also noticed after printing the scanning_command , that the first bit is ignored…?

Following the barcode scanner’s documentation I’ve tried several varying python scripts to run the command, but always receive the serial output b''. I am not experienced with Raspberry Pi and would appreciate any help.

Script:

import serial

# Define the serial port and baud rate
serial_port="/dev/ttyS0"
baud_rate = 9600

# Define the scanning command
scanning_command = b'\x7E\x00\x08\x01\x00\x02\x01\xAB\xCD'  

# Open the serial connection
ser = serial.Serial(serial_port, baud_rate)

# Send the scanning command
ser.write(scanning_command)

response = ser.read(7)  # Read 7 bytes response
print("Response:", response.hex())

Read more here: Source link