Skip to content

Commit

Permalink
start restoring tenma 72-2710
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodriguez committed Nov 14, 2023
1 parent b741e4a commit 03a98d3
Show file tree
Hide file tree
Showing 18 changed files with 180 additions and 202 deletions.
14 changes: 0 additions & 14 deletions platform/panduza_platform/connectors/olds/serial_base.py

This file was deleted.

82 changes: 0 additions & 82 deletions platform/panduza_platform/connectors/olds/serial_tty.py

This file was deleted.

2 changes: 1 addition & 1 deletion platform/panduza_platform/connectors/serial_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import abc

class SerialBase(metaclass=abc.ABCMeta):
class ConnectorSerialBase(metaclass=abc.ABCMeta):
"""Base class for modbus client connectors
It defines method to interact with the modbus client
Expand Down
33 changes: 15 additions & 18 deletions platform/panduza_platform/connectors/serial_tty.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,23 @@
import aioserial
# import serial_asyncio

from .serial_base import SerialBase
from .serial_base import ConnectorSerialBase
from log.driver import driver_logger

from .udev_tty import SerialPortFromUsbSetting

class SerialTty(SerialBase):
class ConnectorSerialTty(ConnectorSerialBase):
"""
"""

# Hold instances mutex
__MUTEX = asyncio.Lock()

# Hold instances mutex
__MUTEX = asyncio.Lock()

# Contains instances
__INSTANCES = {}

# Local logs
log = driver_logger("SerialTty")
log = driver_logger("ConnectorSerialTty")

###########################################################################
###########################################################################
Expand All @@ -46,12 +43,12 @@ async def Get(**kwargs):
ID_MODEL_ID
"""
# Log
SerialTty.log.debug(f"Get connector for {kwargs}")
ConnectorSerialTty.log.debug(f"Get connector for {kwargs}")

async with SerialTty.__MUTEX:
async with ConnectorSerialTty.__MUTEX:

# Log
SerialTty.log.debug(f"Lock acquired !")
ConnectorSerialTty.log.debug(f"Lock acquired !")


# Get the serial port name
Expand All @@ -67,22 +64,22 @@ async def Get(**kwargs):
raise Exception("no way to identify the serial port")

# Create the new connector
if not (serial_port_name in SerialTty.__INSTANCES):
SerialTty.__INSTANCES[serial_port_name] = None
if not (serial_port_name in ConnectorSerialTty.__INSTANCES):
ConnectorSerialTty.__INSTANCES[serial_port_name] = None
try:
new_instance = SerialTty(**kwargs)
new_instance = ConnectorSerialTty(**kwargs)
await new_instance.connect()

SerialTty.__INSTANCES[serial_port_name] = new_instance
SerialTty.log.info("connector created")
ConnectorSerialTty.__INSTANCES[serial_port_name] = new_instance
ConnectorSerialTty.log.info("connector created")
except Exception as e:
SerialTty.__INSTANCES.pop(serial_port_name)
ConnectorSerialTty.__INSTANCES.pop(serial_port_name)
raise Exception('Error during initialization').with_traceback(e.__traceback__)
else:
SerialTty.log.info("connector already created, use existing instance")
ConnectorSerialTty.log.info("connector already created, use existing instance")

# Return the previously created
return SerialTty.__INSTANCES[serial_port_name]
return ConnectorSerialTty.__INSTANCES[serial_port_name]

###########################################################################
###########################################################################
Expand All @@ -104,7 +101,7 @@ def __init__(self, **kwargs):

key = kwargs["serial_port_name"]

if not (key in SerialTty.__INSTANCES):
if not (key in ConnectorSerialTty.__INSTANCES):
raise Exception("You need to pass through Get method to create an instance")
else:
self.log = driver_logger(key)
Expand Down
6 changes: 6 additions & 0 deletions platform/panduza_platform/core/platform_device.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import abc
import copy
from .platform_errors import InitializationError
from .itf_device import InterfacePanduzaDevice

