Specifications

AN93
Rev. 0.9 217
{
unsigned long ulNoOfbytes;
strcpy(cpOutBuffer, cpCommand);
WriteFile(hCom, (long *)cpOutBuffer, strlen((char *)cpOutBuffer),
&ulNoOfbytes, 0);
if(iTimeoutMs)
cpInBuffRd = WaitForResponse(cpResponse, cpInBuffRd, iTimeoutMs);
if(!cpInBuffRd)
exit(0);
return cpInBuffRd;
}
// Check for a specific response in the input buffer, and return ptr to what
// follows. If this times out or ERRORs before the response is found then a
// NULL is returned; It keeps reading the ser channel while waiting
char *WaitForResponse(char *cpResponse, char *cpInputBuffer, int iTimeOutInMs)
{
unsigned long ulNoOfbytes;
clock_t sStartTime = clock();
clock_t sCurrentTime;
// covert wait time in ms's to clock_t by mutiplying by CLOCKS_PER_SEC/1000
clock_t sWaitTime = (clock_t)(iTimeOutInMs*CLOCKS_PER_SEC)/1000;
int iPasses = 0;
int iCharCnt =0; // set to 0
while(1)
{
char cTemp = *cpInputWr;
*cpInputWr = 0;
char *cpFound = strstr(cpInputBuffer, cpResponse);
*cpInputWr = cTemp;
if(cpFound)
{//copy the received bytes for late display
strncpy(cpInput_test, cpInputBuffer, iCharCnt);cpInput_test[iCharCnt]='\0';
return cpFound + strlen(cpResponse);
}
// Setup a 50 ms timeout for reads
sCOMMTIMEOUTS.ReadIntervalTimeout = 0;
sCOMMTIMEOUTS.ReadTotalTimeoutMultiplier = 0;
sCOMMTIMEOUTS.ReadTotalTimeoutConstant = 50;
sCOMMTIMEOUTS.WriteTotalTimeoutMultiplier = 0;
sCOMMTIMEOUTS.WriteTotalTimeoutConstant = 0;