Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i communicate with an HID USB device in delphi [closed]

Tags:

delphi

usb

hid

I have been researching this problem for a while now and I just can't seem to get it right. I have a C++ version of the software I would like to make in delphi, but I can't get it to work in delphi. I need some sort of tutorial or guide that can show me how to connect to, read and write data to a HID USB device.

like image 885
Grant Avatar asked Nov 21 '11 16:11

Grant


People also ask

How does HID USB work?

The USB HID class keyboard is normally designed with an IN endpoint that communicates keystrokes to the computer and an OUT endpoint that communicates the status of the keyboard's LEDs from the computer to the keyboard.

What is the difference between HID and USB?

As for the difference between HID and USB serial, serial is bulk while HID is control and interrupt. That's fundamental for USB, and means HID has (potentially) lower latency but serial has higher capacity.

What is HID compliant USB port?

Universal Serial Bus devices are used to connect various components to a computer. A HID (Human Interface Device) compliant USB follows a specific protocol for communication that allows it to be used with virtually any system.


2 Answers

See Jan Axelson's USB page for examples. He has written a book also. USB Complete.

See also Robert Marquardt's HID controller suite for Delphi.

If you are using Delphi 2009 or newer, follow the link given in the answer on SO question :using-hidcontroller-on-delphi-2010

like image 95
LU RD Avatar answered Oct 06 '22 01:10

LU RD


You can use QueryDosDevice to obtain the full device name. List all entries before you plug-in the device, and after, and see which new entry appears in the list. (I've found that most HID devices apear twice in the list, haven't found why yet). The code will contain "USB" "VID" "PID" and a GUID.

You can use this code with CreateFile if you prefix it with ´\\?\´ and use this Handle as a Serial Port (I personally prefer using THandleStream). The code could look like this:

var
  h:THandle;
begin
  h:=CreateFile(
    PChar('\\?\'+MyPortName),
    GENERIC_WRITE or GENERIC_READ,FILE_SHARE_WRITE or FILE_SHARE_READ,
    nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
  if h=INVALID_HANDLE_VALUE then RaiseLastOSError;
  MyPort:=THandleStream.Create(h);
  SetCommTimeouts(h,MyFCommTimeouts);
like image 34
Stijn Sanders Avatar answered Oct 06 '22 03:10

Stijn Sanders