Skip to content

Commit

Permalink
- Fixed bug where setting/getting variables did not work when pyContr…
Browse files Browse the repository at this point in the history
…ol.utility was imported into task file using named rather than * import
  • Loading branch information
ThomasAkam committed Dec 23, 2021
1 parent f6ba396 commit beb33b2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pyControl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pyControl.framework as fw
import pyControl.utility as ut
import pyControl.hardware as hw
import pyControl.state_machine as sm
import pyControl.utility as ut
import pyControl.state_machine as sm
2 changes: 1 addition & 1 deletion pyControl/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def get_states():

def get_variables():
# Print state machines variables as dict {v_name: repr(v_value)}
print({k: repr(v) for k, v in state_machine.smd.v.__dict__.items()})
print({k: repr(v) for k, v in state_machine.variables.__dict__.items()})

def output_data(event):
# Output data to computer.
Expand Down
7 changes: 5 additions & 2 deletions pyControl/state_machine.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from . import utility
from . import framework as fw


class State_machine():
# State machine behaviour is defined by passing state machine description object smd to
# State_machine __init__(). smd is a module which defines the states, events and
Expand All @@ -8,6 +10,7 @@ class State_machine():
def __init__(self, smd):

self.smd = smd # State machine definition.
self.variables = utility.v # User task variables object.
self.state_transition_in_progress = False # Set to True during state transitions.

fw.register_machine(self)
Expand Down Expand Up @@ -66,13 +69,13 @@ def _set_variable(self, v_name, v_str, checksum=None):
if not str_sum == checksum:
return False # Bad checksum.
try:
setattr(self.smd.v, v_name, eval(v_str))
setattr(self.variables, v_name, eval(v_str))
return True # Variable set OK.
except Exception:
return False # Bad variable name or invalid value string.

def _get_variable(self, v_name):
try:
return repr(getattr(self.smd.v, v_name))
return repr(getattr(self.variables, v_name))
except Exception:
return None

0 comments on commit beb33b2

Please sign in to comment.