diff --git a/frappy_psi/ionopimax.py b/frappy_psi/ionopimax.py index 7d0b8792..e6eeb1f6 100644 --- a/frappy_psi/ionopimax.py +++ b/frappy_psi/ionopimax.py @@ -38,7 +38,6 @@ class Base: def initModule(self): super().initModule() - self.log.info('initModule %r', self.name) candidates = list(Path('/sys/class').glob(f'ionopi*/*/{self.addr}')) if not candidates: raise ConfigError(f'can not find path for {self.addr}') @@ -49,10 +48,12 @@ class Base: def read(self, addr, scale=None): with open(self._devpath / addr) as f: - result = f.read() + result = f.read().strip() + if result == '-1': + self.log.warning('read %r (error?) %s', result, self._devpath / addr) if scale: return float(result) / scale - return result.strip() + return result def write(self, addr, value, scale=None): value = str(round(value * scale)) if scale else str(value) @@ -135,7 +136,9 @@ class VoltageInput(AnalogInput): def initModule(self): super().initModule() - self.write(f'{self.addr}_mode','U') + if self.read(f'{self.addr}_mode') != 'U': + # change mode only if needed, as this disturbs the input for some time + self.write(f'{self.addr}_mode', 'U') class LogVoltageInput(VoltageInput): @@ -157,7 +160,10 @@ class CurrentInput(AnalogInput): def initModule(self): super().initModule() - self.write(f'{self.addr}_mode', 'U') + if self.read(f'{self.addr}_mode') != 'U': + # change mode only if needed, as this disturbs the input for some time + self.log.warning('set mode to U') + self.write(f'{self.addr}_mode', 'U') class AnalogOutput(AnalogInput, Writable):