From 03c356590badbd5527c6911d6959f13979de0b89 Mon Sep 17 00:00:00 2001 From: zebra Date: Mon, 2 Oct 2023 16:58:09 +0200 Subject: [PATCH] frappy_psi.phytron: implement limit switches --- frappy_psi/phytron.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/frappy_psi/phytron.py b/frappy_psi/phytron.py index 244fc7f..5909d05 100644 --- a/frappy_psi/phytron.py +++ b/frappy_psi/phytron.py @@ -20,15 +20,12 @@ # # ***************************************************************************** -"""driver for phytron motors - -limits switches are not yet implemented -""" +"""driver for phytron motors """ import time from frappy.core import Done, Command, EnumType, FloatRange, IntRange, \ HasIO, Parameter, Property, Drivable, PersistentMixin, PersistentParam, \ - StringIO, StringType, IDLE, BUSY, ERROR, Limit + StringIO, StringType, IDLE, BUSY, ERROR, Limit, BoolType from frappy.errors import CommunicationFailedError, HardwareError from frappy.features import HasOffset from frappy.states import HasStates, status_code, Retry @@ -66,6 +63,8 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable): encoder_mode = Parameter('how to treat the encoder', EnumType('encoder', NO=0, READ=1, CHECK=2), default=1, readonly=False) + check_limit_switches = Parameter('whethter limit switches are checked',BoolType(), + default=0, readonly=False) value = PersistentParam('angle', FloatRange(unit='deg')) status = PersistentParam() target = Parameter('target angle', FloatRange(unit='deg'), readonly=False) @@ -186,11 +185,14 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable): self.hw_stop() def read_status(self): + hexstatus = 0x100 for _ in range(3): sysstatus = self.communicate(f'{self.address:x}SE') try: sysstatus = sysstatus[1:4] if self.axis == 'X' else sysstatus[5:8] hexstatus = int(sysstatus, base=16) + if not self.check_limit_switches: + hexstatus &= 0xfcf # ignore limit switch bits status_items = formatStatusBits(hexstatus & 0xf7, self.status_bits) if status_items: status = ERROR, ', '.join(status_items)