From fbace69f0fcc10e51ca4a152a7376752f9e7a8a5 Mon Sep 17 00:00:00 2001 From: e20216 Date: Fri, 16 Sep 2022 17:44:21 +0200 Subject: [PATCH 01/10] update timestamp on read --- ophyd_devices/galil/galil_ophyd.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ophyd_devices/galil/galil_ophyd.py b/ophyd_devices/galil/galil_ophyd.py index 694f1f0..8e830f5 100644 --- a/ophyd_devices/galil/galil_ophyd.py +++ b/ophyd_devices/galil/galil_ophyd.py @@ -250,6 +250,7 @@ class GalilReadbackSignal(GalilSignalRO): return current_pos / step_mm def read(self): + self._metadata["timestamp"] = time.time() val = super().read() if self.parent.axis_Id_numeric == 2: try: From e66208ca182c12711e695bf360964cd4d5d39c6a Mon Sep 17 00:00:00 2001 From: e20216 Date: Wed, 12 Oct 2022 15:58:24 +0200 Subject: [PATCH 02/10] fixed bug in rt readout --- ophyd_devices/rt_lamni/rt_lamni_ophyd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ophyd_devices/rt_lamni/rt_lamni_ophyd.py b/ophyd_devices/rt_lamni/rt_lamni_ophyd.py index 0d4433b..1bd22a8 100644 --- a/ophyd_devices/rt_lamni/rt_lamni_ophyd.py +++ b/ophyd_devices/rt_lamni/rt_lamni_ophyd.py @@ -363,7 +363,7 @@ class RtLamniController(Controller): mode, number_of_positions_planned, current_position_in_scan = self.get_scan_status() time.sleep(0.01) if current_position_in_scan > 5: - while current_position_in_scan > read_counter: + while current_position_in_scan > read_counter + 1: return_table = (self.socket_put_and_receive(f"r{read_counter}")).split(",") # logger.info(f"{return_table}") logger.info(f"Read {read_counter} out of {number_of_positions_planned}") From 0b774f25dd995fdf3d66f0d83a3868dc63a9dabb Mon Sep 17 00:00:00 2001 From: e20216 Date: Wed, 12 Oct 2022 15:59:49 +0200 Subject: [PATCH 03/10] fixed bug that lead galil to quit unexpectedly --- ophyd_devices/galil/galil_ophyd.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/ophyd_devices/galil/galil_ophyd.py b/ophyd_devices/galil/galil_ophyd.py index 8e830f5..261e330 100644 --- a/ophyd_devices/galil/galil_ophyd.py +++ b/ophyd_devices/galil/galil_ophyd.py @@ -134,8 +134,10 @@ class GalilController(Controller): f"Expected return value of ':' but instead received {return_val}" ) - def is_axis_moving(self, axis_Id) -> bool: - return bool(float(self.socket_put_and_receive(f"MG_BG{axis_Id}"))) + def is_axis_moving(self, axis_Id, axis_Id_numeric) -> bool: + is_moving = bool(float(self.socket_put_and_receive(f"MG_BG{axis_Id}")) != 0) + backlash_is_active = bool(float(self.socket_put_and_receive(f"MGbcklact[axis]")) != 0) + return bool(is_moving or backlash_is_active) def is_thread_active(self, thread_id: int) -> bool: val = float(self.socket_put_and_receive(f"MG_XQ{thread_id}")) @@ -254,9 +256,9 @@ class GalilReadbackSignal(GalilSignalRO): val = super().read() if self.parent.axis_Id_numeric == 2: try: - self.parent.device_manager.devices[ - self.parent.rt - ].obj.controller.set_rotation_angle(val[self.parent.name]["value"]) + rt = self.parent.device_manager.devices[self.parent.rt] + if rt.enabled: + rt.obj.controller.set_rotation_angle(val[self.parent.name]["value"]) except KeyError: logger.warning("Failed to set RT value during readback.") return val @@ -306,6 +308,8 @@ class GalilSetpointSignal(GalilSignalBase): self.controller.socket_put_confirmed(f"ntarget={target_val:.3f}") self.controller.socket_put_confirmed("movereq=1") self.controller.socket_put_confirmed("XQ#NEWPAR") + while self.controller.is_thread_active(0): + time.sleep(0.005) else: raise GalilError("Not all axes are referenced.") @@ -323,7 +327,7 @@ class GalilMotorIsMoving(GalilSignalRO): @threadlocked def _socket_get(self): return ( - self.controller.is_axis_moving(self.parent.axis_Id) + self.controller.is_axis_moving(self.parent.axis_Id, self.parent.axis_Id_numeric) or self.controller.is_thread_active(0) or self.controller.is_thread_active(2) ) @@ -494,9 +498,10 @@ class GalilMotor(Device, PositionerBase): position, atol=self.tolerance, ) - self._done_moving(success=success) + if not success: print(" stop") + self._done_moving(success=success) logger.info("Move finished") threading.Thread(target=move_and_finish, daemon=True).start() From ed77e575bf9d1e7f01eb8850a9f40cf27eb91b5b Mon Sep 17 00:00:00 2001 From: e20216 Date: Wed, 12 Oct 2022 16:00:14 +0200 Subject: [PATCH 04/10] added bec logger --- ophyd_devices/utils/socket.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ophyd_devices/utils/socket.py b/ophyd_devices/utils/socket.py index 30a9cce..b8bc500 100644 --- a/ophyd_devices/utils/socket.py +++ b/ophyd_devices/utils/socket.py @@ -8,8 +8,10 @@ import typing import numpy as np from ophyd import Signal from ophyd.utils.errors import DisconnectedError +from bec_utils import bec_logger -logger = logging.getLogger("socket") +logger = bec_logger.logger +#logger = bec_logger.logger("socket") def raise_if_disconnected(fcn): From 28cb54c254f62976926ded33544dbbb9fdcbfffa Mon Sep 17 00:00:00 2001 From: Klaus Wakonig Date: Wed, 12 Oct 2022 17:41:54 +0200 Subject: [PATCH 05/10] fixed formatting for socket --- ophyd_devices/utils/socket.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ophyd_devices/utils/socket.py b/ophyd_devices/utils/socket.py index b8bc500..858f5c5 100644 --- a/ophyd_devices/utils/socket.py +++ b/ophyd_devices/utils/socket.py @@ -6,12 +6,12 @@ import time import typing import numpy as np +from bec_utils import bec_logger from ophyd import Signal from ophyd.utils.errors import DisconnectedError -from bec_utils import bec_logger logger = bec_logger.logger -#logger = bec_logger.logger("socket") +# logger = bec_logger.logger("socket") def raise_if_disconnected(fcn): From ab61aa61aebd2593914df8ea59b48390a76cda90 Mon Sep 17 00:00:00 2001 From: Klaus Wakonig Date: Wed, 12 Oct 2022 17:50:46 +0200 Subject: [PATCH 06/10] updated ci file --- .gitlab-ci.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7d40575..4683611 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,11 +1,11 @@ # This file is a template, and might need editing before it works on your project. # Official language image. Look for the different tagged releases at: # https://hub.docker.com/r/library/python/tags/ -image: "python:3.8" +image: python:3.8 #commands to run in the Docker container before starting each job. before_script: - pip install -r ./requirements.txt - - pip install -e . + - pip install -e . # different stages in the pipeline stages: - Formatter @@ -18,7 +18,6 @@ formatter: pytest: stage: Test script: - - apt-get update && apt-get install -y git - - git clone https://oauth2:$CI_BEC_KEY@gitlab.psi.ch/bec/bec.git - - pip install -e ./bec/bec_utils - - pytest -v ./tests + - git clone https://oauth2:$CI_BEC_KEY@gitlab.psi.ch/bec/bec.git + - pip install -e ./bec/bec_utils + - pytest -v ./tests From cdc0f8294ad34d37ee12814f2d57eba8b0cb04e7 Mon Sep 17 00:00:00 2001 From: wakonig_k Date: Wed, 12 Oct 2022 15:55:20 +0000 Subject: [PATCH 07/10] Update .gitlab-ci.yml --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4683611..139f516 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,6 +2,9 @@ # Official language image. Look for the different tagged releases at: # https://hub.docker.com/r/library/python/tags/ image: python:3.8 +variables: + DOCKER_BUILDKIT: 0 + #commands to run in the Docker container before starting each job. before_script: - pip install -r ./requirements.txt From 22bbfb1d59c11fa770092652856938bb6b4f4a42 Mon Sep 17 00:00:00 2001 From: wakonig_k Date: Wed, 12 Oct 2022 15:56:40 +0000 Subject: [PATCH 08/10] Update .gitlab-ci.yml --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 139f516..c63f738 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,6 +5,9 @@ image: python:3.8 variables: DOCKER_BUILDKIT: 0 +services: + - docker:18.09-dind + #commands to run in the Docker container before starting each job. before_script: - pip install -r ./requirements.txt From be8d113e5baf65ccb760aff93d1c52706cad1230 Mon Sep 17 00:00:00 2001 From: wakonig_k Date: Wed, 12 Oct 2022 16:01:59 +0000 Subject: [PATCH 09/10] Update .gitlab-ci.yml --- .gitlab-ci.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c63f738..53800f3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,11 +2,6 @@ # Official language image. Look for the different tagged releases at: # https://hub.docker.com/r/library/python/tags/ image: python:3.8 -variables: - DOCKER_BUILDKIT: 0 - -services: - - docker:18.09-dind #commands to run in the Docker container before starting each job. before_script: From faa6e0db1aa412d1a5ac6e2e682434a124f2fe07 Mon Sep 17 00:00:00 2001 From: Klaus Wakonig Date: Wed, 12 Oct 2022 18:14:50 +0200 Subject: [PATCH 10/10] fixed tests --- tests/test_galil.py | 2 ++ tests/test_socket.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_galil.py b/tests/test_galil.py index ba98480..4d60a19 100644 --- a/tests/test_galil.py +++ b/tests/test_galil.py @@ -40,6 +40,7 @@ def test_axis_get(pos, msg, sign): b"ntarget=0.000\r", b"movereq=1\r", b"XQ#NEWPAR\r", + b"MG_XQ0\r", ], [ b"1.00", @@ -48,6 +49,7 @@ def test_axis_get(pos, msg, sign): b":", b":", b":", + b"-1", ], ), ], diff --git a/tests/test_socket.py b/tests/test_socket.py index f02d74a..dc33c0d 100644 --- a/tests/test_socket.py +++ b/tests/test_socket.py @@ -1,5 +1,5 @@ -import pytest import socket + from ophyd_devices.utils.socket import SocketIO