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

Page 150

Advertising
background image

150

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

Chapter 8

Program Windows Events to Monitor and Change Controller Execution

{
_tprintf(_T("Bad run mode event handle\n"));
_tprintf(_T("GetLastError() = %d\n"), GetLastError());
return 1;
}
else
{
// Add the run mode event to the event array
EventArray[numevents] = hRunMode;
numevents++;
}

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

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

// We are now ready to start waiting for mode changes!
_tprintf(_T("Ready\n"));
fflush(stdout);

// Loop forever, waiting for mode changes. The user must perform a control-c to
// stop the application
while (1)
{
// First we wait for the single mode change event. The mode change event is an
// automatic reset event that is set by the SoftLogix controller every time the
// controller is changing modes. Once the mode change event is set, we need to
// check the state of the acutal mode events.
status = WaitForSingleObject(hModeChange,INFINITE);
switch (status)
{
case WAIT_OBJECT_0:

Advertising