Skip to content

Commit beb33b2

Browse files
committed
- Fixed bug where setting/getting variables did not work when pyControl.utility was imported into task file using named rather than * import
1 parent f6ba396 commit beb33b2

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

pyControl/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import pyControl.framework as fw
2+
import pyControl.utility as ut
23
import pyControl.hardware as hw
3-
import pyControl.state_machine as sm
4-
import pyControl.utility as ut
4+
import pyControl.state_machine as sm

pyControl/framework.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def get_states():
172172

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

177177
def output_data(event):
178178
# Output data to computer.

pyControl/state_machine.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from . import utility
12
from . import framework as fw
23

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

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

1316
fw.register_machine(self)
@@ -66,13 +69,13 @@ def _set_variable(self, v_name, v_str, checksum=None):
6669
if not str_sum == checksum:
6770
return False # Bad checksum.
6871
try:
69-
setattr(self.smd.v, v_name, eval(v_str))
72+
setattr(self.variables, v_name, eval(v_str))
7073
return True # Variable set OK.
7174
except Exception:
7275
return False # Bad variable name or invalid value string.
7376

7477
def _get_variable(self, v_name):
7578
try:
76-
return repr(getattr(self.smd.v, v_name))
79+
return repr(getattr(self.variables, v_name))
7780
except Exception:
7881
return None

0 commit comments

Comments
 (0)