Agilent Technologies E4375A Video Gaming Accessories User Manual


 
7 - C Program Examples
112
Example 3
You can control up to 16 Agilent MCCDs from one PC and still achieve good system responsiveness,
depending on the application program structure.
This following C program example uses a multi-threaded program in which each thread can
independently control one Agilent MCCD but can share data with a user interface thread. This provides
the advantage of a central system view of all of the Agilent MCCDs, with the simplicity of each thread
controlling only one Agilent MCCD. With this type of program, you must be careful to use
synchronization objects to access any shared data. Overall, using a multi-threaded program is simpler
than writing a single-threaded program to control multiple Agilent MCCDs.
#include <windows.h>
#include <stdio.h>
#include <time.h>
#include "mccd.h"
#define MEAS_BUF_SIZE CF_MEAS_LOG_BUFSIZE
#define LINE_SIZE 80
#define PASSWORD "mufasa"
// Structure for thread information
typedef struct {
char *szAddr;
char *szLogFile;
HANDLE hStart;
} THREAD_INFO;
THREAD_INFO ThreadInfo[] = {
{"15.14.250.130", "mccdlog0.txt", NULL},
{"15.14.250.124", "mccdlog1.txt", NULL},
};
// Local function prototypes
void GetTimeStamp(char *szTimeStamp);
void ErrorHandler(CF_HANDLE server, char *function, int errorcode);
DWORD WINAPI ReadThread(LPVOID lpvThreadParm);
/*****************************************************************************
Main function
*****************************************************************************/
void main (int argc, char *argv[])
{
DWORD dwThreadId;
HANDLE hReadThread0, hReadThread1;
// Create events to signal threads to start reading.
ThreadInfo[0].hStart = CreateEvent(NULL, FALSE, FALSE, NULL);
ThreadInfo[1].hStart = CreateEvent(NULL, FALSE, FALSE, NULL);
// Create threads to read log from MCCDs.
hReadThread0 = CreateThread(NULL, 0, ReadThread, (LPVOID)0, 0,
&dwThreadId);
hReadThread1 = CreateThread(NULL, 0, ReadThread, (LPVOID)1, 0,
&dwThreadId);