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

Commit

Permalink
adapt and test hm310t
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodriguez committed Nov 15, 2023
1 parent 07897bf commit 07f744f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
)


Original file line number Diff line number Diff line change
@@ -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

# ---

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

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

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

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

# ---
Expand Down
14 changes: 13 additions & 1 deletion platform/tests/manual/load_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}}
]
})


0 comments on commit 07f744f

Please sign in to comment.