1

I have scanner of make Datalogic Magellan 1500i. When I connect it to my machine via USB, I can use the following command to see what barcodes the scanner reads:

cat -v /dev/ttyACM0
F4009900511513^M

When we receive these scanners, we want to configure them for our purposes. This process is done by scanning barcodes provided in the manual of the scanner.

I want to do this programmatically, by sending the value of the barcodes to the scanner directly, simulating that they have been scanned. I've read some questions here and found some suggestions, but I cannot getthe scanner to react to my events.

I run the command above in one terminal, and in another I echo to the same tty device:

echo "test" > /dev/ttyACM0 

However there is nothing displayed in the terminal reading the output, and the scanner shows no signs of receiving what I send.

This is what I get from lsusb -D /dev/bus/usb/001/039

Device: ID 05f9:4002 PSC Scanning, Inc. 
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            2 Communications
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x05f9 PSC Scanning, Inc.
  idProduct          0x4002 
  bcdDevice            0.49
  iManufacturer           1 
  iProduct                2 
  iSerial                 3 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           67
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              500mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         2 Communications
      bInterfaceSubClass      2 Abstract (modem)
      bInterfaceProtocol      1 AT-commands (v.25ter)
      iInterface              4 
      CDC Header:
        bcdCDC               1.10
      CDC ACM:
        bmCapabilities       0x07
          sends break
          line coding and serial state
          get/set/clear comm features
      CDC Union:
        bMasterInterface        0
        bSlaveInterface         1 
      CDC Call Management:
        bmCapabilities       0x01
          call management
        bDataInterface          0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0010  1x 16 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0 Unused
      bInterfaceProtocol      0 
      iInterface              5 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0

This is what I see in journalctl when I unplug the device and plug it back in again:

kernel: usb 1-8: USB disconnect, device number 39
upowerd[1029]: unhandled action 'unbind' on /sys/devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8:1.1
upowerd[1029]: unhandled action 'unbind' on /sys/devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8:1.0
upowerd[1029]: unhandled action 'unbind' on /sys/devices/pci0000:00/0000:00:14.0/usb1/1-8
kernel: usb 1-8: new full-speed USB device number 40 using xhci_hcd
kernel: usb 1-8: New USB device found, idVendor=05f9, idProduct=4002, bcdDevice= 0.49
kernel: usb 1-8: New USB device strings: Mfr=1, Product=2, SerialNumber=3
kernel: usb 1-8: Product: Point of Sale Handable Barcode Scanner
kernel: usb 1-8: Manufacturer: Datalogic USA Inc.
kernel: usb 1-8: SerialNumber: E19I43871
kernel: cdc_acm 1-8:1.0: ttyACM0: USB ACM device
mtp-probe[7447]: checking bus 1, device 40: "/sys/devices/pci0000:00/0000:00:14.0/usb1/1-8"
mtp-probe[7447]: bus: 1, device: 40 was not an MTP device
snapd[748]: hotplug.go:199: hotplug device add event ignored, enable experimental.hotplug
upowerd[1029]: unhandled action 'bind' on /sys/devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8:1.1
upowerd[1029]: unhandled action 'bind' on /sys/devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8:1.0
upowerd[1029]: unhandled action 'bind' on /sys/devices/pci0000:00/0000:00:14.0/usb1/1-8

Is there any way to achieve what I'm trying to do? Am I looking in the wrong place?

Additional information update

Checking the options used for the tty yields this result:

$ stty -F /dev/ttyACM0        
speed 115200 baud; line = 0;
eof = ^A; min = 1; time = 0;
-brkint -icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke

When scanning the barcode the code ends with ^M, and searching for that leads to additional answers. I'm thinking it's perhaps related to me not sending a correct line ending when echoing to the device, but I can't figure out how to change the accepted line ending or how to send the correct line ending.

Further debugging

Tried setting eol, eof and enabling icrnl:

stty eol 'x' eof 'x' -F /dev/ttyACM0 115200 -brkint icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke

The latter now prints a new row for each code scanned:

$ cat -v /dev/ttyACM0
F4009900511513
F4009900511513
F4009900511513

Tried sending correct data with printf after suggestion, no result in the terminal reading the device:

printf 'F4009900511513\r' > /dev/ttyACM0
printf 'F4009900511513\r\n' > /dev/ttyACM0

Final solution

I emailed Datalogic and the following seems to work:

printf 'F400990051153\x0d' > /dev/ttyACM0

This results in the terminal reading to output the following:

$ cat -v /dev/ttyACM0
^F
6
  • 1
    You should look in the detailed configuration manual for the device for whether you can send commands to the scanner. There seems to be one on their website you can download if you are a customer.
    – meuh
    Commented Nov 4, 2020 at 13:13
  • @meuh I have access to the manual but unfortunately it only outlines how to program the scanner by scanning barcodes. From experience that process is error prone.
    – jokarl
    Commented Nov 4, 2020 at 13:30
  • 1
    If you want to control exactly what you are writing use printf instead of echo. Eg: printf 'test\r\n' will add carriage-return (^M) and newline (^J). (To check, pipe the printf into |od -c).
    – meuh
    Commented Nov 5, 2020 at 10:33
  • Thanks for the suggestion, I tried it out but unfortunately it doesn't seem to work. I've updated my answer with some more debugging I've done. Thinking of just contacting the manufacturer and see what they say.
    – jokarl
    Commented Nov 5, 2020 at 10:51
  • 1
    So I got a response from them now, and it seems to work but I'm unsure how much I can share. I will update the question with what I think is appropriate
    – jokarl
    Commented Nov 6, 2020 at 6:42

1 Answer 1

0

Final solution

I emailed Datalogic and the following seems to work:

printf 'F400990051153\x0d' > /dev/ttyACM0

This results in the terminal reading to output the following:

$ cat -v /dev/ttyACM0
^F

Unfortunately I can't share more details, but with the help from the answers and sending a line break as \x0d with printf seems to do the trick.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .