diff --git a/.pylintrc b/.pylintrc index 21527bf..6180ea0 100644 --- a/.pylintrc +++ b/.pylintrc @@ -218,7 +218,7 @@ max-branches=50 max-statements=150 # Maximum number of parents for a class (see R0901). -max-parents=15 +max-parents=25 # Maximum number of attributes for a class (see R0902). max-attributes=50 diff --git a/Makefile b/Makefile index 6e4f543..3148ea2 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ doc: $(MAKE) -C doc html lint: - pylint -j 0 -f colorized -r n --rcfile=.pylintrc secop secop_* test + pylint -f colorized -r n --rcfile=.pylintrc secop secop_* test isort: @find test -name '*.py' -print0 | xargs -0 isort -e -m 2 -w 80 -ns __init__.py diff --git a/secop_psi/mercury.py b/secop_psi/mercury.py index abd5be3..deb4a9e 100644 --- a/secop_psi/mercury.py +++ b/secop_psi/mercury.py @@ -327,15 +327,15 @@ class HeaterOutput(HasInput, MercuryChannel, Writable): self._last_target = self._volt_target ** 2 / max(10, self.resistivity) return self._last_target - def set_target(self, value): + def set_target(self, target): """set the target without switching to manual might be used by a software loop """ - self._volt_target = math.sqrt(value * self.resistivity) + self._volt_target = math.sqrt(target * self.resistivity) self.change('HTR:SIG:VOLT', self._volt_target) - self._last_target = value - return value + self._last_target = target + return target def write_target(self, value): self.write_controlled_by(SELF) @@ -482,13 +482,13 @@ class PressureLoop(HasInput, PressureSensor, Loop, Drivable): def read_target(self): return self.query('PRES:LOOP:PRST') - def set_target(self, value): + def set_target(self, target): """set the target without switching to manual might be used by a software loop """ - self.change('PRES:LOOP:PRST', value) - super().set_target(value) + self.change('PRES:LOOP:PRST', target) + super().set_target(target) def write_target(self, value): self.write_controlled_by(SELF) diff --git a/secop_psi/phytron.py b/secop_psi/phytron.py index 5fcdbf9..14f596e 100644 --- a/secop_psi/phytron.py +++ b/secop_psi/phytron.py @@ -34,13 +34,11 @@ class PhytronIO(StringIO): timeout = 0.5 identification = [('0IVR', 'MCC Minilog .*')] - def communicate(self, command, expect_response=True): + def communicate(self, command): for ntry in range(5, 0, -1): try: _, _, reply = super().communicate('\x02' + command).partition('\x02') if reply[0] == '\x06': # ACK - if len(reply) == 1 and expect_response: - raise CommunicationFailedError('empty response') break raise CommunicationFailedError('missing ACK %r' % reply) except Exception as e: @@ -77,7 +75,7 @@ class Motor(PersistentMixin, HasIO, Drivable): _backlash_pending = False _mismatch_count = 0 _rawlimits = None - _step_size = None + _step_size = None # degree / step def earlyInit(self): super().earlyInit() @@ -92,7 +90,7 @@ class Motor(PersistentMixin, HasIO, Drivable): return self.communicate('\x02%x%s%s' % (self.address, self.axis, cmd)) def set(self, cmd, value): - self.communicate('\x02%x%s%s%g' % (self.address, self.axis, cmd, value), False) + self.communicate('\x02%x%s%s%g' % (self.address, self.axis, cmd, value)) def set_get(self, cmd, value, query): self.set(cmd, value) diff --git a/secop_psi/triton.py b/secop_psi/triton.py index b03d4e9..998b162 100644 --- a/secop_psi/triton.py +++ b/secop_psi/triton.py @@ -21,8 +21,7 @@ """oxford instruments triton (kelvinoxjt dil)""" from math import sqrt -from secop.core import Writable, Parameter, Readable, Drivable, IDLE, WARN, BUSY, Done -from secop.errors import HardwareError +from secop.core import Writable, Parameter, Readable, Drivable, IDLE, WARN, BUSY, ERROR, Done from secop.datatypes import EnumType, FloatRange from secop.lib.enum import Enum from secop_psi.mercury import MercuryChannel, Mapped, off_on, HasInput, SELF @@ -62,7 +61,7 @@ class Action(MercuryChannel, Writable): # PCOND (pause pre-cool (not condense?) automation) # RCOND (resume pre-cool (not condense?) automation) # WARM (warm-up) - # EPCL (empty pre-coll automation) + # EPCL (empty pre-cool automation) class Valve(MercuryChannel, Drivable): @@ -76,7 +75,19 @@ class Valve(MercuryChannel, Drivable): self.read_status() def read_value(self): - return self.query('VALV:SIG:STATE', open_close) + pos = self.query('VALV:SIG:STATE', open_close) + if pos == self.target: + self.status = IDLE, '' + self._try_count = 0 + self.setFastPoll(False) + elif self._try_count <= 7: # odd number: last try is previous position + # toggle new/previous position until success or too many tries + self.change('VALV:SIG:STATE', pos if self._try_count % 2 else self.target, open_close) + self._try_count += 1 + self.status = BUSY, 'opening' if self.target else 'closing' + else: + self.status = ERROR, 'can not %s valve' % self.target.name + return pos def read_status(self): pos = self.read_value()