From 3099c813d1b6880257633566c0e6d75e98d83a7e Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Wed, 10 May 2023 14:32:11 +0200 Subject: [PATCH 1/2] add unit=s to pollinterval Change-Id: I6a28fecd4b0d650042f2f031a1b64b801fc2885e --- frappy/modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappy/modules.py b/frappy/modules.py index 0105c51..9844b2f 100644 --- a/frappy/modules.py +++ b/frappy/modules.py @@ -834,7 +834,7 @@ class Readable(Module): value = Parameter('current value of the module', FloatRange()) status = Parameter('current status of the module', StatusType(Status), default=(StatusType.IDLE, '')) - pollinterval = Parameter('default poll interval', FloatRange(0.1, 120), + pollinterval = Parameter('default poll interval', FloatRange(0.1, 120, unit='s'), default=5, readonly=False, export=True) def doPoll(self): From c46947afd4e94b51c8d83ee8463dfca90bfa3f62 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Wed, 10 May 2023 14:32:26 +0200 Subject: [PATCH 2/2] update phytron driver offset as storage only (after current draft specs) Change-Id: I1a005f149a8bd562124e2d40e49416957f66e851 --- frappy_psi/phytron.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/frappy_psi/phytron.py b/frappy_psi/phytron.py index ca43725..d4680af 100644 --- a/frappy_psi/phytron.py +++ b/frappy_psi/phytron.py @@ -43,8 +43,7 @@ class PhytronIO(StringIO): _, _, reply = super().communicate('\x02' + command).partition('\x02') if reply[0] == '\x06': # ACK break - raise CommunicationFailedError('missing ACK %r (cmd: %r)' - % (reply, command)) + raise CommunicationFailedError(f'missing ACK {reply!r} (cmd: {command!r})') except Exception as e: if itry < ntry - 1: warn = e @@ -70,13 +69,13 @@ class Motor(HasOffset, PersistentMixin, HasIO, Drivable): encoder_tolerance = Parameter('', FloatRange(unit='deg'), readonly=False, default=0.01) sign = PersistentParam('', IntRange(-1,1), readonly=False, default=1) encoder = Parameter('encoder reading', FloatRange(unit='deg')) - backlash = Parameter("""backlash compensation\n - offset for always approaching from the same side""", - FloatRange(unit='deg'), readonly=False, default=0) + backlash = PersistentParam("""backlash compensation\n + offset for always approaching from the same side""", + FloatRange(unit='deg'), readonly=False, default=0) target_min = Limit() target_max = Limit() alive_time = PersistentParam('alive time for detecting restarts', - FloatRange(), default=0) # export=False + FloatRange(), default=0, export=False) ioClass = PhytronIO fast_poll = 0.1 @@ -86,19 +85,19 @@ class Motor(HasOffset, PersistentMixin, HasIO, Drivable): _reset_needed = False def get(self, cmd): - return self.communicate('%x%s%s' % (self.address, self.axis, cmd)) + return self.communicate(f'{self.address:x}{self.axis}{cmd}') def set(self, cmd, value): # make sure e format is not used, max 8 characters - strvalue = '%.6g' % value + strvalue = f'{value:.6g}' if 'e' in strvalue: if abs(value) <= 1: # very small number - strvalue = '%.7f' % value + strvalue = f'{value:.7f}' elif abs(value) < 99999999: # big number - strvalue = '%.0f' % value + strvalue = f'{value:.0f}' else: - raise ValueError('number (%g) must not have more than 8 digits' % value) - self.communicate('%x%s%s%s' % (self.address, self.axis, cmd, strvalue)) + raise ValueError(f'number ({value}) must not have more than 8 digits') + self.communicate(f'{self.address:x}{self.axis}{cmd}{strvalue}') def set_get(self, cmd, value, query): self.set(cmd, value) @@ -126,7 +125,7 @@ class Motor(HasOffset, PersistentMixin, HasIO, Drivable): enc = self.read_encoder() else: enc = pos - status = self.communicate('%xSE' % self.address) + status = self.communicate(f'{self.address:x}SE') status = status[0:4] if self.axis == 'X' else status[4:8] self.log.debug('run %s enc %s end %s', status[1], status[2], status[3]) status = self.get('=H') @@ -163,6 +162,7 @@ class Motor(HasOffset, PersistentMixin, HasIO, Drivable): self._mismatch_count = 0 self.status = IDLE, '' self.value = pos + self.read_encoder() # let encoder quickly match value self.saveParameters() self.setFastPoll(False) return pos