[fpc-pascal] USB Human Interface Devices
Johann Glaser
Johann.Glaser at gmx.at
Sat Aug 17 23:45:53 CEST 2019
Hi!
Am Samstag, den 17.08.2019, 16:16 +0200 schrieb Jean SUZINEAU:
> Le 17/08/2019 à 15:00, James Richters a écrit :
> > Function TLibUsbInterface.FindEndpoint(MatchFunc :
> > TLibUsbEndpointMatchMethod) : Plibusb_endpoint_descriptor;
> > 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.
>
> MatchFunc is a parameter (its type is TLibUsbEndpointMatchMethod) of
> TLibUsbInterface.FindEndpoint.
> To find which function is actually called, you should trace back
> where TLibUsbInterface.FindEndpoint is called and what function is
> provided as parameter MatchFunc.
> It's likely you'll have to "climb up" through several calls, may be
> that TLibUsbInterface.FindEndpoint has itself a parameter MatchFunc
> If you use the debugger, the callstack and a breakpoint just before
> the offending call to MatchFunc should help you to find from where
> comes your MatchFunc.
> I wouldn't be surprised that it resolves somewhere to an overridden
> method Match of an instance of a class derived from
> TLibUsbDeviceMatchClass, likely TLibUsbDeviceMatchVidPid.Match,
> TLibUsbDeviceMatchVidPidSerial.Match or
> TLibUsbInterfaceMatchNumAlt.Match from unit libusbutil.pas
> This can sound difficult for you at the beginning if you're not too
> much accustomed with variables of type procedure and inheritance, but
> after a few practice it's not that complicated.
Thanks Jean for the explanation! The MatchFunc is a so called
"callback". I've chosen this pattern to allow to implement flexible
filter functions when searching for devices, interfaces, endpoints, ...
As far as I can see, you are using TMyDevice in mydevice.pas. This unit
is specifically implemented for the EZ-USB chips (Cypress AN2131),
which do not have Flash or ROM, but only SRAM. The driver has to
download the firmware before the real communication. This specific
behavior is demonstrated in mydevice.pas. Therefore it is only of
limited use for your device.
One action of TMyDevice.Create is to open an interface and then two
bulk endpoints (see lines 141-145 in your "Hack" branch. The interface
can be opened (hence you see an 'e' in your output. Then wants to open
the endpoint 2 (line 143) using
TLibUsbInterface.FindEndpoint(bEndpointAddress : Byte) at
libusboop.pas:1099. This calls via some detours the function where
you've added the WriteLns.
Actually all these functions should reside cleanly in the Pascal world
and there are no calls to libusb functions, therefore I wouldn't expect
any calling convention troubles here.
Could you please remove the try-except block in
testopendevic_vidpid2.pas and compile with debug line info to get the
full exception backtrace incl. line numbers?
Thanks
Hansi
More information about the fpc-pascal
mailing list