1

I have bought a serial - USB adapter to connect my UPS (serial equipped) to my Raspberry machine and therefore to monitor the UPS.

The adapter is seen as /dev/USB1. The baud rate is 2400, the data lenght is 8 bit, stop bit 1 bit and no parity.

To get the status of the UPS, I should send to serial the command “Q1” followed by “cr” and then to read the output of the serial.

I have found following script:

tty=/dev/ttyUSB1

exec 4<$tty 5>$tty

stty -F $tty 9600 -echo

echo ‘Q1\n\r’ >&5

read reply <&4

echo "reply is $reply"

but it works just once and then it get stuck when executing the read command.

It looks like the serial get stuck after the first enquiry and then it returns alive after a few hours. Could it be?

Can anyone please help me?

Thanks, Daniele

Daniele
  • 15
  • Is this an exact replica of the command as copied from source, if so then this should have been '. That's one thing a see wrong with this script! – George Udosen Nov 15 '17 at 22:39
  • 1
    Just use screen or byobu. Don't bother with file descriptors. And add yourself to dialout group, since tty devices are owned by that group – Sergiy Kolodyazhnyy Nov 15 '17 at 22:46

1 Answers1

0

Like stated, screen would help.

screen /dev/ttyUSB1 2400

Note, you need to be in dialout group or issue connection from root account.

fugitive
  • 1,246