Closed Megamouse closed 1 month ago
I've been looking at hid_read_timeout as well. It luckily seems to handle synchronous reads correctly already, since it already passes bytes_read to ReadFile and uses it later to write to the read_buf.
@mcuee can you have a quick check of this with known devices you have? I'm pretty sure this is fine, but just to be sure
@mcuee can you have a quick check of this with known devices you have? I'm pretty sure this is fine, but just to be sure
I will carry out the tests over the weekend.
Building is fine with VS2022 and MinGW64 (cmake and auto-tools).
Simple hidtest output (with Microchip Simple HID Demo).
Last portion with the test device (not exactly suitable for the test but this is probably the closest).
Button not pressed --> return 81 01
Device Found
type: 04d8 003f
path: \\?\HID#VID_04D8&PID_003F#6&42784ee&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer: Microchip Technology Inc.
Product: Simple HID Device Demo
Release: 2
Interface: 0
Usage (page): 0x1 (0xff00)
Bus type: 1 (USB)
Indexed String 1: Microchip Technology Inc.
Unable to send a feature report.
Unable to get a feature report: Get Input/Feature Report DeviceIoControl: (0x00000001) Incorrect function.
waiting...
Data read:
81 01 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c
Press any key to continue . . .
Button pressed: return 81 00
.
Device Found
type: 04d8 003f
path: \\?\HID#VID_04D8&PID_003F#6&42784ee&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
serial_number:
Manufacturer: Microchip Technology Inc.
Product: Simple HID Device Demo
Release: 2
Interface: 0
Usage (page): 0x1 (0xff00)
Bus type: 1 (USB)
Indexed String 1: Microchip Technology Inc.
Unable to send a feature report.
Unable to get a feature report: Get Input/Feature Report DeviceIoControl: (0x00000001) Incorrect function.
waiting...
Data read:
81 00 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c
Press any key to continue . . .
Using hidapitester.
MINGW64 /c/work/hid/hidapitester
$ diff -u Makefile Makefile_pr697
--- Makefile 2024-06-09 07:38:35.441954600 +0800
+++ Makefile_pr697 2024-09-29 11:11:18.637356000 +0800
@@ -4,7 +4,7 @@
#
# overide this with something like `HIDAPI_DIR=../hidapi-libusb make`
-HIDAPI_DIR ?= ../hidapi
+HIDAPI_DIR ?= ../hidapi_pr697
# try to do some autodetecting
UNAME := $(shell uname -s)
$ make clean
rm -f ../hidapi/windows/hid.o hidapitester.o
rm -f hidapitester.exe
$ make -f Makefile_pr697
gcc -I ../hidapi_pr697/hidapi -DHIDAPITESTER_VERSION=\"""v0.5""\" -c hidapitester.c -o hidapitester.o
gcc -I ../hidapi_pr697/hidapi -DHIDAPITESTER_VERSION=\"""v0.5""\" ../hidapi_pr697/windows/hid.o hidapitester.o -o hidapitester.exe -lsetupapi -Wl,--enable-auto-import -static-libgcc -static-libstdc++
$ ./hidapitester --list
046D/B021: Logitech - Logitech_Pebble
046D/B021: Logitech - Logitech_Pebble
8087/0A1E: -
06CB/CD40: Microsoft - HIDI2C Device
06CB/CD40: Microsoft - HIDI2C Device
06CB/CD40: Microsoft - HIDI2C Device
06CB/CD40: Microsoft - HIDI2C Device
045E/0000: -
045E/0000: -
DEED/FEED: Acer Inc - Acer Airplane Mode Controller
045E/0000: -
1EA7/0064: (Standard system devices) - 2.4G Mouse
1EA7/0064: (Standard system devices) - 2.4G Mouse
04D8/003F: Microchip Technology Inc. - Simple HID Device Demo
$ ./hidapitester --vidpid 04d8/003f --list-detail
04D8/003F: Microchip Technology Inc. - Simple HID Device Demo
vendorId: 0x04D8
productId: 0x003F
usagePage: 0xFF00
usage: 0x0001
serial_number:
interface: 0
path: \\?\HID#VID_04D8&PID_003F#6&42784ee&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
$ ./hidapitester --vidpid 04d8/003f --open --get-report-descriptor
Opening device, vid/pid: 0x04D8/0x003F
Report Descriptor:
06 00 FF 09 01 A1 01 19 01 29 40 15 01 25 40 75 08 95 40 81 00 19 01 29 40 15 01 25 40 75 08 95
40 91 00 C0
Closing device
$ ./hidapitester --vidpid 04d8/003f -l 64 --open --send-output 0x00,0x80
Opening device, vid/pid: 0x04D8/0x003F
Writing output report of 64-bytes...wrote 65 bytes:
00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Closing device
(Note--> toggle LED command with 0x80 -- this is working fine)
$ ./hidapitester --vidpid 04d8/003f --open --send-output 0x00,0x80
Opening device, vid/pid: 0x04D8/0x003F
Writing output report of 64-bytes...wrote 65 bytes:
00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Closing device
$ ./hidapitester --vidpid 04d8/003f --open --send-output 0x00,0x80
Opening device, vid/pid: 0x04D8/0x003F
Writing output report of 64-bytes...wrote 65 bytes:
00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Closing device
(Note--> Read button press status command with 0x81 -- this is working fine.
Button Not pressed --> return 81 01
Button pressed --> return 81 00)
$ ./hidapitester --vidpid 04d8/003f --open --send-output 0x00,0x81 --read-input
Opening device, vid/pid: 0x04D8/0x003F
Writing output report of 64-bytes...wrote 65 bytes:
00 81 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading up to 64-byte input report, 250 msec timeout...read 64 bytes:
81 01 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C
1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C
Closing device
$ ./hidapitester --vidpid 04d8/003f --open --send-output 0x00,0x81 --read-input
Opening device, vid/pid: 0x04D8/0x003F
Writing output report of 64-bytes...wrote 65 bytes:
00 81 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading up to 64-byte input report, 250 msec timeout...read 64 bytes:
81 00 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C
1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C
Closing device
@Youw
I am not sure if my tests can really catch anything, but there is no regression at least. I think it should be fine.
This is perfect, thanks!
Return bytes_written in hid_write if WriteFile returns 1, which means it succeeded synchronously.
According to documentation, the system reserves the right to run WriteFile synchronously, even if FILE_FLAG_OVERLAPPED is set.
"Be careful when you code for asynchronous I/O because the system reserves the right to make an operation synchronous if it needs to. So it is best if you write the program to correctly handle an I/O operation that may be completed either synchronously or asynchronously. The sample code demonstrates this consideration."
Fixes #695