0

I'm leveraging the Python HID API to attempt to write data to a scanner. The specific command I am trying to write is "A1 04 00"(where A1 Is the ID 04 is the command and 00 is the data)and currently I am writing to the scanner following the specific command format, which is below.

Image here

In code this looks like data=[0x05,0x57,0xA1,0x04,0x00,0xFE,0xFF] and I'm using device.write(data) however I get no response from the scanner. I don't have a lot of experience in interfacing HID devices with Python so I'm sure I'm doing something incorrectly, thanks for the help!

Edit: Code added per request

import hid
data=[0x05,0x57,0xA1,0x04,0x00,0xFE,0xFF]
VENDOR_ID = 0x24ea
PRODUCT_ID = 0x0197

device = hid.device()
device.open(VENDOR_ID,PRODUCT_ID)
device.write(data)

Checksum algorithm per scanner docs

0x10000 – [ Length] – [ Source] – [ExID] – [ExCMD] – [D1 + D2 +D3 +…..]
basic197
  • 33
  • 3
  • 2
    Show us your code. There are a lot of details here. Are you sure you have the right checksum algorithm? – Tim Roberts May 22 '21 at 04:33
  • Added the code as well as the checksum algorithm that was provided by vendor docs. – basic197 May 22 '21 at 04:46
  • Where did you get that command sequence? I'm not doubting, but HID devices can be complicated. You're sending an output report. Could it be a feature report? And if the device accepts more than one report type, you have to include a report ID in the first byte. If you copied this from somewhere else, that's fine. – Tim Roberts May 22 '21 at 06:53
  • The command sequence was taken from the scanners manual, uploaded here https://drive.google.com/file/d/1Plm8uPNpLdgU1K-7xXiDJbX5ZIAAkeAy/view?usp=drivesdk on page 184 – basic197 May 22 '21 at 09:19
  • The scanner data is delivered to you over a HID keyboard interface, but that's output-only. The control sequences go over a USB virtual serial port. You will need to use something like `pyserial` to access that. It can be a bit tricky to figure out which serial port is the scanner; do `ls /dev/tty*` before and after you plug in to find it. – Tim Roberts May 23 '21 at 01:51
  • Thanks for the detailed hints!! That actually worked in my case, and I can add that as my answer if you post it below!! – basic197 May 23 '21 at 03:04

1 Answers1

1

The scanner data is delivered to you over a HID keyboard interface, but that's output-only. The control sequences go over a USB virtual serial port. You will need to use something like pyserial to access that. It can be a bit tricky to figure out which serial port is the scanner; do ls /dev/tty* before and after you plug in to find it.

Tim Roberts
  • 48,973
  • 4
  • 21
  • 30