Expand Down Expand Up @@ -123,6 +124,11 @@ def get_manufacturer(self):

# ---

def get_settings(self):
return copy.deepcopy(self.settings)

# ---

def get_settings_props(self):
return self.get_config_field("settings_props", [])

Expand Down
3 changes: 3 additions & 0 deletions platform/panduza_platform/core/platform_device_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ async def hunt_next(self):
d = next(self.__hunt_iter)

device_builder = self.__device_templates[d]()

self.__log.info(f"HUNT FOR >> {device_builder.get_ref()}")

instances = await device_builder.get_hunted_instances()
self.__device_store[d]['instances'] = instances

Expand Down
4 changes: 2 additions & 2 deletions platform/panduza_platform/devices/korad/ka3005/dev_ka3005.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from connectors.udev_tty import HuntUsbDevs

from connectors.serial_tty import SerialTty
from connectors.serial_tty import ConnectorSerialTty

class DeviceKoradKA3005P(PlatformDevice):
"""Power Supply From Korad
Expand Down Expand Up @@ -37,7 +37,7 @@ async def _PZA_DEV_hunt(self):
"""
print( HuntUsbDevs('0416', '5011', 'tty') )

# connector = await SerialTty.Get(serial_port_name='/dev/ttyACM0')
# connector = await ConnectorSerialTty.Get(serial_port_name='/dev/ttyACM0')
# status = await connector.write_and_read_until("*IDN?", time_lock_s=0.5)

# print(">>> ", status)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from hamcrest import assert_that, has_key, instance_of
import asyncio
from meta_drivers.ammeter import MetaDriverAmmeter
from connectors.serial_tty import SerialTty
from connectors.serial_tty import ConnectorSerialTty

COMMAND_TIME_LOCK=0.1

Expand Down Expand Up @@ -31,7 +31,7 @@ async def _PZA_DRV_loop_init(self):
# Checks
assert_that(settings, has_key("serial_baudrate"))

self.serial_connector = await SerialTty.Get(loop,**settings)
self.serial_connector = await ConnectorSerialTty.Get(loop,**settings)

# Call meta class BPC ini
await super()._PZA_DRV_loop_init()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from hamcrest import assert_that, has_key, instance_of
import asyncio
from meta_drivers.bpc import MetaDriverBpc
from connectors.serial_tty import SerialTty
from connectors.serial_tty import ConnectorSerialTty

VOLTAGE_BOUNDS = { "min": 0, "max": 30 }
CURRENT_BOUNDS = { "min": 0, "max": 5 }
Expand Down Expand Up @@ -36,7 +36,7 @@ async def _PZA_DRV_loop_init(self):
# Checks
assert_that(settings, has_key("serial_baudrate"))

self.serial_connector = await SerialTty.Get(loop,**settings)
self.serial_connector = await ConnectorSerialTty.Get(loop,**settings)

# Call meta class BPC ini
await super()._PZA_DRV_loop_init()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from hamcrest import assert_that, has_key, instance_of
import asyncio
from meta_drivers.voltmeter import MetaDriverVoltmeter
from connectors.serial_tty import SerialTty
from connectors.serial_tty import ConnectorSerialTty

COMMAND_TIME_LOCK=0.1

Expand Down Expand Up @@ -31,7 +31,7 @@ async def _PZA_DRV_loop_init(self):
# Checks
assert_that(settings, has_key("serial_baudrate"))

self.serial_connector = await SerialTty.Get(loop,**settings)
self.serial_connector = await ConnectorSerialTty.Get(loop,**settings)

# Call meta class BPC ini
await super()._PZA_DRV_loop_init()
Expand Down
2 changes: 1 addition & 1 deletion platform/panduza_platform/devices/tenma/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .t722710.t722710 import DeviceTenma722710
from .t722710.dev_t722710 import DeviceTenma722710

PZA_DEVICES_LIST= [
DeviceTenma722710
Expand Down
Empty file.
Loading

0 comments on commit 03a98d3

Please sign in to comment.