Forum > Embedded - AVR

HID for Teensy 4

(1/4) > >>

j.g.holstein@rug.nl:
Hi all,
I use a Teensy 4 and a com port (/dev/ttyACM0 for the communication send and receive,
but for my application it is better to use a HID.
My test program recognize already the Teensy 4.... perfect, but how can I send and receive serial strings? See also attachment for the raw output.
Is there any solution to solve this ?
Best regards,
Johan
 

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program demo; // this modeswitch makes the pointers to// objects more comfortable to use{$modeswitch autoderef} uses  sysutils, hidapi;  procedure EnumerationDemo;var  EnumList, EnumItem: PHidDeviceInfo;  Path: String;  Vid, Pid: Word;  ProductName: UnicodeString; begin  WriteLn('will now enumerate all USB HID devices.');  WriteLn('Note that it will list more info if you run with sudo,');  WriteLn('you might want to add an udev rule for your device.');  WriteLn();   // request the hidapi to build a linked list of all HID devices  // it will match all of them because VID and PID are zero  EnumList := THidDeviceInfo.Enumerate(0, 0);   // iterate through linked list  EnumItem := EnumList;  while Assigned(EnumItem) do begin    Path := EnumItem.Path;    Vid := EnumItem.VendorID;    Pid := EnumItem.ProductID;    ProductName := PCWCharToUnicodeString(EnumItem.ProductString);    WriteLn(Format('Found: %s (%0.4x:%0.4x) at: %s', [ProductName, Vid, Pid, Path]));    EnumItem := EnumItem.Next;  end;  WriteLn();   // dont forget to free the list again, this s done  // by calling free on the first item of the linked list  EnumList.Free;end;  procedure OpenAndReadDemo;const  // This is a Logitech Extreme 3D Joystick, a  // cheap and popular model, probably you own one,   // if not then try some other VID/PID, try to run  // as root or make an udev rule for the device.  DEMO_VID = $16c0;  DEMO_PID = $0486; var  Device: PHidDevice;  I, J, Num: Integer;  Buffer: array[0..63] of Byte; begin  WriteLn(Format('Will now try to open device %0.4x:%0.4x', [DEMO_VID, DEMO_PID]));  WriteLn();  Device := THidDevice.Open(DEMO_VID, DEMO_PID, '');  if not Assigned(Device) then begin    WriteLn('could not open device');  end  else begin    WriteLn('device is open, now going to read data from it');    WriteLn('Manufacturer: ', Device.GetManufacturerString);    WriteLn('Product: ', Device.GetProductString);     for I := 1 to 1000 do begin      Num := Device.Read(Buffer, SizeOf(Buffer));      for J := 0 to Num - 1 do begin          Write(Format('%0.2x ', [Buffer[J]]));       end;       Write(#13);    end;    WriteLn();    WriteLn('closing device');    Device.Close;  end;   end;  begin  EnumerationDemo;  OpenAndReadDemo;end.                                                     

MarkMLl:
Rawhid might be useful.

MarkMLl

j.g.holstein@rug.nl:
So what must be done to read and write to the HID?
Can you help whit that?
Thanks,
Johan

MarkMLl:
You need a copy of the rawhid library from the Teensy site, and a binding looking something like


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit rawhid;interface {  Automatically converted by H2Pas 1.0.0 from hid.h  The following command line parameters were used:    hid.h} {$IFDEF FPC}{$PACKRECORDS C}{$ENDIF} {$L hid.o}                      // Built by Makefile from Teensyduino host example{$LINKLIB libusb }              // Statically-linked prerequisite library   function rawhid_open(max:longint; vid:longint; pid:longint; usage_page:longint; usage:longint):longint;cdecl;external;   function rawhid_recv(num:longint; buf:pointer; len:longint; timeout:longint):longint;cdecl;external;   function rawhid_send(num:longint; buf:pointer; len:longint; timeout:longint):longint;cdecl;external;   procedure rawhid_close(num:longint);cdecl;external;  implementation  end. 
MarkMLl

j.g.holstein@rug.nl:
Hi Mark,

I looked at the  https://www.pjrc.com/teensy/rawhid.html  but can not find a library as mentioned.

Best,
Johan

Navigation

[0] Message Index

[#] Next page

Go to full version