From 00db8ba8bd21fa741624105fa4e878ffea7515d7 Mon Sep 17 00:00:00 2001 From: Rodriguez Date: Wed, 18 Oct 2023 15:15:26 +0200 Subject: [PATCH] Serial connector update and upgrade driver for tenma 72-2710 --- .../connectors/serial_base.py | 4 +- .../panduza_platform/connectors/serial_tty.py | 4 +- .../panduza_platform/core/platform_device.py | 3 +- .../panduza_platform/devices/tenma/t722710.py | 7 +-- .../ammeter/drv_korad_ka3005p_ammeter.py | 4 +- .../drivers/bpc/drv_korad_ka3005p_bpc.py | 20 +++---- .../drivers/bpc/drv_tenma_722710_bpc.py | 54 ++++++++++--------- .../voltmeter/drv_korad_ka3005p_voltmeter.py | 4 +- 8 files changed, 52 insertions(+), 48 deletions(-) diff --git a/platform/panduza_platform/connectors/serial_base.py b/platform/panduza_platform/connectors/serial_base.py index 563fa7a..6ae7aac 100644 --- a/platform/panduza_platform/connectors/serial_base.py +++ b/platform/panduza_platform/connectors/serial_base.py @@ -7,13 +7,13 @@ class SerialBase(metaclass=abc.ABCMeta): """ @abc.abstractmethod - async def write_uart(self, message): + async def read_data(self, n_bytes = None): """ """ pass @abc.abstractmethod - async def read_uart(self): + async def write_data(self, message): """ """ pass diff --git a/platform/panduza_platform/connectors/serial_tty.py b/platform/panduza_platform/connectors/serial_tty.py index d26d1a9..682c927 100644 --- a/platform/panduza_platform/connectors/serial_tty.py +++ b/platform/panduza_platform/connectors/serial_tty.py @@ -125,7 +125,7 @@ async def connect(self): # --- - async def read_uart(self, n_bytes = None): + async def read_data(self, n_bytes = None): """Read from UART using asynchronous mode """ @@ -144,7 +144,7 @@ async def read_uart(self, n_bytes = None): # --- - async def write_uart(self, message, time_lock=None): + async def write_data(self, message, time_lock=None): """write to UART using asynchronous mode """ async with self._mutex: diff --git a/platform/panduza_platform/core/platform_device.py b/platform/panduza_platform/core/platform_device.py index 3c38705..248ec2c 100644 --- a/platform/panduza_platform/core/platform_device.py +++ b/platform/panduza_platform/core/platform_device.py @@ -117,7 +117,8 @@ def _PZA_DEV_config(self): def _PZA_DEV_interfaces_generator(self): """Generate interface definitions from device settings """ - return {} + raise Exception("Function Not Implemented !") + # return {} # --- diff --git a/platform/panduza_platform/devices/tenma/t722710.py b/platform/panduza_platform/devices/tenma/t722710.py index fe959d6..db41c92 100644 --- a/platform/panduza_platform/devices/tenma/t722710.py +++ b/platform/panduza_platform/devices/tenma/t722710.py @@ -13,23 +13,24 @@ def _PZA_DEV_config(self): """ """ return { + "family": "bps", "model": "722710", "manufacturer": "Tenma" } - def _PZA_DEV_interfaces(self): + def _PZA_DEV_interfaces_generator(self): """ """ interfaces = [] - fake_mode = self._initial_settings.get("fake_mode", False) + fake_mode = self.get_settings().get("fake_mode", False) if fake_mode: pass else: interfaces.append({ - "name": f"bpc", + "name": f":channel_{0}:_ctrl", "driver": "tenma.722710.bpc", "settings": { "usb_vendor": USBID_VENDOR, diff --git a/platform/panduza_platform/drivers/ammeter/drv_korad_ka3005p_ammeter.py b/platform/panduza_platform/drivers/ammeter/drv_korad_ka3005p_ammeter.py index 192b603..d440364 100644 --- a/platform/panduza_platform/drivers/ammeter/drv_korad_ka3005p_ammeter.py +++ b/platform/panduza_platform/drivers/ammeter/drv_korad_ka3005p_ammeter.py @@ -39,8 +39,8 @@ async def _PZA_DRV_loop_init(self, loop, tree): async def _PZA_DRV_AMMETER_read_measure_value(self): cmd = "IOUT1?" - await self.uart_connector.write_uart(cmd) - current = await self.uart_connector.read_uart(n_bytes=5) + await self.uart_connector.write_data(cmd) + current = await self.uart_connector.read_data(n_bytes=5) return float(current) # --- \ No newline at end of file diff --git a/platform/panduza_platform/drivers/bpc/drv_korad_ka3005p_bpc.py b/platform/panduza_platform/drivers/bpc/drv_korad_ka3005p_bpc.py index 4df25bb..ebf63ca 100644 --- a/platform/panduza_platform/drivers/bpc/drv_korad_ka3005p_bpc.py +++ b/platform/panduza_platform/drivers/bpc/drv_korad_ka3005p_bpc.py @@ -51,8 +51,8 @@ async def _PZA_DRV_loop_init(self, loop, tree): async def _PZA_DRV_BPC_read_enable_value(self): await asyncio.sleep(1) print("Sending cmd: {}".format("STATUS?")) - await self.uart_connector.write_uart("STATUS?") - status = await self.uart_connector.read_uart(n_bytes=1) + await self.uart_connector.write_data("STATUS?") + status = await self.uart_connector.read_data(n_bytes=1) print("LOL", status) return bool(status[0] & (1 << 6)) @@ -60,8 +60,8 @@ async def _PZA_DRV_BPC_write_enable_value(self, v): await asyncio.sleep(1) cmd = "OUT{}".format(int(v)) print("Sending cmd: {}".format(cmd)) - await self.uart_connector.write_uart(cmd) - status = await self.uart_connector.read_uart(n_bytes=1) + await self.uart_connector.write_data(cmd) + status = await self.uart_connector.read_data(n_bytes=1) await asyncio.sleep(1) # --- @@ -69,15 +69,15 @@ async def _PZA_DRV_BPC_write_enable_value(self, v): async def _PZA_DRV_BPC_read_voltage_value(self): await asyncio.sleep(0.2) cmd = "VSET1?" - await self.uart_connector.write_uart(cmd) - voltage = await self.uart_connector.read_uart(n_bytes=5) + await self.uart_connector.write_data(cmd) + voltage = await self.uart_connector.read_data(n_bytes=5) return float(voltage) async def _PZA_DRV_BPC_write_voltage_value(self, v): await asyncio.sleep(0.2) v = "{:05.2f}".format(v) cmd = "VSET1:{}".format(v) - await self.uart_connector.write_uart(cmd) + await self.uart_connector.write_data(cmd) async def _PZA_DRV_BPC_voltage_value_min_max(self): return VOLTAGE_BOUNDS @@ -90,15 +90,15 @@ async def _PZA_DRV_BPC_read_voltage_decimals(self): async def _PZA_DRV_BPC_read_current_value(self): await asyncio.sleep(0.2) cmd = "ISET1?" - await self.uart_connector.write_uart(cmd) - current = await self.uart_connector.read_uart(n_bytes=5) + await self.uart_connector.write_data(cmd) + current = await self.uart_connector.read_data(n_bytes=5) return float(current) async def _PZA_DRV_BPC_write_current_value(self, v): await asyncio.sleep(0.2) v = "{:05.3f}".format(v) cmd = "ISET1:{}".format(v) - await self.uart_connector.write_uart(cmd) + await self.uart_connector.write_data(cmd) async def _PZA_DRV_BPC_current_value_min_max(self): return CURRENT_BOUNDS diff --git a/platform/panduza_platform/drivers/bpc/drv_tenma_722710_bpc.py b/platform/panduza_platform/drivers/bpc/drv_tenma_722710_bpc.py index 46e8b3c..47ac1bb 100644 --- a/platform/panduza_platform/drivers/bpc/drv_tenma_722710_bpc.py +++ b/platform/panduza_platform/drivers/bpc/drv_tenma_722710_bpc.py @@ -45,10 +45,7 @@ async def _PZA_DRV_loop_init(self, loop, tree): assert_that(settings, has_key("usb_model")) assert_that(settings, has_key("serial_baudrate")) - # Get the gate - #self.modbus = await ConnectorModbusClientSerial.Get(**settings) - - # Get the gate connector + # Get the Serial Connector self.uart_connector = await SerialTty.Get(loop,**settings) # @@ -64,37 +61,42 @@ async def _PZA_DRV_loop_init(self, loop, tree): # STATE # async def _PZA_DRV_BPC_read_enable_value(self): - # Send "STATUS?" to get back the output state - await self.uart_connector.write_uart(f"STATUS?\n") - statusBytes = await self.uart_connector.read_uart() - status = ord(statusBytes) - if status & 0x40: - out = 1 - else: - out = 0 - str_value = int_to_state_string(out) - return str_value + # Send "STATUS?" to get back the output state + + + await self.uart_connector.write_data(f"STATUS?\n") + statusBytes = await self.uart_connector.read_data() + + self.log.debug(f"{statusBytes.strip()}") + status = ord(statusBytes.strip()) + + if status & 0x40: + out = 1 + else: + out = 0 + str_value = int_to_state_string(out) + return str_value # --- async def _PZA_DRV_BPC_write_enable_value(self, v): # Send "OUT{v}" to enable output int16_value = STATE_VALUE_ENUM[v] - await self.uart_connector.write_uart(f"OUT{int16_value}\n") + await self.uart_connector.write_data(f"OUT{int16_value}\n") # VOLTAGE # async def _PZA_DRV_BPC_read_voltage_value(self): - # Send "VSET1?" to get the voltage value - await self.uart_connector.write_uart(f"VSET{self.channel}?\n") - voltage = await self.uart_connector.read_uart() - return float(voltage) + # Send "VSET1?" to get the voltage value + await self.uart_connector.write_data(f"VSET{self.channel}?\n") + voltage = await self.uart_connector.read_data() + return float(voltage) # --- async def _PZA_DRV_BPC_write_voltage_value(self, v): - # Send "VSET1:{v}" to set the voltage value - await self.uart_connector.write_uart(f"VSET{self.channel}:{v}\n") + # Send "VSET1:{v}" to set the voltage value + await self.uart_connector.write_data(f"VSET{self.channel}:{v}\n") # --- @@ -109,16 +111,16 @@ async def _PZA_DRV_BPC_read_voltage_decimals(self): # CURRENT # async def _PZA_DRV_BPC_read_current_value(self): - # Send "ISET1?" to get the Current value - await self.uart_connector.write_uart(f"ISET{self.channel}?\n") - current = await self.uart_connector.read_uart() - return float(current) + # Send "ISET1?" to get the Current value + await self.uart_connector.write_data(f"ISET{self.channel}?\n") + current = await self.uart_connector.read_data() + return float(current) # --- async def _PZA_DRV_BPC_write_current_value(self, v): # Send "ISET1:{v}" to set the Current value - await self.uart_connector.write_uart(f"ISET{self.channel}:{v}\n") + await self.uart_connector.write_data(f"ISET{self.channel}:{v}\n") # --- diff --git a/platform/panduza_platform/drivers/voltmeter/drv_korad_ka3005p_voltmeter.py b/platform/panduza_platform/drivers/voltmeter/drv_korad_ka3005p_voltmeter.py index c258fff..7e8ce4a 100644 --- a/platform/panduza_platform/drivers/voltmeter/drv_korad_ka3005p_voltmeter.py +++ b/platform/panduza_platform/drivers/voltmeter/drv_korad_ka3005p_voltmeter.py @@ -39,8 +39,8 @@ async def _PZA_DRV_loop_init(self, loop, tree): async def _PZA_DRV_VOLTMETER_read_measure_value(self): cmd = "VOUT1?" - await self.uart_connector.write_uart(cmd) - voltage = await self.uart_connector.read_uart(n_bytes=5) + await self.uart_connector.write_data(cmd) + voltage = await self.uart_connector.read_data(n_bytes=5) return float(voltage) # --- \ No newline at end of file