I recently added a bit of code before a call to USBDriverStatus() to check if the driver window was open (and therefore the driver running). If the driver isn't running the code attempts to run the driver (see code below).
I then check again see if it is running and then i make a call to USBDriverStatus() and check everything is OK with the driver, but if i've just launched the driver from within code, USBDriverStatus() allways returns NOT_USB. I've changed the code to ignore this and everything works OK (i am able to intialise the rest of the hardware, but the NOT_USB return is obviously wrong (there are no PCI cards in the machine for a start). I can't see anything that is incorrect within my code:
Code: Select all
if(FindWindowEx (NULL,NULL,NULL,"AES Windowed USB Driver") == NULL)
{
CString driverPath;
char tmpPath[513];
tmpPath[0] = 0;
::_getcwd(tmpPath,512);
if(tmpPath[strlen(tmpPath)] != '\\')
{
strcat(tmpPath,"\\");
}
driverPath = CString(tmpPath);
strcat(tmpPath,"AESWDriver.exe");
ShellExecute(NULL,"open",tmpPath,NULL,driverPath,SW_SHOWMINNOACTIVE);
Sleep (700); //give the driver a chance to start (normally takes 200 - 300 ms)
}
if(FindWindowEx (NULL,NULL,NULL,"AES Windowed USB Driver") == NULL)
{
retVal = MHE_USB_DRIVER_NOT_RUNNING;
return retVal;
}
switch (USBDriverStatus())
{
case STANDARD_DRIVER:
retVal = MHE_OK;
break;
case NOT_USB:
this->lastError = CString("FATAL ERROR, no USB paylink card detected!");
retVal = MHE_USB_DRIVER_FATAL;
break;
case USB_IDLE:
this->lastError = CString("ERROR, USB driver not running, please locate the driver (\"AES Windowed USB Driver\"), place it in the start->programs->startup menu and restart the machine.");
retVal = MHE_USB_DRIVER_NOT_RUNNING;
break;
case FLASH_LOADER:
case MANUFACTURING_TEST:
this->lastError = CString("ERROR, paylink card link is busy, please retry later. If you continue to get this message, please restart the machine and try again.");
retVal = MHE_USB_DRIVER_BUSY;
break;
case DRIVER_RESTART:
this->lastError = CString("ERROR, the paylink driver is restarting or about to exit. Please ensure it is running and retry.");
retVal = MHE_USB_DRIVER_RESTARTING;
break;
case USB_ERROR:
this->lastError = CString("FATAL ERROR, there is a problem with the low-level USB driver.");
retVal = MHE_USB_DRIVER_LOW_LEVEL;
break;
default:
this->lastError = CString("UNKOWN ERROR, an unknown error was encountered checking the status of the USB driver");
retVal = MHE_USB_DRIVER_UNKNOWN;
break;
}