Changeset 360
- Timestamp:
- Jan 31, 2012, 7:39:34 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
powerbar/npm2000.py
r359 r360 24 24 MAX_PORTS = 8 25 25 26 # Wait a little while to allow device to turn off 27 CYCLE_WAIT = 1 28 26 29 # XOR all the 8bit values to get a checksum 27 30 def checksum(s): … … 168 171 doCommand('portOn', port) 169 172 173 def cyclePort(port): 174 raw_status= doCommand('status') 175 if getPortState(port,raw_status): 176 doCommand('portOff',port) 177 time.sleep(CYCLE_WAIT) 178 doCommand('portOn',port) 179 else: 180 doCommand('portOn', port) 181 time.sleep(CYCLE_WAIT) 182 doCommand('portOff',port) 183 170 184 171 185 def runTest(): … … 214 228 try: 215 229 opts, args = getopt.getopt(sys.argv[1:], 216 " hf:s:t:o:v", ["help","verbose","host=", "port=", "password=", "addresscode=","toggle=","off=", "on=", "status="])230 "c:hf:s:t:o:v", ["cycle=", "help","verbose","host=", "port=", "password=", "addresscode=","toggle=","off=", "on=", "status="]) 217 231 except getopt.GetoptError, err: 218 232 # print help information and exit: … … 243 257 opt_action = "toggle" 244 258 opt_port = a 259 elif o in ("-c","--cycle"): 260 opt_action = "cycle" 261 opt_port = a 245 262 elif o in ("-f","--off"): 246 263 opt_action = "off" … … 280 297 281 298 if opt_action == "toggle": 282 if opt_port == "all": 283 for i in range(1,MAX_PORTS+1): 284 togglePort(getPortHex(i)) 285 else: 286 togglePort(opt_port) 299 if opt_port == "all": 300 for i in range(1,MAX_PORTS+1): 301 togglePort(getPortHex(i)) 302 else: 303 togglePort(opt_port) 304 elif opt_action == "cycle": 305 if opt_port == "all": 306 for i in range(1,MAX_PORTS+1): 307 cyclePort(getPortHex(i)) 308 else: 309 cyclePort(opt_port) 287 310 elif opt_action == "on": 288 311 if opt_port == "all":
Note:
See TracChangeset
for help on using the changeset viewer.