Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticket8253_make_IOC_work_if_crate_is_power_cycled #175

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lewis_emulators/mclennan/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

states = OrderedDict([("Stopped", StoppedState()),
("Moving", MovingState()),
("Homing", HomingState()),
("Homing", HomingState()),
("Jogging", JoggingState())])


Expand All @@ -20,6 +20,7 @@ def _initialize_data(self):
self.is_moving = False
self.is_homing = False
self.is_pm304 = False
self.has_sent_BA = False
self.is_idle = True
self.jog_velocity = 0
self.position = 0
Expand All @@ -46,7 +47,7 @@ def _initialize_data(self):
self.abort_mode = {}
self.datum_mode = {}
self.home_pos = {}
for i in range(1,10):
for i in range(1, 10):
self.velocity[i] = 0
self.creep_speed[i] = 700
self.accl[i] = 1000
Expand Down Expand Up @@ -88,7 +89,6 @@ def stop(self):
self.is_idle = True
self.current_op = "Idle"


def _get_state_handlers(self):
return states

Expand Down
45 changes: 29 additions & 16 deletions lewis_emulators/mclennan/interfaces/stream_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,44 @@ class MclennanStreamInterface(StreamInterface):
CmdBuilder("jog").int().escape("CV").int().eos().build(),
CmdBuilder("query_speeds").int().escape("QS").eos().build(),
CmdBuilder("set_mode").int().escape("CM").int().eos().build(),
CmdBuilder("set_encoder_ratio").int().escape("ER").int().escape("/").int().eos().build(),
CmdBuilder("set_encoder_ratio").int().escape(
"ER").int().escape("/").int().eos().build(),
CmdBuilder("set_window").int().escape("WI").int().eos().build(),
CmdBuilder("set_timeout").int().escape("TO").int().eos().build(),
CmdBuilder("set_tracking_window").int().escape("TR").int().eos().build(),
CmdBuilder("enable_soft_limits").int().escape("SL").int().eos().build(),
CmdBuilder("set_tracking_window").int().escape(
"TR").int().eos().build(),
CmdBuilder("enable_soft_limits").int().escape(
"SL").int().eos().build(),
CmdBuilder("set_backoff").int().escape("BO").int().eos().build(),
CmdBuilder("set_creep_steps").int().escape("CR").int().eos().build(),
CmdBuilder("set_settle_time").int().escape("SE").int().eos().build(),
CmdBuilder("set_abort_mode").int().escape("AM").arg("[0-1]{8}").eos().build(),
CmdBuilder("set_datum_mode").int().escape("DM").arg("[0-1]{8}").eos().build(),
CmdBuilder("set_abort_mode").int().escape(
"AM").arg("[0-1]{8}").eos().build(),
CmdBuilder("set_datum_mode").int().escape(
"DM").arg("[0-1]{8}").eos().build(),
CmdBuilder("set_home_pos").int().escape("SH").int().eos().build(),
CmdBuilder("move_relative").int().escape("MR").int().eos().build(),
CmdBuilder("move_absolute").int().escape("MA").int().eos().build(),
CmdBuilder("set_velocity").int().escape("SV").int().eos().build(),
CmdBuilder("home").int().escape("HD").int().eos().build(),
CmdBuilder("set_ba").int().escape("BA").eos().build(),
CmdBuilder("clear_datum").int().escape("CD").eos().build(),
CmdBuilder("define_command_position").int().escape("CP").int().eos().build(),
CmdBuilder("define_actual_position").int().escape("AP").int().eos().build(),
CmdBuilder("define_command_position").int().escape(
"CP").int().eos().build(),
CmdBuilder("define_actual_position").int().escape(
"AP").int().eos().build(),
CmdBuilder("query_mode").int().escape("QM").eos().build(),
CmdBuilder("query_current_op").int().escape("CO").eos().build(),
CmdBuilder("query_all").int().escape("QA").eos().build(),
CmdBuilder("query_position").int().escape("QP").eos().build(),
CmdBuilder("query_current_op").int().escape("CO").eos().build(),
CmdBuilder("query_all").int().escape("QA").eos().build(),
CmdBuilder("query_position").int().escape("QP").eos().build(),
}

in_terminator = "\r"
out_terminator = "\r\n"

def handle_error(self, request, error):
err_string = "command was: {}, error was: {}: {}\n".format(request, error.__class__.__name__, error)
err_string = "command was: {}, error was: {}: {}\n".format(
request, error.__class__.__name__, error)
print(err_string)
self.log.error(err_string)
return err_string
Expand Down Expand Up @@ -110,7 +119,7 @@ def reset(self, controller):
def jog(self, controller, velocity):
self.device.jog(velocity)
return "OK"

@if_connected
def set_mode(self, controller, mode):
self.device.mode[controller] = mode
Expand Down Expand Up @@ -191,6 +200,11 @@ def home(self, controller, dir):
self.device.home()
return "OK"

@if_connected
def set_ba(self, controller):
self.device.has_sent_BA = True
return "OK"

@if_connected
def clear_datum(self, controller):
return "OK"
Expand All @@ -204,7 +218,7 @@ def define_command_position(self, controller, value):
def define_actual_position(self, controller, value):
self.device.position = value
return "OK"

@if_connected
def query_mode(self, controller):
return f"{controller:02}:CM = {self.device.mode[controller]} AM = {self.device.abort_mode[controller]} DM = {self.device.datum_mode[controller]} JM = 11000000"
Expand All @@ -214,7 +228,7 @@ def query_current_op(self, controller):
return f"{controller:02}:{self.device.current_op}"

# all replies should contain the original command string first and \r, the emulator does not do this in general but it
# only matters for multiline replies which this is the only such command
# only matters for multiline replies which this is the only such command
@if_connected
def query_all(self, controller):
lines = [
Expand Down Expand Up @@ -243,8 +257,7 @@ def query_all(self, controller):
"Read port: %00000000 Last write: %00000000"
]
return f'{controller:02}QA\r' + '\r\n'.join(lines)

@if_connected
def query_position(self, controller):
return f"{controller:02}:CP = {self.device.target_position} AP = {self.device.position} IP = 1050 TP = 0 OD = -2050"