EETimes

Embedded Systems October 2000 Vol13_11

Issue link: http://dc.ee.ubm-us.com/i/71842

Contents of this Issue

Navigation

Page 71 of 181

When YOIl have the HID firmware lip and running, you're ready to start accessing the device from applications on the host computer. TABLE 1 API function SetupDiGetClassDevs oUler information about the device's intended use and abili ti es. Once you've identified ule device Documentation Windows NT 12000 DDK and NT 12000 Platform SDK SetupDiEnumDevicelnterfaces Windows NT 12000 DDK and NT/2000 Platform SDK CreateFile SetupDiGetDevicelnterfaceDetail Windows NT /2000 DDK and NT /2000 Platform SDK Windows Platform SDK HidD _GetAttributes HidD _ GetPreparsedData HidD_GetCaps HidD _GetValueCaps HidD _ GetButtonCaps HidD_GetFeature Hid D _SetFeatu re ReadFile WriteFile HidP _SetButtons Windows 98/2000 DDK Windows 98/2000 DDK Windows 98/2000 DDK Windows 98/2000 DDK Windows 98/2000 DDK Windows 98/2000 DDK Windows 98/2000 DDK Windows Platform SDK Windows Platform SDK Windows 98/2000 DDK Use in HID with HIDs Returns an array of structures containing information about all installed HIDs Returns a pointer to a structure that identif ies an interface in the array retu by SetupDiGetClassDevs Returns a device path name for a specified device interface Opens a handle to a HID using the pathname returned by SetupDiGetDevice- Interface Detail Returns the Vendor ID, Prod uct I D, and Version for a specified HID Returns a handle to a buffer with information about a device's capabilities Returns a structure np';rnmnp a device's capabilities Returns a structure describing the values in a device port Returns a structure describing buttons in a device report Reads a feature report from a specified HID Sends a feature report to a specif ied HID Reads in input report from a specified HID Sends out output report to a specified HID Sets the button data in a report you' re looking for, you' re ready to exchange reports using ReadFileO and Wri teFileO (for input and output reports) or HidD_Get_FeatureO and I-lidD_Se t_FeatureO (for feature reports) . One caution about input reports: ReadFi leO is a blocking system call that won't return un til the device has ) -eturn ed th e expec ted amount of report data. Using ReadFileExO or overlapped I/ O doe n't help. So it's best to place code that calls ReadFilesO in its own program thread, so it doesn' t hang the main application while waiting for data. Between the support provided by Windows and other operating systems and the wide availabi li ty of USB ports, HIDs a re worth a look. A HID i ' like- ly to be the quickest route to a fin - ished PC peripheral, and you can be confiden t th a t you 've chosen an in terface that will be around for a long while. esp Jan Axelson is the authoT of USB Complete: Everything You Need to Deve lop Custom USB Pe riphe rals. Portions of this article are adapted fran! material in USB Complete. Jan hosts a USB Centml /Jage for developers at www.lvr.com/ usb.htm. The Windows 98 and 2000 driver development kits (DDK5) include a fa irly complete tutorial on user-mode (application-level) HID communica- tions. The examples use C synt..:"1x, but with some translating you can use Visual BASIC, Delphi, or any other language that can call API functions. Table I lists the maj or API fun ctions used in HID communications. The first step in talking to any HID is findin g it. This requires a seri es of API calls that steps through all attached HIDs, looking for one that matches your criteria. You can look for a standard device type like a j oystick or keyboard, or YOll can look for a match with th e Vendor and Product IDs or Product String in your descriptors. The API functions Ulat idenLi fy and return a device pathname for each HID a re Windows Device Management FuncLions documented in the Windows NT and 2000 Platform Software Developme nt Kits (SDKs) , bUl not included in ule Windows 98 DDl<.. When you have a pathname, YOll can use CreateFile 0 to open a handle to the device, then use HID-specific API functions to read the Vendor and Product IDs, Product Strin g, and 70 OCTOBER 2000 Embedded Systems Programming Resources Ganssle, Jack. "An Introduction to USB Development," Embedded Systems Programming, March 2000, p. 79. HID Page (www.usb.orgldevelopers/ hidpage.htm/). Links to the HID specifi- cation, Usage Tables documents, and the Descriptor Tool. Hosted by the USB Implementers Forum. USBComp (www.usb.orgldeve/opersl too/s.htm/). A free suite of tools for compliance testing. DirectX Developers Center (msdn.microsoft.comldiredxl). The DirectX DDK, newsgroups, articles, and more.

Articles in this issue

Archives of this issue

view archives of EETimes - Embedded Systems October 2000 Vol13_11