
Designer Reference Manual USB08 Evaluation Board
144 Universal USB Device Driver (USBIO) MOTOROLA
Universal USB Device Driver (USBIO)
Handle2 and Handle3 are called pipe handles. Note that while Handle1 cannot be used to communicate with a pipe, any oper ation on the de vice can be executed by using Handle2 or Handle3, too.E.4.2 Establishing a Connection to the DeviceThe following code sample demonstrates the steps that are necessary at the USBIO API to establish a handle for a device and a pip e. The code is not complete, no error handling is included.// include the interface header fi le of USB IO.SYS
#include “usbio_i.h”
// device instance number
#define DEVICE_NUMBER 0
// some local variables
HANDLE FileHandle;
USBIO_SET_CONFIGURATION SetConfiguration;
USBIO_BIND_PIPE BindPip e;
HDEVINFO DevInfo;
GUID g_UsbioID = USBIO_IID;
SP_DEVICE_INTERFACE_DAT A Dev Da ta;
SP_INTERFACE_DEVICE_DET AI L_D ATA *DevDetail = NULL;
DWORD ReqLen;
DWORD BytesReturned;
// enumerate the devices
// get a handle to the device list
DevInfo = SetupDiGetClassDev s (& g_ UsbioID,
NULL,NULL,DIGCF_DEVICEI NTERFACE|DIGCF_PRESENT);
// get the device with index DEVICE_NUMBER
SetupDiEnumDeviceInterf ac es (D evInfo, NULL,
&g_usbioID, DEVICE_NUMBER, &DevData );
// get length of detail ed information
SetupDiGetDeviceInterfa ceDetail (DevInfo, &DevD ata, NULL,
0, &ReqLen, NULL);
// allocate a buffer
DevDetail = (SP_INTERFA CE_DEVICE_DETAIL_DATA*) malloc (ReqLen);
// now get the detailed device information
DevDetail->cbSize = siz eof(SP_INTERFACE_DEVICE_ DETAIL_DATA);
SetupDiGetDeviceInterfa ceDetail (DevInfo, &DevD ata, DevDetail,
ReqLen, &ReqLen, NULL);
// open the device, use OVERLAPPED flag if nece ssary
// use DevDetail->Devic ePath as device name
FileHandle = CreateFile(
DevDetail->DevicePath,
GENERIC_READ|GENERIC_WR ITE,
FILE_SHARE_WRITE|FILE_S HARE_READ,
NULL,
OPEN_EXISTING,
0 /* or FILE_FLAG_OVERLAPPED */,
NULL);