Initial check-in
This commit is contained in:
3
App/GetState.bat
Normal file
3
App/GetState.bat
Normal file
@@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
.\USBCaseControl.py -c "GETSTATE"
|
||||
pause
|
||||
3
App/MasterOff.bat
Normal file
3
App/MasterOff.bat
Normal file
@@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
.\USBCaseControl.py -c "MASTER=OFF"
|
||||
pause
|
||||
3
App/MasterOn.bat
Normal file
3
App/MasterOn.bat
Normal file
@@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
.\USBCaseControl.py -c "MASTER=ON"
|
||||
pause
|
||||
33
App/USBCaseControl.py
Normal file
33
App/USBCaseControl.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import serial.tools.list_ports
|
||||
import sys, getopt
|
||||
import time
|
||||
|
||||
|
||||
def main(argv):
|
||||
cmd = 'GETSTATE'
|
||||
print("USBCaseControl starting up...")
|
||||
try:
|
||||
opts, args = getopt.getopt(argv,"hc:",["cmd="])
|
||||
except getopt.GetoptError as err:
|
||||
print(err)
|
||||
sys.exit(2)
|
||||
for opt, arg in opts:
|
||||
if opt == '-h':
|
||||
print("USBCaseControl.py --cmd <command>")
|
||||
sys.exit()
|
||||
elif opt in ("-c", "--cmd"):
|
||||
cmd = arg
|
||||
ports = serial.tools.list_ports.comports()
|
||||
for port, desc, hwid in sorted(ports):
|
||||
if "Arduino Leonardo" in desc:
|
||||
print("{}: {} [{}]".format(port, desc, hwid))
|
||||
finalport=port
|
||||
ser = serial.Serial(finalport, 9600, timeout=0,parity=serial.PARITY_EVEN, rtscts=1)
|
||||
print("Calling command: {} on Port {}".format(cmd,port))
|
||||
ser.write(cmd.encode('utf_8'))
|
||||
time.sleep(2)
|
||||
out = ser.read(100)
|
||||
print("Command return: {}".format(out.decode(encoding="utf_8", errors="ignore")))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
||||
Reference in New Issue
Block a user