Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C++
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);   // Open automatically  calls Close(  ) if nece
		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())	//Look for CD940
	{
		CD940USBRegInterface = new CyUSBRegisters(CyUSBDevice);	// Create USB Register handling object
		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:
		/*
		Process other WM_DEVICECHANGE notifications for other
		devices or reasons.
		*/
		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 DBT_DEVICEARRIVAL followed by DBT_DEVNODES_CHANGED 
	if (bPnP_DevNodeChange && bPnP_Arrival) 
	{ 
		bPnP_Arrival = false;
		bPnP_DevNodeChange = false;
		GetDevice(AppHandle); 
	} 	 
	InitialiseDLL1(AppHandle);
	return ErrorCode;
}


Thanks!
Posted
Updated 7-Oct-13 9:48am
v5
Comments
Richard MacCutchan 7-Oct-13 11:09am    
Probably by reading the Cypress documentation.
[no name] 7-Oct-13 18:27pm    
Or posting the question on the appropriate Cypress forum.
http://www.cypress.com/?app=forum&id=167&rID=42100&source=support

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900