From 07f744ff983533838b323c5ae07a9548d2a014b0 Mon Sep 17 00:00:00 2001 From: Rodriguez Date: Wed, 15 Nov 2023 07:40:02 +0100 Subject: [PATCH] adapt and test hm310t --- .../devices/hanmatek/hm310t/dev_hm310t.py | 5 +++ .../hm310t/itf_hanmatek_hm310t_voltmeter.py | 42 +++++++++++++++++++ .../tenma/t722710/itf_tenma_722710_ammeter.py | 2 +- .../tenma/t722710/itf_tenma_722710_bpc.py | 6 +-- .../t722710/itf_tenma_722710_voltmeter.py | 2 +- platform/tests/manual/load_config.py | 14 ++++++- 6 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 platform/panduza_platform/devices/hanmatek/hm310t/itf_hanmatek_hm310t_voltmeter.py diff --git a/platform/panduza_platform/devices/hanmatek/hm310t/dev_hm310t.py b/platform/panduza_platform/devices/hanmatek/hm310t/dev_hm310t.py index ac487dc..422f989 100644 --- a/platform/panduza_platform/devices/hanmatek/hm310t/dev_hm310t.py +++ b/platform/panduza_platform/devices/hanmatek/hm310t/dev_hm310t.py @@ -8,6 +8,7 @@ from .itf_hanmatek_hm310t_bpc import InterfaceHanmatekHm310tBpc from .itf_hanmatek_hm310t_ammeter import InterfaceHanmatekHM310tAmmeter +from .itf_hanmatek_hm310t_voltmeter import InterfaceHanmatekHM310tVoltmeter from connectors.udev_tty import HuntUsbDevs from connectors.modbus_client_serial import ConnectorModbusClientSerial @@ -87,4 +88,8 @@ async def _PZA_DEV_mount_interfaces(self): self.mount_interface( InterfaceHanmatekHM310tAmmeter(name=f":channel_0:_am", modbus_settings=modbus_settings) ) + self.mount_interface( + InterfaceHanmatekHM310tVoltmeter(name=f":channel_0:_vm", modbus_settings=modbus_settings) + ) + diff --git a/platform/panduza_platform/devices/hanmatek/hm310t/itf_hanmatek_hm310t_voltmeter.py b/platform/panduza_platform/devices/hanmatek/hm310t/itf_hanmatek_hm310t_voltmeter.py new file mode 100644 index 0000000..f58f0d5 --- /dev/null +++ b/platform/panduza_platform/devices/hanmatek/hm310t/itf_hanmatek_hm310t_voltmeter.py @@ -0,0 +1,42 @@ +from hamcrest import assert_that, has_key, instance_of +from meta_drivers.voltmeter import MetaDriverVoltmeter +from connectors.modbus_client_serial import ConnectorModbusClientSerial + +class InterfaceHanmatekHM310tVoltmeter(MetaDriverVoltmeter): + """ + """ + + # --- + + def __init__(self, name=None, modbus_settings={}) -> None: + """Constructor + """ + self.modbus_settings = modbus_settings + super().__init__(name=name) + + # --- + + async def _PZA_DRV_loop_init(self): + """Driver initialization + """ + + # Get the gate + self.modbus = await ConnectorModbusClientSerial.Get(**self.modbus_settings) + + # + self.modbus_unit = 1 + + # Call meta class BPC ini + await super()._PZA_DRV_loop_init() + + # --- + + async def _PZA_DRV_VOLTMETER_read_measure_value(self): + addr = 0x0010 + regs = await self.modbus.read_holding_registers(addr, 1, self.modbus_unit) + # self.log.debug(f"read real current addr={hex(addr)} regs={regs}") + float_value = float(regs[0]) / 100.0 + return float_value + + # --- + diff --git a/platform/panduza_platform/devices/tenma/t722710/itf_tenma_722710_ammeter.py b/platform/panduza_platform/devices/tenma/t722710/itf_tenma_722710_ammeter.py index 88b0f73..f08d97c 100644 --- a/platform/panduza_platform/devices/tenma/t722710/itf_tenma_722710_ammeter.py +++ b/platform/panduza_platform/devices/tenma/t722710/itf_tenma_722710_ammeter.py @@ -33,7 +33,7 @@ async def _PZA_DRV_loop_init(self): # --- async def _PZA_DRV_AMMETER_read_measure_value(self): - current = await self.serial_connector.write_and_read_until(f"IOUT{self.channel}?\n", time_lock_s=COMMAND_TIME_LOCK) + current = await self.serial_connector.write_and_read_until(f"IOUT{self.channel}?\n", time_lock_s=COMMAND_TIME_LOCK, read_duration_s=0.1) return float(current) # --- diff --git a/platform/panduza_platform/devices/tenma/t722710/itf_tenma_722710_bpc.py b/platform/panduza_platform/devices/tenma/t722710/itf_tenma_722710_bpc.py index f2f9d1c..3b4765d 100644 --- a/platform/panduza_platform/devices/tenma/t722710/itf_tenma_722710_bpc.py +++ b/platform/panduza_platform/devices/tenma/t722710/itf_tenma_722710_bpc.py @@ -51,7 +51,7 @@ async def _PZA_DRV_loop_init(self): async def _PZA_DRV_BPC_read_enable_value(self): # Send "STATUS?" to get back the output state - statusBytes = await self.serial_connector.write_and_read_until("STATUS?\n", time_lock_s=COMMAND_TIME_LOCK) + statusBytes = await self.serial_connector.write_and_read_until("STATUS?\n", time_lock_s=COMMAND_TIME_LOCK, read_duration_s=0.1) self.log.debug(f"{statusBytes.strip()}") status = ord(statusBytes.strip()) @@ -74,7 +74,7 @@ async def _PZA_DRV_BPC_write_enable_value(self, v): async def _PZA_DRV_BPC_read_voltage_value(self): # Send "VSET1?" to get the voltage value - voltage = await self.serial_connector.write_and_read_until(f"VSET{self.channel}?\n", time_lock_s=COMMAND_TIME_LOCK) + voltage = await self.serial_connector.write_and_read_until(f"VSET{self.channel}?\n", time_lock_s=COMMAND_TIME_LOCK, read_duration_s=0.1) return float(voltage) # --- @@ -96,7 +96,7 @@ async def _PZA_DRV_BPC_read_voltage_decimals(self): # CURRENT # async def _PZA_DRV_BPC_read_current_value(self): - current = await self.serial_connector.write_and_read_until(f"ISET{self.channel}?\n", time_lock_s=COMMAND_TIME_LOCK) + current = await self.serial_connector.write_and_read_until(f"ISET{self.channel}?\n", time_lock_s=COMMAND_TIME_LOCK, read_duration_s=0.1) return float(current) # --- diff --git a/platform/panduza_platform/devices/tenma/t722710/itf_tenma_722710_voltmeter.py b/platform/panduza_platform/devices/tenma/t722710/itf_tenma_722710_voltmeter.py index ed41a43..77d584c 100644 --- a/platform/panduza_platform/devices/tenma/t722710/itf_tenma_722710_voltmeter.py +++ b/platform/panduza_platform/devices/tenma/t722710/itf_tenma_722710_voltmeter.py @@ -33,7 +33,7 @@ async def _PZA_DRV_loop_init(self): # --- async def _PZA_DRV_VOLTMETER_read_measure_value(self): - voltage = await self.serial_connector.write_and_read_until(f"VOUT{self.channel}?\n", time_lock_s=COMMAND_TIME_LOCK) + voltage = await self.serial_connector.write_and_read_until(f"VOUT{self.channel}?\n", time_lock_s=COMMAND_TIME_LOCK, read_duration_s=0.1) return float(voltage) # --- diff --git a/platform/tests/manual/load_config.py b/platform/tests/manual/load_config.py index 1a6bf12..3c1334d 100644 --- a/platform/tests/manual/load_config.py +++ b/platform/tests/manual/load_config.py @@ -17,10 +17,22 @@ plat = Platform(addr=ADDR, port=PORT, topic=platform_topic) +# plat.dtree.content.set({ +# "devices": [ +# {'ref': 'Tenma.72-2710', 'settings': {'usb_serial_short': '00321FCC0454'}} +# ] +# }) + +# plat.dtree.content.set({ +# "devices": [ +# {'ref': 'Hanmatek.Hm310t', 'settings': {}} +# ] +# }) + plat.dtree.content.set({ "devices": [ + {'ref': 'Hanmatek.Hm310t', 'settings': {}}, {'ref': 'Tenma.72-2710', 'settings': {'usb_serial_short': '00321FCC0454'}} ] }) -