[Nut-upsdev] Megatec - modem control lines

Arjen de Korte nut+devel at de-korte.org
Mon Jun 18 12:14:14 UTC 2007


Carlos,

Today I was browsing through the NUT Tracker and noticed an entry which
linked to a message on nut-upsdev:

http://lists.alioth.debian.org/pipermail/nut-upsdev/2006-January/000559.html


Although the fentonups driver is no longer in the tree (since it was
replaced by the megatec driver), I think there is still some merit in
this patch. Notice the following lines from this message:

> here is the patch to make fentonups recognize some PowerCOM's UPS's, and 
> to setup terminal lines for them (at least for SMK-1500a) as powercom's 
> original upsmon do. fentonups -x powercom works correctly with SMK-1500a 
> (it screamed ''Communications with UPS lost - check cabling' or 'Short 
> read during UPS id sequence' without this patch).

Currently, unreliable communication is one of the things some people
that use these UPSes with the megatec driver are sometimes complaining
about. I never dug too deeply into this, but from the problem reports
we're seeing I can imagine that this indeed may be a problem.

So far, the megatec driver doesn't do anything with the modem control
lines at all. This may be OK if these are indeed not used by the
interface (for instance if only TX and RX are wired). But if they are
used to provide cable power this is not right. The build in NUT
functions don't do anything with the modem control lines and will leave
them in the state they are in before the driver started. If that happens
to be the right state, fine, but if they are not, we have a problem.
Therefor, I want to propose the following patch:

Index: /home/arjen/Devel/nut/trunk/drivers/megatec.c
===================================================================
--- trunk/drivers/megatec.c       (revision 965)
+++ trunk/drivers/megatec.c       (working copy)
@@ -853,13 +853,22 @@

 void upsdrv_initups(void)
 {
+       int    dtr_bit = TIOCM_DTR;
+       int    rts_bit = TIOCM_RTS;
+
        upsfd = ser_open(device_path);
        ser_set_speed(upsfd, device_path, B2400);
+
+       ioctl(upsfd, TIOCMBIS, &dtr_bit);
+       ioctl(upsfd, TIOCMBIC, &rts_bit);
 }


 void upsdrv_cleanup(void)
 {
+       int    dtr_bit = TIOCM_DTR;
+
+       ioctl(upsfd, TIOCMBIC, &dtr_bit);
        ser_close(upsfd, device_path);
 }

This should be backwards compatible, since we never did anything with
these lines before, so the state would have been 'random' until now.Note
that at power up, these often will be cleared so usually they will be
cleared, but if the port had been used before by other applications, the
state they're in is undefined.

The least this patch will do, is to define a state for the modem control
lines.

Best regards, Arjen



More information about the Nut-upsdev mailing list