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.
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.
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.
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.
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
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With