Recent

Author Topic: USB HID  (Read 10047 times)

folkeu08

  • Full Member
  • ***
  • Posts: 106
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

  • Full Member
  • ***
  • Posts: 106
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


folkeu08

  • Full Member
  • ***
  • Posts: 106
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

  • Full Member
  • ***
  • Posts: 106
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

  • Full Member
  • ***
  • Posts: 106
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: 1739
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

  • Full Member
  • ***
  • Posts: 106
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: 1739
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;

folkeu08

  • Full Member
  • ***
  • Posts: 106
Re: USB HID
« Reply #9 on: June 01, 2020, 07:58:02 pm »
Hi,
I found an example in Delphi 7 which uses the TJvHidDevice Controller component. The project is in attached files
In public statements, "MyHidDev: TJvHidDevice;" is indicated.
At the compilation Lazarus said he did not know TJvHidDevice.
What to replace it with ?
It is use un this prosedure :
Code: Pascal  [Select][+][-]
  1. procedure TfmMain.HidCtl1DeviceChange(Sender: TObject);
  2. begin
  3.   if (MyHidDev <> nil) and (not MyHidDev.IsPluggedIn) then
  4.     HidCtl1.CheckIn(MyHidDev);
  5.   if (MyHidDev = nil) then
  6.     HidCtl1.CheckOutById(MyHidDev, Sonelec_VID, Sonelec_PID);
  7.   //bHIDDevConnected := (MyHidDev <> nil);
  8.   MyHidDev := nil;
  9.   Hid_Reset(false);
  10. end;
  11.  


Thanks
« Last Edit: June 01, 2020, 09:13:55 pm by folkeu08 »

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1739
Re: USB HID
« Reply #10 on: June 01, 2020, 10:10:43 pm »
This is the uses-section of your main form:

Code: Pascal  [Select][+][-]
  1. uses
  2.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  3.   Dialogs, ButtonGroup, StdCtrls, ComCtrls, JvComponentBase,
  4.   JvHidControllerClass, ExtCtrls, rmSwitch, VrControls, VrLeds,
  5.   VrCheckLed, ActnList, Menus, AdvEdit, advlued;

This is definitely not Lazarus. And I am not able to run or test your project with Lazarus.
If you want (my) help, please upload a Lazarus project.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: USB HID
« Reply #11 on: June 01, 2020, 10:38:50 pm »
I am concerned that OP has not taken on board that whatever software he eventually gets running on a PC he will also need matching firmware to run on the PIC.

Telling us that the PIC is 1234:0001 and expecting everything to magically come together is not a good start.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

folkeu08

  • Full Member
  • ***
  • Posts: 106
Re: USB HID
« Reply #12 on: June 01, 2020, 11:15:01 pm »
Hi,
I started with the Microchip "MCHPUSB" demo project.
I mounted a small hardware card with the pic firmware. The card works because it is detected by the executable also provided by Microchip and I manage to control it in both directions.
I try to reproduce this operation in Lazarus without using a third party DLL with your source.
I'm not used to Lazarus.
The first step is to mount the electronic card in the software and I go around in circles.
I am looking to have the interface detected by the software and to have the state of the InterfaceLabel changed from "Intercave not connected" to "Interface connected".
The  VENDOR_ID = 1240 and PRODUCT_ID = 0005;
The project is attached
Thanks

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1739
Re: USB HID
« Reply #13 on: June 02, 2020, 09:41:10 am »
The included project (your project with some changes) will show you HID devices when you press connect.

folkeu08

  • Full Member
  • ***
  • Posts: 106
Re: USB HID
« Reply #14 on: June 02, 2020, 09:10:49 pm »
Hello DonAlfredo,

I managed to detect my interface from your example by going to modify the value of Vendor and Product.
I certainly explained it wrong.
I would like the USB interface to be detected or not detected by the software when the USB plug is inserted or removed from the PC and the information "Connected" or "Not Connected" within the "InterfaceLabel".
Then I should be able to read and send data because the syntax "Data-Read" and "Data_Write" exists.
I don't just want to list the USB interfaces connected to the PC.
Thanks

 

TinyPortal © 2005-2018