/*******************************************************************/
/*                                                                 */
/* File Name:   UsbHidApi_2.h                                      */
/*                                                                 */
/* Description:                                                    */
/*                                                                 */
/*    This DLL provides a relatively simple method for accessing   */
/*    a USB HID device.  The device must specify HID reports for   */
/*    transferring data.                                           */
/*                                                                 */
/*    Client applications use the exported methods from the        */
/*    CUsbHidApi class to identify and access external             */
/*    HID device(s).  A new instance of the class must             */
/*    be created for each device being accessed.                   */
/*                                                                 */
/*                                                                 */
/* Revision History:                                               */
/*                                                                 */
/*    Name              Date      Description                      */
/*    ----              ----      -----------                      */
/*    K.Delahoussaye    5/13/03   Initial version                  */
/*    K.Delahoussaye    3/06/05   Added _stdcall prefix for export */
/*                                capability.                      */
/*    K.Delahoussaye    9/13/05   Inserted #ifndef block.          */
/*    K.Delahoussaye    3/12/07   Added cabability to search       *
/*                                 interfaces and/or collections.  */
/*    S. Murthy         9/06/07   Modified for LabWindows/CVI.     */
/*    L. Tell           9/20/07   Modified for LabWindows/CVI.     */
/*                                to match UsbHid.fp function panel*/
/*******************************************************************/

#ifndef __USBHID_API_H__
#define __USBHID_API_H__
//
// Notes:
// -----
// 
// This DLL provides the client application an easy method for accessing
// an HID device via USB link.  The acts of reading and writing 
// a USB device under Windows are significantly different and more
// involved than for other comm devices such as serial comm ports.
// For this reason, it seemed necessary to encapsulate the complexity
// of the interface within a DLL.  This DLL provides all the required
// functions for accessing the device, while hiding the details
// of the implementation.
//
// The USB link is implemented as a Human Interface Device (HID) class
// function.  As such, the DLL is dependent on the following Windows
// drivers:
//
//   hidclass.sys   hidparse.sys    hidusb.sys
//
// In addition to being USB-compliant, the host PC should have the 
// latest, versions of these drivers.  (Initial development was done
// using drivers from Windows 98, 2nd edition.)
//
// The module was built using Microsoft Visual C++, 6.0 as a Win32, 
// non-MFC DLL.  Since there is no dependence on the Microsoft 
// Foundation Class (MFC), there is no need to copy additional MFC 
// DLLs to your Windows system folder.  Also, no dependence on MFC
// means the size of the DLL itself is minimal.  (Although the DLL
// does not internally use the MFC, the client application is not
// restricted.  Exported functions in the DLL may be called by either
// MFC or non-MFC applications.)
//
// The client application may link implicitly or explicitly with the
// DLL.  In explicit linking, the client application makes function 
// calls to explicitly load and unload the DLL's exported functions.
// In implicit linking, the application links to an import library
// (UsbHidApi.lib) and makes function calls just as if the functions 
// were contained within the executable.
//
#define USBHIDAPI_DLL_NAME	"UsbHidApi.dll"

// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the USBHIDAPI_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// USBHIDAPI_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef USBHIDAPI_EXPORTS
#define USBHIDAPI_API __declspec(dllexport)
#else
#define USBHIDAPI_API __declspec(dllimport)
#endif

   // This structure defines an entry in a device list
   // The list describes the parameters associated with
   // a device.  It is mainly used with the GetList()
   // function. 
   // modified 3/12/07
   typedef struct {
    char         DeviceName[50];   // Device name
    char         Manufacturer[50]; // Manufacturer
    char         SerialNumber[20]; // Serial number
    unsigned int VendorID;         // Vendor ID
    unsigned int ProductID;        // Product ID
    int          InputReportLen;   // Length of HID input report (bytes)
    int          OutputReportLen;  // Length of HID output report (bytes)
    int          Interface;        // Interface  
    int          Collection;       // Collection 
   } mdeviceList;

   // This structure was created to ease VB access.  It alleviates
   // some of the issues associated with inter-compiler data handling
   // such as alignment.
   // added 3/8/05
//#pragma pack (push, 4)
   typedef struct {
    char         *DeviceName;   // Device name
    char         *Manufacturer; // Manufacturer
    char         *SerialNumber; // Serial number
    unsigned int VendorID;         // Vendor ID
    unsigned int ProductID;        // Product ID
    int          InputReportLen;   // Length of HID input report (bytes)
    int          OutputReportLen;  // Length of HID output report (bytes)
    int          Interface;        // Interface  
    int          Collection;       // Collection 
   } mdeviceList2;
//#pragma pack (pop,4)

	int _stdcall GetList(unsigned int VendorID, 
								unsigned int ProductID, 
								char *Manufacturer, 
								char *SerialNum, 
								char *DeviceName, 
								mdeviceList2 *pList, 
								int nMaxDevices);

	int _stdcall Open (unsigned int VendorID,
                                   unsigned int ProductID,
                                   char         *Manufacturer,
                                   char         *SerialNum,
                                   char         *DeviceName,
                                   int          bAsync);
	
	int _stdcall Read(void *pBuf);                   // Read the from the HID device.

	int _stdcall Write(void *pBuf);                  // Write to the HID device

	void  _stdcall CloseRead(void);                  // Close the read pipe

	void  _stdcall CloseWrite(void);                 // Close the write pipe

	void _stdcall GetReportLengths (int *input_len, int *output_len); // Pointer for storing output length

	void _stdcall SetCollection(int col);                // Specifies a collection (call prior to Open())  (0xffff = unspecified)

	int _stdcall GetCollection();                    // Retrieves collection setting (0xffff = unspecified)
	
	int _stdcall SetInstance(int instance);          // Set object instance


	int _stdcall GetLibVersion(char *buf);           // Get DLL version string


#endif
