Forum > General

FPC-HID-USB ReadFile ok on Windows, not working on Linux

<< < (2/3) > >>

BobT:
Thank you all. System is 64bit x86_64, Lazarus 2.0.10, fpc 3.2.0, Kernel: 4.19.0-6-amd64 x86_64 (as I should have said before).

I do have appropriate udev rule in place, I think, and I can apparently access the device. 'WriteFile' is returning without error and the target device is responding as expected.

The target response in this test instance is fixed (4 bytes MCU ID code + 2 byte checksum) so I know what I should be getting every time, and can see the correct data appearing on the Wireshark trace. Some (not all) of those byte values are consistently appearing in the readBuffer content after calling ReadFile, though not as the 'value' fields but as the lowest byte of the 'HID' field. So alignment does seem to be a major part of the problem. 


MarkMLl:
I think the problem I was seeing was very close to the ioctl() calls themselves, but it might be reasonable to expect data alignment issues if what's being buffered has already been partially-processed by the kernel. I don't know to what extent that's fixable with explicit alignment directives etc.

There might possibly be something useful in my notes below... angst if nothing else :-)


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---(* This is a USB (and in particular HID) exerciser derived from this author's   *)(* lg600 program which has- or at least should have- the sole functionality of  *)(* setting up a Logitech G600 gamer's mouse. While the lg600 program put a      *)(* lot of effort into parsing information in the /sys tree it made very few     *)(* demands on the USB APIs and as such had no dependency on the development     *)(* versions of libusb or libhid, however once one starts looking at more        *)(* general functionality one gets very much bogged down in alignment and        *)(* anomalous structure size issues (specifically, at the binary API between     *)(* libhid and the kernel) with the result that using precompiled system         *)(* libraries is pretty much unavoidable.                MarkMLl, 2019-01-11     *) (* NOTE: a lot of the structure of this program is derived from LG600, where it *)(* probably made more sense. Sorry.                                             *) (* ASSUME THIS IS PERMANENTLY BROKEN, IT'S HERE ENTIRELY TO PREVENT ME FROM     *)(* TRYING TO TACK MORE AND MORE INAPPROPRIATE FUNCTIONALITY INTO THE LG600      *)(* MOUSE PROGRAM.                                                               *) ... (* Minimal testing of the above has been applied, and in practical terms even   *)(* during initial development I'm pretty sure that much of what I've done here  *)(* needs to be ripped out and replaced. One of the problems is that libhid      *)(* exists in two forms (one using the kernel's HID support, the other using     *)(* libusb) and both implementations are useful, and I suspect that the only way *)(* to sort out the naming conflicts will be to rely on dynamic linkage of the   *)(* appropriate .so files: see what I did for the K8055 test program.            *) (* Discussion in the forum directed me to https://github.com/prof7bit/HIDAPI.pas *)(* which is an interface to hidapi-libusb, but by then I'd just about done my   *)(* own transcript. Also https://github.com/LongDirtyAnimAlf/FPC-USB-HID but     *)(* this is a JEDI interface and as such is not what I was looking for.          *) 
MarkMLl

DonAlfredo:
What HID report length do you use.
And what HID report length does the device support ?

BobT:
Hi Don Alfredo, report length and device support both 64 bytes.

DonAlfredo:
I will try to look closer into this. I must confess: only used this library on 32 bit ARM systems.
As a first try:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  TReport = packed record    ReportID: byte;    Data:    array [0..15] of byte; // <-- this needs to be adapted to your report size; e.g 63 !  end; 

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version