AnalogInput: write mode only when needed

- this does probably influence the input channel for some short time
+ issue a warning when read value is -1. this may indicate an error!
This commit is contained in:
2025-07-07 16:03:45 +02:00
parent 03dfb6aeb0
commit 1e73440149

View File

@@ -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):