[Nut-upsuser] Megatec serial UPS woes

Angela Williams angie at eoh.co.za
Thu Feb 7 13:44:16 UTC 2008


Yo Arjen!
On Thursday 07 February 2008, Arjen de Korte wrote:
> [...]
>
> > I can now see what is in "buffer" and it looks like just a few leading
> > characters might just be missing!
> >
> > So now I am at a loss of how to resolve this problem!
>
> This could be due to some data remaining in the buffers. The megatec
> driver doesn't flush the buffers, so if the UPS sends something it doesn't
> expect, this may cause a problem in the synchronisation if a command is
> not understood by the UPS.
>
> > I'm not the greatest C programmer. I can read it and it makes sense but
> > writing it is a real plod!
>
> Add
>
> 	ser_flush_io(upsfd);
>
> on lines 258, 278, 309 and 333. Basically, this will flush whatever is in
> the in- and output buffers before sending a command to the UPS. It is safe
> (but not always needed) to do so before every ser_send_pace() function.

I needed a few mods to the ser_flush_io!!
The serial.c file says ser_flush_in needs more than just the upsfd passed!
I added IGNCHAR and 0 to each line and reran configure to only build megatec 
and not usb and the make went fine!

Here is the result!
gatekeeper drivers # /usr/local/ups/bin/megatec -a rossups -DDDD -u nut
Network UPS Tools 2.2.0- - Megatec protocol driver 1.5.4 [megatec]
Carlos Rodrigues (c) 2003-2007

debug level is '4'
Starting UPS detection process...
Attempting to detect the UPS...
Sending "Q1" command...
"Q1" command successful.
Attempting to detect the UPS...
Sending "Q1" command...
"Q1" command successful.
Attempting to detect the UPS...
Sending "Q1" command...
"Q1" command successful.
Attempting to detect the UPS...
Sending "Q1" command...
"Q1" command successful.
Attempting to detect the UPS...
Sending "Q1" command...
"Q1" command successful.
0 out of 5 detection attempts failed (minimum failures: 2).
Asking for UPS information ("I" command)...
UPS doesn't return any information about itself.
Megatec protocol UPS detected.
Asking for UPS power ratings ("F" command)...
UPS power ratings: #230.0 013 096.0 50.0
Asking for UPS status ("Q1" command)...
UPS status: (208.5 182.0 229.3 054 50.1 2.29 39.0 00000001
96.0V battery, interval [1.6V, 2.3V].
Done setting up the UPS.
Asking for UPS status ("Q1" command)...
UPS doesn't return any information about its status.
UPS status buffer: (208.5 182.0 229.3 054 50.1 2.29
dstate_init: sock /var/state/ups/megatec-rossups open on fd 6
Signal 2: exiting


Thanks for the quick response! You solved the problem!

Would it not be worthwhile to added these lines into the megatec.c source file 
or the FAQ?

Cheers
Ang




-- 
Angela Williams				Enterprise Outsourcing
Unix/Linux & Cisco spoken here!		Bedfordview
awilliams at eoh.co.za			Gauteng South Africa

Smile!! Jesus Loves You!!



More information about the Nut-upsuser mailing list