espressif / esp-usb

Other
15 stars 9 forks source link

usb hid device barcode scanner can not use (IEC-98) #26

Closed yel-best closed 3 months ago

yel-best commented 3 months ago

Answers checklist.

General issue report

image

I'm using this example https://github.com/espressif/esp-idf/tree/master/examples/peripherals/usb/host/hid

Please tell me some ways or reasons,thanks

Through another project, usb_host_lib, the parameters of the scanning gun I am currently using are read as follows:

I (13615) CLASS: Opening device at address 1
I (13615) CLASS: Getting device information
I (13615) CLASS:        Full speed
I (13615) CLASS:        bConfigurationValue 1
I (13615) CLASS: Getting device descriptor
*** Device descriptor ***
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 0x0
bDeviceSubClass 0x0
bDeviceProtocol 0x0
bMaxPacketSize0 64
idVendor 0x218
idProduct 0x210
bcdDevice 0.00
iManufacturer 1
iProduct 2
iSerialNumber 3
bNumConfigurations 1
I (13645) CLASS: Getting config descriptor
*** Configuration descriptor ***
bLength 9
bDescriptorType 2
wTotalLength 34
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
bMaxPower 400mA
        *** Interface descriptor ***
        bLength 9
        bDescriptorType 4
        bInterfaceNumber 0
        bAlternateSetting 0
        bNumEndpoints 1
        bInterfaceClass 0x3
        bInterfaceSubClass 0x1
        bInterfaceProtocol 0x1
        iInterface 0
                *** Endpoint descriptor ***
                bLength 7
                bDescriptorType 5
                bEndpointAddress 0x83   EP 3 IN
                bmAttributes 0x3        INT
                wMaxPacketSize 8
                bInterval 1
I (13695) CLASS: Getting Manufacturer string descriptor
USBScn Chip
I (13705) CLASS: Getting Product string descriptor
USBScn Module$
I (13715) CLASS: Getting Serial Number string descriptor
2027300413413333
peter-marcisovsky commented 3 months ago

Hello @yel-best

Could you please specify and elaborate what do you mean by a following quote:

it enters a dead loop

Also, could you please specify all the changes, if any, you have made to the HID example code? Thank you.

yel-best commented 3 months ago

Hello @yel-best

Could you please specify and elaborate what do you mean by a following quote:

it enters a dead loop

Also, could you please specify all the changes, if any, you have made to the HID example code? Thank you.

Oh, I didn't modify the logic code, I just added some esp_log, and I printed out every function execution point that the program ran. Then I found that the content of my QR code was "a"but the result of scanning the code was keyCode = 57, and in the function:

hid_host_interface_callback
hid_host_keyboard_report_callback
hid_host_interface_callback
hid_host_keyboard_report_callback
key_event_callback 57

The loop jump does not output the result character "a"I want.

I don’t know the reason, but the result I understand from the code scanner is actually characters such as abcdefg in the keyboard. Do I need to modify anything? I think the driver and character set in hid_usage_keyboard can be applied to the code scanner.

roma-jam commented 3 months ago

Hi @yel-best ,

To determine, where is the problem, is it possible to add the debug output for the raw report and share the log output?

The regular barcode scanner works a keyboard, so during the scanning it emulates the keyboard key pressing. That means that example should not do anything, when you are not scanning and show any data, when you scan the barcode. Is that right?

Then, example parses the data from scanner based on the default keyscan table, which is provided in the example hid_host_example.c#L90.

To add the debug output, please add ESP_LOG_BUFFER_HEX In the line 386, hid_host_example.c file:

...
    case HID_HOST_INTERFACE_EVENT_INPUT_REPORT:
        ESP_ERROR_CHECK(hid_host_device_get_raw_input_report_data(hid_device_handle,
                                                                  data,
                                                                  64,
                                                                  &data_length));

        ESP_LOG_BUFFER_HEX(TAG, data, data_length); // This is debug output for raw data input report

        if (HID_SUBCLASS_BOOT_INTERFACE == dev_params.sub_class) {
...

Thanks.

yel-best commented 3 months ago

hid_host_device_get_raw_input_report_data

yes, you are right. The code scanner is actually simulating the keyboard for data output. I cannot recognize the USB HID device after running the example. I suspect that the code scanner I use is not standard enough. I will try to replace it with another one first. Scan code gun, and then add this code, I will update the log, please wait until I find a new code scanner, I will update again

thank you for your help

JeevabharathiRK commented 3 months ago

Hi @yel-best,

yel-best commented 3 months ago

Hi @yel-best,

  • I like to share my experience in making a connection with the Barcode scanner and ESP32 S3 Devkit M1 board, I used to upload code via Visual Studio Code, but I had an issue there, so I searched for that and found that it could be solved by using Official Espressif IDE.
  • I am using Espressif-IDE Version: 2.12.0 and example code-named "hid_host_example.c"
  • Connection was as per the readme file and additionally, I have shared some images for better understanding. The connected barcode scanner was brought from Amazon and It was dismantled.

  • And Here is the Output .....

oh, thank you very much for sharing, you are so kind, this will bring me a solution, thank you very much 😄

roma-jam commented 3 months ago

Hey @yel-best, Are there any updates?

I cannot recognize the USB HID device after running the example. I suspect that the code scanner I use is not standard enough.

Based on the debug output from hid example you had provided, it is a USB device that has one Keyboard interface. So the example found the "keyboard" and handle the key scan code. So, it should work.

If there anything new, please feel free to report.

roma-jam commented 3 months ago

Hi @yel-best, Are there any progress?

yel-best commented 3 months ago

Hi @yel-best, Are there any progress?

Thank you for your concern. After trying it, I suspected that the protocol of the scanner hardware may not be standard. I suspected that it was a hardware compatibility issue. Then we replaced two scanner devices for USB connection. It worked without any code changes. Correctly obtain the corresponding barcode or QR code value, so this is how I currently solve my problem.

thanks 😄

roma-jam commented 3 months ago

@yel-best Thanks for the information.

I will close the issue then. If there will be anything else, feel free to re-open that issue or create a new one.