ASCOM Generic UPS driver

The UPS ASCOM driver set-up for use with APC Back-UPS and PowerChute.
Figure 1: The UPS ASCOM driver set-up for use with APC Back-UPS and PowerChute.
As my MountCMD tool could not warm up the camera, I decided to write this ASCOM Generic UPS SafetyMonitor driver for use in Sequence Generator Pro (SGP). It is written in C# .NET using Visual Studio and has passed the ASCOM Conform test (report is included in the zip file). Version 0.4.6 can be downloaded from my server: http://www.dehilster.info/docs/GenericUPS-Setup.zip
The driver works with the events in the Windows Application Events Logbook (can be accessed via eventvwr). This SafetyMonitor can be combined with others, like a weather SafetyMonitor, by using the ASCOM SafetyMonitor Hub.1


Configuration

Before configuring the driver the UPS and its software should be installed (i.e. PowerChute for an APC UPS or PowerPanel for a CyberPower UPS).
The rest of the set-up can be done manually or semi-automatic.


Set-up fields

Windows eventvwr.
Figure 2: Windows eventvwr.
The Generic UPS SafetyMonitor works with a set of rules similar to a firewall. These rules can be specified and added by pressing the Add button. Once defined, each rule can be altered by clicking on the rule, editing the corresponding fields, and accept them by clicking the Update button.
There are several fields to be filled (see figure 2):
  • A: The Windows logbook to monitor (Application or System). Currently the Generic UPS SafetyMonitor can only monitor one logbook at the time.
  • B: The type of event (i.e. either SAFE or UNSAFE).
  • C: Specify whether or not the event is actively monitored by the driver.
  • D: Specify whether or not the driver is allowed to return to SAFE when the UNSAFE event has gone past its Set Unsafe Delay.
  • The event-id (E) and optionally a part of the message string (F) that specifies the event that serves as a trigger (both to be determined for your UPS through the Windows eventvwr (see #23@#) or by using the Learning mode)
  • G: The amount of time to wait until we have to stop the sequence after an UNSAFE event was found in order to be able to shutdown the ASCOM application properly.
  • H: A description can be entered for your own administration. This description will also be used when Trace On is selected.


Manual set-up using Windows EventViewer

Windows EventViewer
Figure 3: Windows EventViewer
In order to find these Event-IDs, unplug the UPS from mains at a given time (e.g. 16:20:30) and plug it in again a short while later (e.g. 16:23:35). Start the Windows Event Viewer by clicking the [Windows] and [R] keys, typing "eventvwr" (without the quotes) and hitting enter. It should result in the adjacent screen.
Goto Windows-logbook->Application and search for the times that the UPS took over control. Note down the two Event-IDs given for the UPS events (174 and 61455 in this example) and enter these values in the driver setup. In case these two IDs are equal, note down the messages that come with it. If the Application logbook does not contain the necessary information, the System logbook may contain them. In that case the "Logbook to Monitor" in the driver should be changed to "System".


Semi-automatic set-up

The Learn and Verbose checkboxes in the Generic UPS SafetyMonitor driver.
Figure 4: The Learn and Verbose checkboxes in the Generic UPS SafetyMonitor driver.
  • start the Generic UPS SafetyMonitor driver.
  • Switch in the learning mode by clicking on the Learn checkbox (see figure 4). Select the Windows logbook that should be monitored.
Learning mode will automatically detect all events that are logged in the selected Windows logbook. To avoid non-UPS-related events to be detected a filter can be defined by entering a number between 0 and 65525 in the EventID box. Only events with that number will be logged (useful for CyberPower UPS).
If it is to be expected that multiple events are used (as by an APC UPS) a range can be defined by entering a second number in the Unsafe Delay box.
Switching on the Verbose option (next to the Learn option) will cause the learning mode to show message boxes with the events that are found.
  • Click OK and connect the driver.


  • Two events captured automatically by the Learn and Verbose settings.
    Figure 5: Two events captured automatically by the Learn and Verbose settings.
    To test-fire the events:
    • Pull the mains cable. If Verbose was selected a message box should appear within 10-20 seconds (see figure 5). If nothing happens either the wrong logbook was selected or the filter range was set too tight, or the event was already defined in the set-up.
    • Re-insert the mains cable.
    • Disconnect the communication cable (USB or Ethernet, depending on your device), wait a few seconds, and reconnect it again.
    • Disconnect the communication cable, followed by the mains cable, reconnect the communications cable, followed by the mains cable.
    • Finally disconnect the mains cable, disconnect the communications cable, insert the mains cable, followed by the communications cable.
    • The above procedure will produce most of the safe and unsafe events, which are all stored as inactive Unsafe events (with a 999 minutes Unsafe Delay).
    • Accept all of the pop-ups to have them added to the set-up.
    • Disconnect the driver and open the driver properties dialogue window. Edit each new entry by clicking on them. Set the proper event type (Safe or Unsafe), the Unsafe Delay in case of an Unsafe event, and make it active. Click the Apply button to save the changes (pressing OK does not save the changes made!).
    There are bound to be more events (e.g. "Battery backup transferred to battery power due to electrical noise") that are not yet found. The currently found events are a good indication of the EventID range used by the UPS. Setting up a filter or filter range and leaving the learn mode on for some time may detect the rest of the events. Learning mode can be used while using the SafetyMonitor, although it is recommended to leave the Verbose option off when not attended.


    Behaviour

    The UPS ASCOM driver configured for a CyberPower UPS with PowerPanel Business.
    Figure 6: The UPS ASCOM driver configured for a CyberPower UPS with PowerPanel Business.
    If mains returns with the Set Unsafe Delay [minutes] time, the driver keeps the safe mode to safe. It will not return to safe when the delay time has expired, unless the option Report SAFE after Unsafe Delay is checked. There is, however, a risk that using this option will exhaust the UPS when multiple power failures occur shortly after each other. So use this option with caution and preferably with a short Set Unsafe Delay time.
    The Generic UPS driver communicates with the ASCOM SafetyMonitor Hub. In that driver a timer will be visible when the UPS fails, while the alert window turns orange as an indication that the system is becoming unsafe.
    The only thing not covered is the complete shutdown of the mount, but that is done using my MountCMD tool on computer shutdown.
    I have tested this driver with SGP and NINA, both doing their stuff with a ZWO ASI1600MM Cool, a 10Micron GM3000 mount and the slaved LesveDome, which all parked and warmed up properly.


    UPS systems tested so far

    Settings files are included in the zip-file and an be loaded using the Import button.
    Hopefully other people will test my Generic UPS Safety Monitor driver and give some feedback on how their UPS’s work. Please note that the driver will not work until the first image has been taken (that is a documented SGP feature, see the not at the bottom of their Safety Monitor page). If you wish to postpone imaging, it is best to have two targets in the sequence: one with a single exposure directly taken, the next target being timed.


    Change log

    v.0.0.1 (14/06/2019): first stable version.
    v.0.1.2 (23/06/2019): Added select options for System and Application, extended the triggers with search strings.
    v.0.2.0 (10/07/2019): Added the option to return to safe even when delay time has expired. Added communication with SafetyMonitor Hub.
    v.0.2.1 (10/07/2019): Bug fix in the count-down timer.
    v.0.3.0 (13/07/2019): Added communication with UPS tests to see if the UPS is still connected.
    v.0.4.0 (16/07/2019): Complete revised version of the UPS driver, now serializing events, by which it becomes possible to have an unlimited amount of SAFE and UNSAFE event detections.
    v.0.4.1 (16/07/2019): Added Learning mode, by which the driver semi-automatically adds UPS events found in the Event Viewer.
    v.0.4.2 (22/07/2019): Improved feedback of Learning mode, now not only showing the EventID, but also the event description.
    v.0.4.6 (07/09/2019): Fixed bug that resulted in shutdown if a SAFE event was triggered before an UNSAFE event (i.e. while the system was still SAFE).


    Disclaimer

    [1]: This driver is freeware, it's use is at your own risk! I cannot be held responsible for any damage caused due to improper set-up or malfunctioning of the driver.


    If you have any questions and/or remarks please let me know.


    Home Geodesy Navigation Astronomy Literature
    InFINNity Deck... Astrophotography... Astro-Software... Astro Reach-out... Equipment... White papers...
    ASCOM Generic UPS driver ASCOM Envir. SafetyMonitor ASCOM File SafetyMonitor ASCOM SafetyMonitor Hub Astronomical Twilight FITSalize Log10mGrabber MountCMD MountMonitor