A number of our devices have a built-in RS-232 port for reading data from uninterruptible power supplies (UPS) using the two most common communication protocols – Megatec and Voltronic. To facilitate device testing, we have developed a small emulator program. It is about her that will be discussed further.
The Megatec and Voltronic protocols are textual and fairly simple. Data exchange is carried out at a low speed of 2400 bps, 8 data bits, without parity, on the basis of the “request-response” principle. Requests are text strings of one to three characters in length, terminated by a line feed byte (code 0x0D). Answers also come in text form with the terminating character 0x0D. The values in the responses are separated by spaces. Numbers can be transmitted either with leading zeros or with additional spaces.
Depending on the specific UPS, there may be a different number of such commands, but basic information can be obtained using four of them. Let’s consider them in more detail.
Q1 – request for the current state
(MMM.M NNN.N PPP.P QQQ RR.R S.SS TT.T b7b6b5b4b3b2b1b0
( Is the starting character.
MMM.M – input voltage, V.
NNN.N – voltage at which the last time the switch to battery operation was carried out, V.
PPP.P – output voltage, V.
QQQ – power consumption,%.
RR.R – mains frequency, Hz.
SS.S – battery voltage, V. It can be transmitted in two formats: SS.S – for line-interactive UPS or S.SS – for online UPS (voltage on one element is indicated).
TT.T – UPS temperature, ° C.
b7 … b0 – status bits, which can be 0 or 1.
b7 – 1: battery operation, 0: mains operation.
b6 – 1: low battery level, 0: battery normal.
b5 – 1: bypass enabled, 0: bypass disabled (online UPS only).
b4 – 1: UPS alarm, 0: UPS ok.
b3 – 1: line-interactive UPS, 0: online-UPS.
b2 – 1: UPS test started.
b1 – 1: UPS is off, 0: UPS is on.
b0 – 1: beep on, 0: off.
I – request for information about the UPS
#CompanyName Model Version
# Is the starting character.
CompanyName – UPS manufacturer.
Model – model name.
Version – UPS version.
F – request for information on the nominal parameters of the UPS
# MMM.M QQQ SS.SS RR.R
# Is the starting character.
MMM.M – rated output voltage, V.
QQQ – rated output current, A.
SS.SS – nominal battery voltage, V (can be in SS.SS or SSS.S formats).
RR.R – rated frequency of the output voltage, Hz.
QBV – request for information about the battery
(RRR.R NN MM CCC TTT
( Is the starting character.
RRR.R – nominal voltage of the battery, V.
NN – the number of batteries in the battery, pcs.
MM – number of parallel groups of batteries, pcs.
CCC – battery capacity,%.
TTT – the remaining operating time from the battery, min.
In addition to commands that read any UPS parameters, there are also control commands. Often used are:
T – start the battery test for 10 sec.
TL – start battery test until full discharge.
CT – stop battery test.
Q – enable / disable the UPS buzzer.
At first glance, the above commands are very simple, but the devil, as usual, is in the little things. For example, some UPSs do not respond to commands at all. I and QBV… An example is a number of models from Ippon.
It is also observed that various UPSs execute the command Q (beep control) for completely different times. That is, from the moment the command is issued Q and until the bit change b0 in response to the command Q1 it can take up to 30 seconds !!! And since switching on and off is carried out by one command, then with automated control, an “oscillatory” process can begin. For example, the off state of the sound signal is set to the controller via the web interface. It analyzes the current status of the UPS (by flag b0), and if it differs from the required one, then issues the command Q… On next request Q1 the controller checks the flag again b0 and sees that he has not changed. As a result, he again gives the command Q… But all this time, the UPS was actually “thinking about” something inside, so it did not immediately react to the first Q, and then the second one has already arrived. As a result, the audible signal may remain on. Moreover, in some UPSs, when the status of the audio signal changes, a short “beep” is performed. And because of this “oscillatory” process, these “beeps” can be emitted many times, until finally the controller and the UPS are “synchronized”.
We solved this problem simply – we change the state of the sound signal only once a minute. During this time, everything inside the UPS will “settle down”.
Another interesting point is the calculation of the remaining battery capacity. It is considered according to a simplified formula:
U – current battery voltage.
Umin– the minimum allowable voltage on the battery (usually about 10V).
Umax– voltage of the charged battery (usually 13.8 … 14.2V).
This is usually enough to estimate the remaining charge.
The Voltronic protocol on the set of the above commands differs only in one of them – instead of the code Q1 used by QS… In this case, the response formats are the same. Our devices have an automatic detection of the exchange protocol based on this difference. The controller, when turned on, tries to send commands one by one Q1 and QS… To which one the answer comes, that protocol is further used. If, within a certain timeout, responses to the command cease to come (another UPS was connected “to hot”), then the protocol definition is automatically restarted.
So, as you can see above, with all the simplicity of these protocols, there can be quite a lot of various combinations of data. Therefore, an emulator program was developed to facilitate testing of our devices.
It is a screen with settings and a choice of a COM port through which the exchange will be carried out. All of the above commands are supported, including those for running tests:
Working with the program will cause difficulties. You can change any parameters right in the process of work, and immediately see the result:
To evaluate the work of the program in dynamics, I recorded a short video:
The emulator program itself can be downloaded here…