This process will be broken into two parts: first create an application (EXE) that will be called by the UPS Management Software when a power failure occurs. This application should create an AEvent object with a name "UPSPowerFailEvent". After creating it, use the PulseEvent() method to signal the test application that the UPS is now running on battery power and it needs to shut down. Second, the test application will create a thread to watch for a UPSPowerFailEvent signal and if received shut down gracefully.
Step 1: Create an application to be run by the UPS Management Software in the event of a power failure. Note: the UPS Management Software is supplied with the UPS
In ATEasy create an application (for example UPSPowerFailure). In the OnInit event procedure create an object called UPSPowerFailEvent (an object with the same name will be created by the test application). Then use the PulseEvent() method to signal the test application that a power failure has occured.
obUPSEvent: AEvent !Object to inform test application of UPS power failure
obUPSEvent = CreateObject("AEvent") ! Create an AEvent object
obUPSEvent.Name="UPSPowerFailEvent" ! Give it the same name as the test application thread
obUPSEvent.PulseEvent() ! Signal the test application of the UPS power failure and that it
! should shutdown
Compile the application and add the name of the executable file to the UPS Management Software Event Notification command line.
Step 2: The test application should create a thread when it starts (OnInit). The thread will call a procedure (called MonitorForUPSEvent() in this example). In the procedure create an event with the same name "UPSPowerFailEvent" as used Step 1 above. Then call WaitForSingleObject() to monitor the event signal. Once the wait returns perform the shut down of the application (call abort, exit, display a message etc):
lThread: Val Long ! Required to create the thread
obUPSEvent: AEvent ! Object to be monitored for UPS Failure
obUPSEvent = CreateObject("AEvent") ! Create an object
obUPSEvent.Name=" UPSPowerFailEvent " ! Give it the same name as Step 1
WaitForSingleObject(obUPSEvent.Handle,) ! Wait for a Pulse Event to occur
! Once the PulseEvent has occurred there are multiple ways of dealing with the shutdown process. These will mainly depend
! on the UPS battery run time. In this example we will use Abort.
Abort !Jump to System.OnAbort. Add code to OnAbort to run all the instrument and application shutdown routines
For instructions on shutting down Windows from ATEasy see KB Article Q200070
The language.prg has additional examples of how to use events.