Scripting Examples

Python using serial library - set outlet 1 off

# params:
#    port => COM port

s = serial.Serial()
s.port = port

# Timeout settings
s.timeout= 1 
s.writeTimeout= 2

try:
  s.open()
	s.flushInput()
	s.flushOutput()
	# Login to admin
	s.write("login\n\radmin\n\radmin\n\r".encode("utf-8"))
	time.sleep(0.5) # Sleep half a second before reading response
  s.read(512)     # Ready 512 bytes of response
  
	# Issue command `pset 1 0` to turn outlet 1 off
  s.write("pset 1 0\n\r".format(command=command).encode("utf-8"))            
  
	# Sleep half a second before reading any responses, if any
	time.sleep(0.5)
	response = s.read(512).decode("utf-8")
	s.close()
except Exception as err:
  # Error handling goes here