Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
Serial connector update and upgrade driver for tenma 72-2710
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodriguez committed Oct 18, 2023
1 parent 9f27f59 commit 00db8ba
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 48 deletions.
4 changes: 2 additions & 2 deletions platform/panduza_platform/connectors/serial_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions platform/panduza_platform/connectors/serial_tty.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""

Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion platform/panduza_platform/core/platform_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

# ---

Expand Down
7 changes: 4 additions & 3 deletions platform/panduza_platform/devices/tenma/t722710.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

# ---
20 changes: 10 additions & 10 deletions platform/panduza_platform/drivers/bpc/drv_korad_ka3005p_bpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,33 @@ 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))

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)

# ---

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
Expand All @@ -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
Expand Down
54 changes: 28 additions & 26 deletions platform/panduza_platform/drivers/bpc/drv_tenma_722710_bpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

#
Expand All @@ -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")

# ---

Expand All @@ -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")

# ---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

# ---

0 comments on commit 00db8ba

Please sign in to comment.