Getting Started

HID Class DLL

HID Class DLL
Getting Started

The DLL is simple and easy to use. Associate the DLL with the project, declare the name space, initialize the DLL and then read and write as necessary: 

First Associate the DLL with the application. In Visual C++ 2008 Express Edition, select Project | Properties (Alt-F7). "Framework and References" tab. Add New Reference button, Browse Tab. Then navigate to the DLL location and add it to the project. 

Next, Add "using namespace HIDClass;" to the namespace section at the top of your code. 

Then you only need three calls to use the library. HIDClassInit, HIDWriteReport and HIDReadReport. Other calls are provided but are not required to communicate with device. 

HID Class Init configures the DLL with the needed information that does not change: Vendor ID, Product ID, Buffer Size and Timeout (optional). This can be called from your application's constructor. 

Both Read and Write functions first check to see if the device has been opened before attempting to communication with the device. If it not it opens a channel and then completes the communication. This allows seamless recovery if a device has been disconnected then reconnected. 

The read and write functions both return a boolean indicating if the transfer was successful or not. Suggest testing these to verify the transfer and recover gracefully if not. 

 

HIDClassInit (0x04D8, 0x0032, 64);

OutBuffer[0] = SOME_COMMAND;
OutBuffer[1] = SOME_COMMAND_PARAMETER_1;
OutBuffer[2] = SOME_COMMAND_PARAMETER_2;
OutBuffer[3] = SOME_COMMAND_PARAMETER_3;
if (MCHPHIDCLASS::HIDWriteReport (OutBuffer, 4)
{
    if (MCHPHIDCLASS::HIDReadReport (InBuffer))
    {
        // process InBuffer
    }
    else
    {
        // appropriate reaction to not receiving data
    }
}
else
{
    MessageBox ("Is the device connected?");
}
Microchip HID Class DLL 1.10 - [15 April 2010]
Copyright © 2009, 2010 Microchip Technology, Inc.  All rights reserved.