Agilent Technologies E4371A Lawn Mower User Manual


 
C Program Examples - 7
113
// Signal threads to start reading logs.
SetEvent(ThreadInfo[0].hStart);
SetEvent(ThreadInfo[1].hStart);
// Wait for threads to terminate.
WaitForSingleObject(hReadThread0, INFINITE);
WaitForSingleObject(hReadThread1, INFINITE);
printf("Press any key to exit\n");
getchar();
}
/*****************************************************************************
Thread to read log from MCCD.
*****************************************************************************/
DWORD WINAPI ReadThread(LPVOID lpvThreadParm)
{
int nThread = (int)lpvThreadParm;
CF_READP readPos;
FILE *hFile;
char szMeasBuffer[MEAS_BUF_SIZE];
char szTimeStamp[LINE_SIZE];
int nMeasBufCount;
CF_HANDLE hServer;
// Wait for a signal to start reading the data logs.
WaitForSingleObject(ThreadInfo[nThread].hStart, INFINITE);
// Open a connection to MCCD.
printf("Thread %d trying MCCD: %s\n", nThread,
ThreadInfo[nThread].szAddr);
if (cfOpen(ThreadInfo[nThread].szAddr, &hServer, PASSWORD) != CF_OK) {
printf("Thread %d could not connect to MCCD: %s\n",
nThread, ThreadInfo[nThread].szAddr);
return 1;
}
printf("Thread %d connected to MCCD: %s\n", nThread,
ThreadInfo[nThread].szAddr);
// Read the measurement log to a file.
if((hFile = fopen(ThreadInfo[nThread].szLogFile, "w")) != NULL) {
GetTimeStamp(szTimeStamp);
fwrite(szTimeStamp, sizeof(char), strlen(szTimeStamp), hFile);
readPos = CF_READ_FIRST;
while (1) {
cfReadMeasLog(hServer, &readPos, CF_ALL_CELLS, CF_ALL_STEPS,
MEAS_BUF_SIZE, szMeasBuffer, &nMeasBufCount);
if (nMeasBufCount == 0)
break;
fwrite(szMeasBuffer, sizeof(char), nMeasBufCount, hFile);
}
GetTimeStamp(szTimeStamp);
fwrite(szTimeStamp, sizeof(char), strlen(szTimeStamp), hFile);
fclose(hFile);
}
return 0;
}