[fpc-pascal] USB Human Interface Devices
Stefan V. Pantazi
svpantazi at gmail.com
Sat Aug 17 17:10:37 CEST 2019
The obvious first thing to make sure is that the calling convention
matches the library for the platform. I see that in
https://github.com/Zaaphod/pas-libusb/blob/Hack/src/libusb.pas 9line 46)
the calling convention on Windows is cdecl (the stdcall is commented
out). In libusbxhid, if I remember correctly, the calling convention for
windows dlls is set to stdcall.
One other thing is that debugging is much more tedious without an
integrated debugger that allows you to step through each line before you
can see which function call blows up with a segfault.
On 8/17/19 9:00 AM, James Richters wrote:
> I’m trying to figure out why I get an access violation when I try to open my device with pas-libusb but it works with libusbxhid they both are using libusb-1.0.dll
>
>
>
> I put a bunch of hacks into pas-libusb to try to figure it out… just a lot of writeln’s so I can try to track down exactly what’s happening. Because if I try to trace through the program I get “Program received signal SIGSEGV Segmentation fault” before I get to the problem
>
>
>
> I put this in a branch here:
>
>
>
> https://github.com/Zaaphod/pas-libusb/tree/Hack/src
>
>
>
> I’m using testopendevic_vidpid2.pas to test it with.
>
>
>
> Here’s my output:
>
> start
>
> 1
>
> 2
>
> a05472131
>
> a10CEEB93
>
> b
>
> c
>
> FALSE 8086 10CE A36D EB93
>
> FALSE 8087 10CE 0AAA EB93
>
> FALSE 0424 10CE 2734 EB93
>
> FALSE 1D50 10CE 6015 EB93
>
> FALSE 1B1C 10CE 0C15 EB93
>
> TRUE 10CE 10CE EB93 EB93
>
> FALSE 05E3 10CE 0610 EB93
>
> FALSE 04E8 10CE 61F5 EB93
>
> FALSE 1B1C 10CE 0C10 EB93
>
> FALSE 0424 10CE 274C EB93
>
> FALSE 047D 10CE 1020 EB93
>
> FALSE 1B1C 10CE 1B4F EB93
>
> FALSE 1A40 10CE 0101 EB93
>
> FALSE 0C45 10CE 7403 EB93
>
> FALSE 10C4 10CE EA60 EB93
>
> d
>
> e
>
> H1
>
> I
>
> 4
>
> Cousldn't connect to device: Access violation
>
>
>
>
>
>
>
> Here’s as far as I could get….
>
> (**
>
> * Find endpoint according to MatchFunc
>
> *
>
> * @param MatchFunc method to compare a given endpoint descriptor with a
>
> * criterion
>
> *
>
> * @returns endpoint or Nil
>
> *)
>
> Function TLibUsbInterface.FindEndpoint(MatchFunc : TLibUsbEndpointMatchMethod) : Plibusb_endpoint_descriptor;
>
> Var IEP : Integer;
>
> ED : Plibusb_endpoint_descriptor;
>
> Begin
>
> writeln('H',FInterface^.bNumEndpoints);
>
> For IEP := 0 to FInterface^.bNumEndpoints-1 do
>
> Begin
>
> Writeln('I');
>
> ED:= @(FInterface^.endpoint^[IEP]);
>
> if MatchFunc(ED) then
>
> Begin
>
> Writeln('J');
>
> Exit(ED);
>
> End
>
> else
>
> Writeln('K');
>
> End;
>
> Result := Nil;
>
> End;
>
> MatchFunc(ED) is where the access violation occurs, but I can’t trace any further because I can’t find the function MatchFunc() I just don’t understand where the actual function is.
>
>
>
> Maybe I made an error in the way I’m trying to open the device? It can’t be any problem with the device itself or using libusb-1.0.dll because that is all working with libusbxhid.. in fact I have all inputs from my device mapped out.. Still don’t have the LCD working…. I can just use libusbxhid, but this is bugging me and I wanted to try to figure out what’s going on.
>
>
>
>
>
> James
>
>
>
>
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
--
_______________________________________________________
More information about the fpc-pascal
mailing list