Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # http://scratch-tales.blogspot.ru/
- #!/usr/local/bin/python2.7
- import sys
- import os
- import time
- import termios
- #------------------------------VAR------------------
- ups_port = '/dev/tty00'
- #--------------Open and setting UPS port------------
- ups_ghost = open(ups_port, 'r+', 0)
- com_port_attr = termios.tcgetattr(ups_ghost)
- #iflag
- com_port_attr[0] = termios.IGNBRK
- #oflag
- com_port_attr[1] = 0x0
- #cflag - ignore CTS/RTS | enable receiver | 2400 | 8n1 (n and 1 are 0x0)
- com_port_attr[2] = termios.CLOCAL | termios.CREAD | termios.B2400 | termios.CS8
- #lflag
- com_port_attr[3] = 0x0
- #ispeed
- com_port_attr[4] = termios.B2400
- #ospeed
- com_port_attr[5] = termios.B2400
- # Do the dastardly deed
- termios.tcsetattr(ups_ghost, termios.TCSANOW, com_port_attr)
- ups_ghost.write('Y')
- ups_ghost.flush()
- ret = ups_ghost.readline().strip()
- print "UPS status: ", ret
- ups_ghost.write('P')
- ups_ghost.flush()
- ret = ups_ghost.readline().strip()
- print "UPS load: ", ret
- ups_ghost.write('L')
- ups_ghost.flush()
- ret = ups_ghost.readline().strip()
- print "Line voltage: ", ret
- ups_ghost.write('O')
- ups_ghost.flush()
- ret = ups_ghost.readline().strip()
- print "Output voltage: ", ret
- ups_ghost.write('B')
- ups_ghost.flush()
- ret = ups_ghost.readline().strip()
- print "Battery voltage: ", ret
- ups_ghost.write('f')
- ups_ghost.flush()
- ret = ups_ghost.readline().strip()
- print "Battery status: ", ret
- ups_ghost.close()
Advertisement
Add Comment
Please, Sign In to add comment