我正在尝试通过微享通过 UART 命令在 Raspberry Pi 3 和条码扫描器之间进行通信,但我总是收到空白响应。该命令长 9 位,这可能是问题所在。我还注意到在打印
scanning_command
之后,第一位被忽略了......?
按照条形码扫描器的文档我已经尝试了几种不同的python脚本来运行命令,但总是收到串行输出
b''
。我没有使用 Raspberry Pi 的经验,非常感谢任何帮助。
脚本:
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())