#! /usr/bin/env python # coding: utf-8 import serial ser = serial.Serial("/dev/ttyS0") ser.baudrate = 9600 while True : line = ser.readline() print line
serrrggggeee@serrrggggeee-Arbyte-Quint-B-M4D3A-H61 ~ $ sudo python port_n.py
#! /usr/bin/env python # coding: utf-8 import serial ser = serial.Serial("/dev/ttyS0") ser.baudrate = 9600 while True : line = ser.readline() print line
serrrggggeee@serrrggggeee-Arbyte-Quint-B-M4D3A-H61 ~ $ sudo python port_n.py
UPS status : Bit Description 7 1 : Utility Fail (Immediate) 6 1 : Battery Low 5 1 : Bypass/Boost or Buck Active 4 1 : UPS Failed 3 1 : UPS Type is Standby (0 is On_line) 2 1 : Test in Progress 1 1 : Shutdown Active 0 1 : Beeper On
#! /usr/bin/env python # coding: utf-8 import serial ser = serial.Serial("/dev/ttyS0") ser.baudrate = 9600 y = ser.write("Q1\n") while True : line = ser.readline() print line
import time import serial ser = serial.Serial("/dev/ttyS0") ser.baudrate = 9600 while True : ser.write("Q1\n") line = ser.readline() # и тут разбраете на запчасти строку print line time.sleep(1000)
serrrgggeeeпопробуйте сначала через терминал. проверьте параметры порта
молчит все равно.
ser.write("Q1\r")
serrrggggeee-Arbyte-Quint-B-M4D3A-H61 serrrggggeee # stty -a < /dev/ttyS0 speed 38400 baud; rows 0; columns 0; line = 0; intr = <undef>; quit = <undef>; erase = <undef>; kill = <undef>; eof = <undef>; eol = ^M; eol2 = <undef>; swtch = <undef>; start = <undef>; stop = <undef>; susp = <undef>; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 0; time = 0; -parenb -parodd cs8 -hupcl -cstopb cread clocal -crtscts -ignbrk -brkint ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -iutf8 -opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 -isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt -echoctl -echoke