Commit b061cb0c authored by Yb Tweezer's avatar Yb Tweezer
Browse files
parents aa879e7c 28a28a9d
from __future__ import annotations
import lib.system as system
from lib.system import MAIN
from lib.system import MAIN#, MOGRF
from lib.ew import EventType
import lib.rtcontrol.parser as parser
import cmd
......@@ -30,6 +30,9 @@ def set_named_connection_state(kind: EventType, state_args: list[tuple]):
else:
raise Exception("Invalid EventType")
def set_mog_channel_state(ch: int, state: tuple[float, float, float, float]):
raise NotImplemented
helptext = """
Simple script to set the output state managed by the EntangleWare backend.
......@@ -121,9 +124,9 @@ Args:
"""
try:
state_args = parser.parse_digital_state(arg)
set_digital_state(state_args)
except Exception as err:
print(err)
set_digital_state(state_args)
def do_analog(self, arg):
"""
......@@ -145,9 +148,37 @@ Args:
"""
try:
state_args = parser.parse_analog_state(arg)
set_analog_state(state_args)
except Exception as err:
print(err)
def do_set(self, arg):
"""
Set the output state of a named channel.
Usage:
set <channel_name> <state>
Args:
channel_name : str
Name of the channel, as defined in `lib.system`.
state : <float|int>
Output state of the channel to be set. Must be interpretable as a float
for analog channels or {1, 0} for digital channels.
"""
try:
if all(
name in lib.system.CONNECTIONS.connections.keys()
for name in args[1].split(",")
):
X = parser.parse_named_connection_state(cmd_args)
for x in X:
set_named_connection_state(*x)
else:
print("Invalid domain name")
except Exception as err:
print(err)
set_analog_state(state_args)
def do_zero(self, arg):
"""
......@@ -163,9 +194,9 @@ Args:
"""
try:
zero_type = parser.parse_zero(arg)
set_zero(zero_type)
except Exception as err:
print(err)
set_zero(zero_type)
def do_alldefaults(self, arg):
"""
......@@ -179,6 +210,18 @@ Args:
"""
MAIN.set_defaults()
def do_list(self, arg):
"""
List all connections defined in `lib.system` with their respective values.
Usage:
list
Args:
None
"""
print(system.CONNECTIONS)
def do_quit(self, arg):
"""
Disconnect and quit.
......@@ -210,29 +253,41 @@ def main(script_args):
print_help(cmd_args)
elif args[0] == "set":
assert len(args) >= 2, "Must provide a setting domain"
if args[1] == "digital":
cmd_args = " ".join(args[2:])
MAIN.connect()
set_digital_state(parser.parse_digital_state(cmd_args))
MAIN.disconnect()
elif args[1] == "analog":
cmd_args = " ".join(args[2:])
# if args[1] == "digital":
# cmd_args = " ".join(args[2:])
# MAIN.connect()
# set_digital_state(parser.parse_digital_state(cmd_args))
# MAIN.disconnect()
# elif args[1] == "analog":
# cmd_args = " ".join(args[2:])
# MAIN.connect()
# set_analog_state(parser.parse_analog_state(cmd_args))
# MAIN.disconnect()
# else:
# if all(
# name in MAIN.defaults.connections.keys()
# for name in args[1].split(",")
# ):
# X = parser.parse_named_connection_state(cmd_args)
# MAIN.connect()
# for x in X:
# set_named_connection_state(*x)
# MAIN.disconnect()
# else:
# print("Invalid domain name")
# sys.exit(1)
if all(
name in MAIN.defaults.connections.keys()
for name in args[1].split(",")
):
X = parser.parse_named_connection_state(cmd_args)
MAIN.connect()
set_analog_state(parser.parse_analog_state(cmd_args))
for x in X:
set_named_connection_state(*x)
MAIN.disconnect()
else:
if all(
name in MAIN.defaults.connections.keys()
for name in args[1].split(",")
):
X = parser.parse_named_connection_state(cmd_args)
MAIN.connect()
for x in X:
set_named_connection_state(*x)
MAIN.disconnect()
else:
print("Invalid domain name")
sys.exit(1)
print("Invalid domain name")
sys.exit(1)
elif args[0] == "digital":
cmd_args = " ".join(args[1:])
MAIN.connect()
......@@ -251,6 +306,8 @@ def main(script_args):
MAIN.connect()
MAIN.set_defaults()
MAIN.disconnect()
elif args[0] == "list":
print(system.CONNECTIONS)
else:
print(helptext)
sys.exit(1)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment