[Python] Datalogic GD4400 Scanner Outputs Encoded Data via CH340 Serial Interface

Discussão em 'Python' iniciado por Stack, Maio 17, 2025.

  1. Stack

    Stack Membro Participativo

    Problem Description I have a Datalogic GD4400 barcode scanner connected to a Raspberry Pi/Linux system via a CH340 USB-to-Serial adapter. When scanning barcodes, the scanner outputs encoded data instead of plain ASCII text.

    Hardware Setup Datalogic GD4400 barcode scanner CH340 breakout board Connection: PIN 6 (TX) → CH340 RX, PIN 5 (RX) → CH340 TX, PIN 4 (GND) → CH340 GND, PIN 7 (VCC) → 5V

    What I'm Seeing When I scan a barcode with text "X0043FEWFX", I get this binary output instead of plain text:

    Received data (length: 11 bytes):
    HEX: EA F6 76 96 36 D5 45 CD 3D 95 00


    My Python code:

    import serial
    import time
    import sys

    def listen_to_scanner(device_path="/dev/ttyUSB0", baud_rate=9600):
    try:
    with serial.Serial(
    port=device_path,
    baudrate=baud_rate,
    bytesize=serial.EIGHTBITS,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    timeout=0.1,
    rtscts=True
    ) as ser:
    print(f"Connected to {device_path} at {baud_rate} baud")
    print("Listening for scanner data... (Press Ctrl+C to stop)")

    while True:
    try:
    data = ser.read(64)
    if len(data) > 0:
    print(f"\nReceived data (length: {len(data)} bytes):")
    print(f"HEX: {' '.join([f'{b:02X}' for b in data])}")
    try:
    ascii_str = data.decode('ascii')
    print(f"ASCII: {ascii_str}")
    except UnicodeDecodeError:
    print("*** Non-ASCII data received ***")
    except serial.SerialException as e:
    print(f"Serial error: {e}")
    break
    time.sleep(0.01)
    except serial.SerialException as e:
    print(f"Error with serial port: {e}")
    except KeyboardInterrupt:
    print("\nProgram terminated by user")

    def main():
    listen_to_scanner()

    if __name__ == "__main__":
    main()


    What I've Tried

    Changed Interface Settings: I've tried configuring the scanner to use "RS-232 Standard" interface using programming barcodes from the manual.

    USB Mode Works: When I connect the scanner directly via USB and configure it for USB HID (keyboard) mode, it correctly outputs plain ASCII, but I need it to work with the CH340 serial connection.

    Baud Rate: I've verified the baud rate is correctly set to 9600.

    Physical Connections: I've verified all pins are correctly connected.

    Could you please help me where i am doing wrong ? Do i need a specific decoding code for the scanner brand ?

    Continue reading...

Compartilhe esta Página