Rockwell Automation 1789-L10_L30_L60 SoftLogix 5800 System User Manual User Manual

Page 149

Advertising
background image

Rockwell Automation Publication 1789-UM002J-EN-P - December 2012

149

Program Windows Events to Monitor and Change Controller Execution

Chapter 8

// Use strings to define the event names in which we are interested
// The user will pass in the slot number via the command line
TCHAR sa_mode_change_event_fmt[] = _T("SOFTLOGIX_%02d_MODE_CHANGE");
TCHAR sa_program_event_fmt[] = _T("SOFTLOGIX_%02d_PROGRAM");
TCHAR sa_run_event_fmt[] = _T("SOFTLOGIX_%02d_RUN");
TCHAR sa_test_event_fmt[] = _T("SOFTLOGIX_%02d_TEST");
TCHAR sa_fault_event_fmt[] = _T("SOFTLOGIX_%02d_FAULT");

int main(int argc, char *argv[])
{
int slot = 0;
DWORD status = 0;
TCHAR eventname[_MAX_PATH];
// We will keep the mode event handles in an array for the WaitForMultipleObjects call
HANDLE EventArray[4];
HANDLE *events = &EventArray[0];
int numevents = 0;

// Make sure a slot number is passed in on the command line
argc--, argv++;
if (argc != 1)
{
_tprintf(_T("You must enter a slot number on the command line.\n"));
fflush(stdout);
return 1;
}

slot = atoi(*argv);
(void) GetLastError();

// Create the mode change event. Note: it must be created as auto reset.
_stprintf(eventname, sa_mode_change_event_fmt, slot);
hModeChange = CreateEvent (NULL, FALSE, FALSE, eventname);
if (hModeChange == NULL)
{
_tprintf(_T("Bad mode change handle\n"));
_tprintf(_T("GetLastError() = %d\n"), GetLastError());
return 1;
}

// Create the program mode event. Note: it must be created as manual reset.
_stprintf(eventname, sa_program_event_fmt, slot);
hProgramMode = CreateEvent (NULL, TRUE, FALSE, eventname);
if (hProgramMode == NULL)
{
_tprintf(_T("Bad program mode event handle\n"));
_tprintf(_T("GetLastError() = %d\n"), GetLastError());
return 1;
}
else
{
// Add the program mode event to the event array
EventArray[numevents] = hProgramMode;
numevents++;
}

// Create the run mode event. Note: it must be created as manual reset.
_stprintf(eventname, sa_run_event_fmt, slot);
hRunMode = CreateEvent (NULL, TRUE, FALSE, eventname);
if (hRunMode == NULL)

Advertising