- Timestamp:
- Jul 16, 2010, 1:06:30 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
powerbar/serial-npm4000.py
r159 r160 127 127 return int(bin(number)[2:].zfill(width)[::-1],2) 128 128 129 #send_command(ser, login_line, 5)130 # Note: you will need to wait at least timeout * 24 to complete131 #ser.timeout = 13132 #send_command(ser, allon_line, 6)133 #send_command(ser, alloff_line,6)134 135 #send_command(ser, power_on_interval_05_line,6)136 #send_command(ser,port_on_cmd(24),6)137 #send_command(ser,port_off_cmd(24),6)138 #retval = send_command(ser, refresh_line, 42)139 #print get_port_status(retval)140 #while True:141 # port_number = random.randint(1,24)142 # print port_number143 # send_command(ser, login_line, 5)144 # send_command(ser, port_on_cmd(port_number),6)145 # send_command(ser, login_line, 5)146 # send_command(ser, port_off_cmd(port_number),6)147 129 148 130 # Login cycle … … 213 195 return send_command('port_off', port_to_hex(port)) 214 196 197 def action_toggle_port(port): 198 """ Toggle port state """ 199 if get_port_status(port): 200 action_port_off(port) 201 else: 202 action_port_on(port) 203 215 204 def get_ports_status(): 216 205 global ports_status, port_status_synced, ports_ampere, grid_status … … 287 276 288 277 def usage(msg="",exitcode=None): 289 print """%s 290 Usage %s arguments 278 if msg: 279 msg = "[ERROR] %s" % msg 280 print """%(msg)s 281 Usage %(argv)s arguments 291 282 Version: $Id: npm4000.py 750 2009-09-27 14:34:55Z rick $ 292 283 … … 296 287 [-d|--debug] Print extra communication output 297 288 [-r|--raw] Status(es) is bits like output 298 --serialport=<path> Serial Port to connect to [% s]299 --password=<hex> Password to use in hex notation [% s]300 --addresscode=<hex> Internal device number in hex notation [% s]301 --delay=<int> Delay used between port operations [% s]302 --baudrate=<int> Bautrate used for communication (19200,9600) [% s]289 --serialport=<path> Serial Port to connect to [%(serialport)s] 290 --password=<hex> Password to use in hex notation [%(password)s] 291 --addresscode=<hex> Internal device number in hex notation [%(addresscode)s] 292 --delay=<int> Delay used between port operations [%(delay)s] 293 --baudrate=<int> Bautrate used for communication (19200,9600) [%(baudrate)s] 303 294 [-s <port>|--status=<port>] Current port(s) configuration 304 295 [-t <port>|--toggle=<port>] Toggle port(s) … … 310 301 --changeaddresscode= Change addresscode [TODO: Implement] 311 302 --changetimerdelay= Change internal timer delay [TODO: Implement] 303 --pinballtest=<int> Randomly toggle ports for number of times] 304 [-p <port>|--port=<port>] Ports needed to be used 312 305 313 306 Note: [TODO: Implement] bit codes are in the source code, feel free to drop me … … 318 311 Actual value of port A1,..,A8,B1,..,B8,C1,..,C8 319 312 All ports all 320 """ % (msg, sys.argv[0], opt_serial_port, hex(opt_password), hex(opt_address_code), opt_delay, opt_baudrate) 321 if exitcode: 313 314 %(msg)s 315 """ % { 'argv' : sys.argv[0], 316 'msg' : msg, 317 'serialport' : opt_serial_port, 318 'password' : opt_password, 319 'addresscode' : opt_address_code, 320 'delay' : opt_delay, 321 'baudrate' : opt_baudrate, 322 } 323 if exitcode != None: 322 324 sys.exit(exitcode) 323 325 324 326 def main(): 325 global DEBUG, ser, opt_serial_port, opt_password, opt_address_code, opt_baudrate, opt_delay 327 global DEBUG, ser, opt_serial_port, opt_password, opt_address_code, opt_baudrate, opt_delay, opt_pinballtest 326 328 try: 327 329 opts, args = getopt.getopt(sys.argv[1:], 328 "ad f:s:t:ro:v",329 ["ampere", "debug", "delay=", " verbose", "serialport=", "password=",330 "addresscode=","toggle=","off=", "on=", "status=", "buadrate=", "raw=" ])330 "adhf:s:t:ro:p:v", 331 ["ampere", "debug", "delay=", "help", "verbose", "serialport=", "port=", "password=", 332 "addresscode=","toggle=","off=", "on=", "status=", "buadrate=", "raw=", "pinballtest="]) 331 333 except getopt.GetoptError, err: 332 334 usage(str(err),2) … … 336 338 opt_raw = False 337 339 opt_ampere = False 340 opt_pinballtest = None 338 341 for o, a in opts: 339 342 debug("%s : %s" % (o, a)) … … 350 353 elif o in ["--password"]: 351 354 opt_passwd = int(a,16) 355 elif o in ["-p","--port"]: 356 opt_port = a 357 elif o in ["--pinballtest"]: 358 opt_action = 'pinballtest' 359 opt_pinballtest = int(a) 352 360 elif o in ["--buadrate"]: 353 361 opt_baudrate = a … … 372 380 373 381 if (opt_port == None): 374 usage(" [ERROR]No port defined",2)382 usage("No port defined",2) 375 383 elif (opt_action == None): 376 usage(" [ERROR]No action defined",2)384 usage("No action defined",2) 377 385 378 386 … … 394 402 debug(serial) 395 403 404 if opt_pinballtest: 405 for count in range(0,opt_pinballtest): 406 port = random.choice(ports) 407 print "[%04i] Toggle port %02i" % (count, port) 408 action_toggle_port(port) 409 # Backoff time 410 time.sleep(opt_delay) 411 sys.exit(0) 412 396 413 # Status needs real integers, hack 397 414 for port in ports: … … 405 422 print "Port %02i : %s %s" % (port, get_port_status(port), ampere_str) 406 423 elif opt_action == "toggle": 407 if get_port_status(port): 408 action_port_off(port) 409 else: 410 action_port_on(port) 424 action_toggle_port(port) 411 425 elif opt_action == "on": 412 426 action_port_on(port)
Note:
See TracChangeset
for help on using the changeset viewer.