Rockwell Automation Publication 1789-UM002K-EN-P - January 2015
159
Program Windows Events to Monitor and Change Controller Execution
Chapter 8
swprintf(eventname, sa_savedone_event_fmt, slot);
h_saveDoneEvent = CreateEvent (&sa, TRUE, FALSE, eventname);
printf("h_saveDoneEvent = %d
swprintf(eventname, sa_savelock_event_fmt, slot);
h_saveLockEvent = CreateEvent (&sa, TRUE, FALSE, eventname);
printf("h_saveLockEvent = %d
// Yield remainder of timeslice to make it less likely that a
// context switch will occur between the wait for lock event and
// corresponding SetEvent().
// If saves not permitted (download in progress) OR
// a save is in progress
// Explain
// Else
// Set lock event
// Kick save event
// Endif
// Wait for save started (if desired)
// Wait for save done (if desired)
SwitchToThread();
if ((WaitForSingleObject(h_savePermittedEvent, 0) != WAIT_OBJECT_0) ||
WaitForSingleObject(h_saveLockEvent, 0) == WAIT_OBJECT_0)
{
printf("Save not permitted or save already running
return 1;
}
else
{
SetEvent(h_saveLockEvent); // Save in progress
printf("Kicking save
SetEvent(h_kicksaveEvent);
}
WaitForSingleObject(h_saveStartEvent, INFINITE);
printf("Save started
WaitForSingleObject(h_saveDoneEvent, INFINITE);
printf("Save complete
return 0;
}