Recent

Author Topic: USB HID  (Read 494 times)

folkeu08

  • New Member
  • *
  • Posts: 10
USB HID
« on: April 08, 2020, 01:44:49 am »
Hi,
I would like to interact with electronics in USB HID mode so as not to have to install drivers under Windows.
The only third party component found that allows this without additional dll is this: https://www.winsoft.sk/nathid.htm
I mounted the electronic board of this site https://www.roboticus.org/electronique/usb/12-carte-dinterface-sur-port-usb-protocole-hid-part-2.html to make my hand to the USB and installed the firmware in the PIC. The board is well recognized by the PC.
I try to reproduce the operation of the demo delphi7 software under Lazarus with third party components but I can't do anything good.
I am attaching my cleaned project file.
Thank you
François
« Last Edit: April 16, 2020, 02:32:23 pm by folkeu08 »

folkeu08

  • New Member
  • *
  • Posts: 10
Re: USB HID
« Reply #1 on: April 09, 2020, 03:16:25 pm »
Hi,
The component is buggy. It does not detect the board https://www.microchip.com/Developmenttools/ProductDetails/DM163025
I make my tests with this board.
The author is informed and tries to remedy the problem.
François

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1253
Re: USB HID
« Reply #2 on: April 09, 2020, 03:26:06 pm »

folkeu08

  • New Member
  • *
  • Posts: 10
Re: USB HID
« Reply #3 on: April 09, 2020, 05:54:40 pm »
Hi DonAlfredo,
I also connected again to give the info because I just found it too.
I compiled and it works.
I must have a problem in my firmware of the pic 18f4550 because it still does not detect it.
Thanks
François

folkeu08

  • New Member
  • *
  • Posts: 10
Re: [SOLVED] USB HID
« Reply #4 on: April 09, 2020, 06:09:18 pm »
Hi,
This post https://forum.lazarus.freepascal.org/index.php?topic=47371.0 indicates a memory problem but if I configure debugging as indicated in the post, the error message when closing the window is no longer present.
François

folkeu08

  • New Member
  • *
  • Posts: 10
Re: USB HID
« Reply #5 on: April 16, 2020, 02:39:00 pm »
Hi,
Is there an example of code to communicate in USB with a Pic18f4550 which will have one:
 * VENDOR_ID = 0x1234
 * PRODUCT_ID = 0x0001
to transmit and receive digital data from 0 to 255?
Even if it's not quite that, I think I should be able to adapt.
Thank you
François

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1253
Re: USB HID
« Reply #6 on: April 16, 2020, 03:00:00 pm »
I do not know if this is related to the FPC USB HID software, but in usb2.pas are two constants: vendor and product. You can adapt these two to suit your hardware.

folkeu08

  • New Member
  • *
  • Posts: 10
Re: USB HID
« Reply #7 on: April 17, 2020, 10:49:50 am »
Hello,
For the syntax of the send and receive commands, can I rely on the JvHIDController examples from the JVCL library?
I read that your Lazarus component was a rewrite of the latter.
a PIC18f4550 from Microchip (www.microchip.com) is a processor that allows dialogue via USB. It is used a lot in amateur electronics
Thank you

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1253
Re: USB HID
« Reply #8 on: April 17, 2020, 02:01:26 pm »
The whole library was designed to communicate with Microchip USB HID controllers.
And its in use 24/7 for a very long time now, with many MCU's.

Example use:

Code: Pascal  [Select][+][-]
  1. function TUSB.SetValue(board):boolean;
  2. var
  3.   error:boolean;
  4.   avalue:word;
  5. begin
  6.   avalue:=0;
  7.  
  8.   with AUSBList.Items[board] do
  9.   begin
  10.       FillChar(LocalData, SizeOf(LocalData), 0);
  11.       LocalData.Data[0] := byte(CMD_set_value);
  12.       LocalData.Data[1] := 12345;
  13.     end;
  14.  
  15.     error:=HidReadWrite(AUSBList.Items[board],False);
  16.  
  17.     if (NOT error) then with AUSBList.Items[board].LocalData do
  18.     begin
  19.       if ( data[0]=byte(CMD_set_value) ) then
  20.       begin
  21.         avalue:=(data[3]+data[4]*256);
  22.       end else error:=True;
  23.  
  24.   end;
  25.  
  26.   result:=error;
  27. end;

 

TinyPortal © 2005-2018