diff --git a/devices/SNMP.py b/devices/SNMP.py index 05e2e1a1709761450a980676928c091b868e71ca..8b5d4a21c85cebbc562bd22baf5afec5e37b86d9 100644 --- a/devices/SNMP.py +++ b/devices/SNMP.py @@ -79,23 +79,6 @@ class SNMP(hardware_device): if_index_R = attribute_wrapper(comms_annotation={"oids": "1.3.6.1.2.1.2.2.1.1"}, dims=(10,), datatype=numpy.int64) - - def always_executed_hook(self): - """Method always executed before any TANGO command is executed.""" - pass - - def delete_device(self): - """Hook to delete resources allocated in init_device. - - This method allows for any memory or other resources allocated in the - init_device method to be released. This method is called by the device - destructor and by the device Init command (a Tango built-in). - """ - self.debug_stream("Shutting down...") - - self.Off() - self.debug_stream("Shut down. Good bye.") - # -------- # overloaded functions # -------- diff --git a/devices/clients/SNMP_client.py b/devices/clients/SNMP_client.py index 9410004274727309f7df1c8d4177951e3e1e1a2e..158ce17dfdbe478d9a417d6026fc0d32e3971370 100644 --- a/devices/clients/SNMP_client.py +++ b/devices/clients/SNMP_client.py @@ -80,17 +80,13 @@ class SNMP_client(CommClient): if isinstance(annotation, dict): # check if required path inarg is present if annotation.get('oids') is None: - AssertionError("SNMP get attributes require an oid") + ValueError("SNMP get attributes require an oid") oids = annotation.get("oids") # required else: TypeError("SNMP attributes require a dict with oid(s)") return - if annotation.get('type') is not None: - dtype = annotation.get("type") # required - # actual_type = snmp_types[dtype] - else: - dtype = None + dtype = annotation.get('type', None) return oids, dtype @@ -128,12 +124,9 @@ class SNMP_client(CommClient): # already is an array but the wrong length. Unable to handle this raise ValueError("SNMP oids need to either be a single value or an array the size of the attribute dimensions. got: {} expected: {}x{}={}".format(len(in_oid),x,y,x*y)) else: - out_oids = [] - for i in range(nof_oids): - out_oids.append(in_oid + ".{}".format(i+1)) + return ["{}.{}".format(in_oid, i + 1) for i in range(nof_oids)] - return out_oids def setup_attribute(self, annotation, attribute): """ @@ -166,14 +159,15 @@ class SNMP_client(CommClient): value = [value] else: for i in range(len(oids)): - self.manager.set(self.host, oids[i], snmp_types[dtype](value[i])) + self.manager.set(self.host, oids[i], value[i]) + else: def _write_function(value): if len(oids) == 1 and type(value) != list: value = [value] else: for i in range(len(oids)): - self.manager.set(self.host, oids[i], value[i]) + self.manager.set(self.host, oids[i], snmp_types[dtype](value[i])) # return the read/write functions return _read_function, _write_function diff --git a/devices/example_device.py b/devices/example_device.py deleted file mode 100644 index 872877c2ff8abd562bfb2f62290fc9b6cd19c981..0000000000000000000000000000000000000000 --- a/devices/example_device.py +++ /dev/null @@ -1,124 +0,0 @@ -# -*- coding: utf-8 -*- -# -# This file is part of the PCC project -# -# -# -# Distributed under the terms of the APACHE license. -# See LICENSE.txt for more info. - -""" PCC Device Server for LOFAR2.0 - -""" - -# PyTango imports -from tango.server import run -from tango.server import device_property -# Additional import - -from clients.SNMP_client import SNMP_client -from src.attribute_wrapper import * -from src.hardware_device import * - -__all__ = ["example_device", "main"] - - -class example_device(hardware_device): - """ - - **Properties:** - - - Device Property - SNMP_community - - Type:'DevString' - SNMP_host - - Type:'DevULong' - SNMP_timeout - - Type:'DevDouble' - """ - - # ----------------- - # Device Properties - # ----------------- - - # SNMP_community = device_property( - # dtype='DevString', - # mandatory=True - # ) - # - # SNMP_host = device_property( - # dtype='DevString', - # mandatory=True - # ) - # - # SNMP_timeout = device_property( - # dtype='DevDouble', - # mandatory=True - # ) - SNMP_community = b"public" - SNMP_host = "127.0.0.1" - SNMP_timeout = 5.0 - - # ---------- - # Attributes - # ---------- - - # simple scalar - description - attr1 = attribute_wrapper(comms_annotation={"oids": "1.3.6.1.2.1.1.1.0"}, datatype=numpy.str_, access=AttrWriteType.READ_WRITE) - # simple scalar uptime - attr2 = attribute_wrapper(comms_annotation={"oids": "1.3.6.1.2.1.1.3.0"}, datatype=numpy.int64, access=AttrWriteType.READ_WRITE) - # simple scalar with name - attr3 = attribute_wrapper(comms_annotation={"oids": "1.3.6.1.2.1.1.5.0"}, datatype=numpy.str_, access=AttrWriteType.READ_WRITE) - - #spectrum with all elements - attr4 = attribute_wrapper(comms_annotation={"oids": ["1.3.6.1.2.1.2.2.1.1.1", "1.3.6.1.2.1.2.2.1.1.2", "1.3.6.1.2.1.2.2.1.1.3"]}, dims=(3,), datatype=numpy.int64) - #inferred spectrum - attr5 = attribute_wrapper(comms_annotation={"oids": ".1.3.6.1.2.1.2.2.1.1"}, dims=(3,), datatype=numpy.int64) - - - def always_executed_hook(self): - """Method always executed before any TANGO command is executed.""" - pass - - def delete_device(self): - """Hook to delete resources allocated in init_device. - - This method allows for any memory or other resources allocated in the - init_device method to be released. This method is called by the device - destructor and by the device Init command (a Tango built-in). - """ - self.debug_stream("Shutting down...") - - self.Off() - self.debug_stream("Shut down. Good bye.") - - # -------- - # overloaded functions - # -------- - def initialise(self): - """ user code here. is called when the state is set to STANDBY """ - - # set up the SNMP ua client - self.snmp_manager = SNMP_client(self.SNMP_community, self.SNMP_host, self.SNMP_timeout, self.Fault, self) - - # map the attributes to the OPC ua comm client - for i in self.attr_list(): - i.set_comm_client(self.snmp_manager) - - self.snmp_manager.start() - -# -------- -# Commands -# -------- - - -# ---------- -# Run server -# ---------- -def main(args=None, **kwargs): - """Main function of the PCC module.""" - return run((example_device,), args=args, **kwargs) - - -if __name__ == '__main__': - main()