I'm using Cypress C++ Library to design a DLL for the Hardware Controller.
I would like to add USB plug and play feature in my DLL using Cypress library functions.
How can I add this feature in my DLL using Cypress C++ library functions?
My C++ Code sample:
void RefreshList(HWND AppHandle)
{
int vid, pid;
CyStreamdev = NULL;
for(UCHAR i=0;i<cyusbdevice->DeviceCount();i++)
{
CyUSBDevice->Open(i);
vid = CyUSBDevice->VendorID;
pid = CyUSBDevice->ProductID;
if(vid == 0x232D && pid == 0x1151)
{
CyStreamdev = new CCyUSBDevice(AppHandle, CYUSBDRV_GUID,true);
}
}
}
int GetDevice(HWND AppHandle)
{
int ErrorCode;
CyUSBDevice = new CCyUSBDevice(AppHandle,CYUSBDRV_GUID,true);
AltInterface = 0;
if (CyUSBDevice->DeviceCount())
{
ErrorCode = CD940_SUCCESS;
}
else
{
ErrorCode = CD940_CARD_NOT_DETECTED;
}
RefreshList(AppHandle);
return ErrorCode;
}
bool FindCard(CCyUSBDevice *USBDevice, USHORT VID, USHORT PID)
{
int numDevices = USBDevice->DeviceCount();
UCHAR deviceNum = 0;
CD940Found = false;
do
{
USBDevice->Open(deviceNum); if((USBDevice->VendorID == VID) && (USBDevice->ProductID == PID))
CD940Found = true;
deviceNum++;
} while ((deviceNum < numDevices ) && !CD940Found);
return(CD940Found);
};
int InitialiseDLL1(HWND AppHandle)
{
CD940USBRegInterface = NULL;
CD940FEB = NULL;
CyUSBDevice = NULL;
CyUSBDevice = new CCyUSBDevice(AppHandle,CYUSBDRV_GUID,true);
if (FindCard(CyUSBDevice, CD940VID, CD940DID) && CyUSBDevice->IsOpen()) {
CD940USBRegInterface = new CyUSBRegisters(CyUSBDevice); CD940FEB = new CD940FrontEndBoard(CD940USBRegInterface);
}
if((CD940FEB != NULL) && Found() && (CyUSBDevice != NULL))
{
ErrorCode = CD940_SUCCESS;
}
else
{
MessageBoxA(NULL, "CD940 Not Found, Please Contact Edinburgh Instruments!!!", "CD940 Error", MB_OK | MB_ICONERROR);
ErrorCode = CD940_CARD_NOT_DETECTED;
}
return ErrorCode;
};
LRESULT CALLBACK WndProc(HWND AppHandle, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(wParam)
{
case DBT_DEVNODES_CHANGED:
bPnP_DevNodeChange = true;
bPnP_Removal = false;
break;
case DBT_DEVICEARRIVAL:
bPnP_DevNodeChange = true;
bPnP_Removal = false;
break;
case DBT_DEVICEREMOVECOMPLETE:
bPnP_Removal = true;
break;
default:
return DefWindowProc(AppHandle, msg, wParam, lParam );
}
return 0;
}
int _stdcall InitialiseDLL(HWND AppHandle)
{
if (bPnP_DevNodeChange && bPnP_Removal)
{
bPnP_Removal = false;
bPnP_DevNodeChange = false;
GetDevice(AppHandle);
}
if (bPnP_DevNodeChange && bPnP_Arrival)
{
bPnP_Arrival = false;
bPnP_DevNodeChange = false;
GetDevice(AppHandle);
}
InitialiseDLL1(AppHandle);
return ErrorCode;
}
Thanks!