From f75802f66968bdee7a8b52cd63b4b46844bcac78 Mon Sep 17 00:00:00 2001 From: thijs snijder <snijder@astron.nl> Date: Thu, 22 Apr 2021 15:15:31 +0200 Subject: [PATCH] misc fixes --- devices/HW_device_template.py | 5 +++-- devices/PCC.py | 5 +++-- devices/SDP.py | 6 ++++-- devices/clients/test_client.py | 8 +++++--- devices/src/attribute_wrapper.py | 17 ++++++++--------- devices/src/comms_client.py | 1 - devices/src/hardware_device.py | 2 +- devices/test_device.py | 8 ++++---- 8 files changed, 28 insertions(+), 24 deletions(-) diff --git a/devices/HW_device_template.py b/devices/HW_device_template.py index 0249747de..cd7880672 100644 --- a/devices/HW_device_template.py +++ b/devices/HW_device_template.py @@ -11,10 +11,11 @@ # PyTango imports from tango.server import run +from tango import AttrWriteType # Additional import -from src.attribute_wrapper import * -from src.hardware_device import * +from src.attribute_wrapper import attribute_wrapper +from src.hardware_device import hardware_device __all__ = ["HW_dev"] diff --git a/devices/PCC.py b/devices/PCC.py index b1bc93d9c..79b8a8228 100644 --- a/devices/PCC.py +++ b/devices/PCC.py @@ -15,11 +15,12 @@ from tango import DebugIt from tango.server import run, command from tango.server import device_property +from tango import AttrWriteType # Additional import from clients.opcua_connection import OPCUAConnection -from src.attribute_wrapper import * -from src.hardware_device import * +from src.attribute_wrapper import attribute_wrapper +from src.hardware_device import hardware_device from src.lofar_logging import device_logging_to_python __all__ = ["PCC", "main"] diff --git a/devices/SDP.py b/devices/SDP.py index 05a5841bf..35c03232e 100644 --- a/devices/SDP.py +++ b/devices/SDP.py @@ -14,14 +14,16 @@ # PyTango imports from tango.server import run from tango.server import device_property +from tango import AttrWriteType # Additional import from clients.opcua_connection import OPCUAConnection -from src.attribute_wrapper import * -from src.hardware_device import * +from src.attribute_wrapper import attribute_wrapper +from src.hardware_device import hardware_device from src.lofar_logging import device_logging_to_python +import numpy __all__ = ["SDP", "main"] diff --git a/devices/clients/test_client.py b/devices/clients/test_client.py index 640d2edb5..b191d991f 100644 --- a/devices/clients/test_client.py +++ b/devices/clients/test_client.py @@ -1,11 +1,11 @@ -from src.comms_client import * +from src.comms_client import CommClient import numpy import os # <class 'numpy.bool_'> -class example_client(CommClient): +class test_client(CommClient): """ this class provides an example implementation of a comms_client. Durirng initialisation it creates a correctly shaped zero filled value. on read that value is returned and on write its modified. @@ -47,7 +47,9 @@ class example_client(CommClient): the annotation can be in whatever format may be required. it is up to the user to handle its content example annotation may include: - a file path and file line/location - - COM object path + - server address + - IDs + - data structures """ # as this is an example, just print the annotation diff --git a/devices/src/attribute_wrapper.py b/devices/src/attribute_wrapper.py index 66dcd4bb3..98faf037c 100644 --- a/devices/src/attribute_wrapper.py +++ b/devices/src/attribute_wrapper.py @@ -84,7 +84,6 @@ class attribute_wrapper(attribute): self.write_function(value) device.value_dict[self] = value - self.fget = read_RW self.fset = write_RW @@ -96,8 +95,8 @@ class attribute_wrapper(attribute): @fault_on_error def read_R(device): """ - _read_R reads the attribute value, stores it and returns it" - """ + _read_R reads the attribute value, stores it and returns it" + """ device.value_dict[self] = self.read_function() return device.value_dict[self] @@ -109,8 +108,8 @@ class attribute_wrapper(attribute): def initial_value(self): """ - returns a numpy array filled with zeroes fit to the size of the attribute. Or if init_value is not the default None, return that value - """ + returns a numpy array filled with zeroes fit to the size of the attribute. Or if init_value is not the default None, return that value + """ if self.init_value is not None: return self.init_value @@ -130,16 +129,16 @@ class attribute_wrapper(attribute): def set_comm_client(self, client): """ - takes a communications client as input arguments This client should be of a class containing a "get_mapping" function - and return a read and write function that the wrapper will use to get/set data. - """ + takes a communications client as input arguments This client should be of a class containing a "get_mapping" function + and return a read and write function that the wrapper will use to get/set data. + """ try: self.read_function, self.write_function = client.setup_attribute(self.comms_annotation, self) except Exception as e: def pass_func(value=None): pass - logger.error("Exception while setting %s read/write functions. using pass function instead.", self.comms_annotation) + logger.error("Exception while setting %s attribute with annotation: '%s' read/write functions. using pass function instead to to keep running", client.__class__.__name__, self.comms_annotation) self.read_function = pass_func self.write_function = pass_func diff --git a/devices/src/comms_client.py b/devices/src/comms_client.py index 0405c737d..f189ce3fd 100644 --- a/devices/src/comms_client.py +++ b/devices/src/comms_client.py @@ -44,7 +44,6 @@ class CommClient(Thread): # keep trying to connect if not self.connected: if self.connect(): - # self.standby_func() pass else: # we retry only once, to catch exotic network issues. if the infra or hardware is down, diff --git a/devices/src/hardware_device.py b/devices/src/hardware_device.py index 2a2dafb57..431cbe971 100644 --- a/devices/src/hardware_device.py +++ b/devices/src/hardware_device.py @@ -16,7 +16,7 @@ from tango.server import Device, command from tango import DevState, DebugIt # Additional import -from src.attribute_wrapper import * +from src.attribute_wrapper import attribute_wrapper from src.lofar_logging import log_exceptions __all__ = ["hardware_device"] diff --git a/devices/test_device.py b/devices/test_device.py index 1d7a2f486..38f688cc0 100644 --- a/devices/test_device.py +++ b/devices/test_device.py @@ -16,7 +16,7 @@ from tango.server import device_property from tango import DevState # Additional import -from clients.test_client import example_client +from clients.test_client import test_client from src.attribute_wrapper import * from src.hardware_device import * @@ -71,13 +71,13 @@ class test_device(hardware_device): self.set_state(DevState.INIT) # set up the test client - self.example_client = example_client(self.Fault, self) + self.test_client = test_client(self.Fault, self) # map an access helper class for i in self.attr_list(): - i.set_comm_client(self.example_client) + i.set_comm_client(self.test_client) - self.example_client.start() + self.test_client.start() # ---------- -- GitLab