Friday, October 8, 2021

More USB HID Implementation

In this blog post, I discussed the issues I was having with the RAD Studio Delphi compiler and the JEDI VCL implementation of a Windows USB HID Device. Eventually tracing it down to a HID device on one laptop that was causing the issue.  At the conclusion of that debugging exercise, I postulated that there was some issue with the JEDI VCL implementation of the USB HID device that needed improvement.

I spent a few hours today in between other projects attempting to track it down further.   Mostly because it was beginning to bug me.  I dont believe there is an error in the code, it works as designed. What is missing in all of my implementations is the OnDeviceCreateError handler. I have never seen documentation that this is to be implemented, other than a short comment in the read me file that it was included. It is not in any of the examples either.  

After tracing through the code, the absence of this handler was causing the code to fail out completely, since the error is not handled. The code snippet below is what appears to be the minimum required. So far it is working on two projects. Depending on why the device is failing, your implementation may need more error processing than shown here.  

procedure TformXXX.JvHidCtrlDeviceCreateError(Controller:
          TJvHidDeviceController; PnPInfo: TJvHidPnPInfo; var Handled, RetryCreate:Boolean);
begin
     Handled:= TRUE;
     RetryCreate:= FALSE;
     FreeAndNil(PnPInfo);
end; 

My only issue is that in development you will continue to receive the error message that the device cannot be identified, which is what started this. The error message appears when you open the project and close the project. So maybe there is some improvement that can still be done. But for me right now, this has dropped far down on my list of things to do. 

 

 


 

 

 

No comments:

Post a Comment