Premise Questions on Building an APC Smart UPS Driver

Motorola Premise

etc6849

Senior Member
I had another thread under the hardware section that generically discussed building an APC SmartUPS driver. I thought it would be more appropriate to move the discuss here as I'm now convinced my problem lies with Premise.

My progress so far: The attached PDF found here: http://www.apcupsd.com/manual/manual.pdf describes how to test UPS communications on page 71:

"The first thing to do is to look at your log file, usually /var/log/messages because apcupsd writes more detailed information to the log file whenever there is an error. If you have a UPS that uses apcsmart protocol, you can manually test the serial communications with the UPS by starting a serial port communications program (such as minicom, tip, or cu) with the settings 2400 8N1 (2400 baud, 8 data bits, no parity, 1 stop bit). Be extremely careful what you send to your UPS as certain characters may cause it to power down or may even cause damage to the UPS. Try sending an upper case Y to the UPS (without a return at the end). It should respond with SM. If this is not the case, review the possible problems listed above. If you fat finger the Y and enter y instead, no cause for alarm, you will simply get the APC copyright notice. Once you are sure that serial port communications is working, proceed to the next test."

I am able to test communications just fine use PuTTY with the default terminal settings. The commands on page 98 of the PDF all work after first sending a "Y" to the UPS to initiate communications.

However, when I try to use the same commands in Premise, after sending "Y" nothing is received? (SM plus 0D 0A should be sent back from the UPS). Any ideas? If serial communications work under PuTTY, shouldn't Premise work too? A test driver is attached that should result in SM being received.
 

Attachments

  • APC.zip
    1.7 KB · Views: 18
What have you observed in Port Spy?

At bare minimum, it should show the "Y" character (hex 59) transmitted. Any responses from the UPS will also be visible in Port Spy.


PS
Ensure Premise has exclusive access to the chosen COM port; no other program should be using the COM port.
 
I see the Y in port spy, but that's all; no response from the UPS is shown?!?

I uninstalled the Powerchute program (used for the UPS) and even uninstalled realport so there should be nothing else using the port... I'm pretty stumped. PuTTY is just a standalone exe so I know it's not running. The UPS program under windows also says the UPS service is stopped.
 
Solution?!?

So, I found a port spy program that's compatible with SYS and Putty: http://www.aggsoft.com/serial-port-monitor.htm

I used this program and came up with the output in the attached text file for Putty and Premise.

Note that the baud rate of the driver was set to 2400, not 9600. In the text file, you can see Putty works correctly, using 2400. I enabled RTS and DTR (cause that is what Putty did), then manually changed the baud 2400 with a mouse and the Premise driver worked?!?

This makes me think it's not ok to set the baud rate like this: this.Baud = "2400" within the class constructor; however, I could not get the error to occur again. I changed the constructor to this.Baud = 8 just in case. I'm very confused, but the driver works now and I'm adding all the commands the APC Powerchute program uses. Any thoughts? Why would a driver display a 2400 baud rate, but connect at 9600?

Premise:
<20100404162351.875 SYS>
COM port is opened
<20100404162351.875 SYS>
Baud rate 9600
<20100404162351.875 SYS>
RTS off
<20100404162351.875 SYS>
DTR off
<20100404162351.875 SYS>
Data bits=8, Stop bits=1, Parity=None
<20100404162351.875 SYS>
Set chars: Eof=0x00, Error=0x00, Break=0x00, Event=0x00, Xon=0x11, Xoff=0x13
<20100404162351.875 SYS>
Handflow: ControlHandShake=(), FlowReplace=(), XonLimit=512, XoffLimit=128
<20100404162351.875 SYS>
Set timeouts: ReadInterval=2, ReadTotalTimeoutMultiplier=0, ReadTotalTimeoutConstant=0, WriteTotalTimeoutMultiplier=0, WriteTotalTimeoutConstant=5000
<20100404162351.875 SYS>
Purge the serial port: RXABORT, RXCLEAR, TXABORT, TXCLEAR
<20100404162355.171 TX>
YY
<20100404162404.578 SYS>
Purge the serial port: RXABORT, RXCLEAR, TXABORT, TXCLEAR
<20100404162405.031 SYS>
COM port is closed
 

Attachments

  • APC_SmartUPS_putty_versus_premise.txt
    3.3 KB · Views: 15
... makes me think it's not ok to set the baud rate like this: this.Baud = "2400" ...
Baud is a MultiValue property. It derives its values from the BaudRate enumeration (Schema/Networks/BaudRate). Each element of an enumeration is called an enum and it has a name and a value.

The first attached image shows the results of setting the Baud property three different ways.

this.Baud = 9
This is an attempt to set Baud to the enum whose value is 9. The name of this enum is 4800 (see the second image). Note that when the combo-box is opened, Builder highlights 4800 thereby indicating that this.Baud = 9 was interpreted correctly.

this.Baud = "4800"
This is an attempt to set Baud to the enum whose name is "4800". Note that when the combo-box is opened, Builder fails to highlight 4800. In other words, Builder was unable to interpret this.Baud = "4800".

this.Baud = "256000"
This is another attempt to set Baud to an enum using the enaum's name. In this case, the name is "256000" and the BaudRate enumeration does not contain an enum with such a name. The result is that Builder, once again, fails to highlight a value thereby suggesting that this.Baud = "256000" is an illegal operation.

NOTE
Just when it looks like it is illegal to assign an enum's name to a MultiValue property, Premise breaks the rule. If the enum's name is non-numeric, then you can assign it to a MultiValue! For example, this.Parity = 2 and this.Parity = "None" are interpreted correctly by Builder. The only explanation I can think of is that the name of each enum in the Parity enumeration is non-numeric: "Even", "Mark", None", "Odd", "Space" (see the third image).
 

Attachments

  • Enumeration_Examples.png
    Enumeration_Examples.png
    31.9 KB · Views: 12
  • BaudRate_Enumeration.png
    BaudRate_Enumeration.png
    16.3 KB · Views: 14
  • Parity_Enumeration.png
    Parity_Enumeration.png
    14.3 KB · Views: 10
123, this is a very nice analysis of what is going on; thank you! It is strange that Builder shows the "4800" in the field to confuse the mis-informed user; it could have said N/A or NULL or something like that and I would not have been so confused! Indeed, Builder was displaying "4800" and not 4800, doh! This is why 4800 is not highlighted in the combo box list...

Man, I feel really dumb; I learned my lesson with enum values! For now on, I'm going to use an integer for pointing. Eventhough you don't have to do this for enum values that are all strings, I'm going to so I never make this mistake again. Just when I thought I was starting to grasp things in Premise...

Progress on the APC SmartUPS driver is going very well. I used your jobque concept from the vizia driver as it offers better reliability (IMHO). I also stole your Polling class too :huh:
 
Back
Top