You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.6 KiB
50 lines
1.6 KiB
import sys
|
|
from time import sleep, time
|
|
|
|
from source.IdiBus4DC import Module4DC
|
|
from source.IdiBusSerialLine import IdiBusSerialLine
|
|
|
|
|
|
class Executioner():
|
|
def __init__(self, name):
|
|
self.name = name
|
|
self.port = ""
|
|
self.address = 0
|
|
self.speed = 0
|
|
def execute(self, command, args):
|
|
pass
|
|
# Must return string with all data in csv format. without \n or \r
|
|
def get_log_string(self):
|
|
pass
|
|
class Exec4DC(Executioner):
|
|
def __init__(self, ):
|
|
super().__init__("Module4DC")
|
|
def execute(self, command, args):
|
|
module = Module4DC(addr=self.address, line=IdiBusSerialLine(port=self.port, baudrate=self.speed))
|
|
if command == "set-data":
|
|
module.set_channel_data(args[0], args[1], args[2])
|
|
elif command == "set-state":
|
|
module.set_channel_state(args[0], args[1])
|
|
else:
|
|
print("Unknown command: " + command)
|
|
def get_log_string(self):
|
|
module = Module4DC(addr=self.address, line=IdiBusSerialLine(port=self.port, baudrate=self.speed))
|
|
str = ""
|
|
for i in range(4):
|
|
data = module.set_channel_data(i)
|
|
if data == None:
|
|
return None
|
|
else:
|
|
str += f"{data["voltage"]},{data["current"]},"
|
|
class ExecSystem(Executioner):
|
|
def __init__(self):
|
|
super().__init__("Module4DC")
|
|
def execute(self, command, args):
|
|
if command == "sleep":
|
|
sleep(args[0])
|
|
elif command == "exit":
|
|
sys.exit(0)
|
|
else:
|
|
print("Unknown command: " + command)
|
|
def get_log_string(self):
|
|
return "System is ok. :P" |