Skip to content
Snippets Groups Projects
Commit 72520dc8 authored by Taya Snijder's avatar Taya Snijder
Browse files

Merge branch 'L2SS-247_2021-07-06-Branched_from_master-attribute_testing' into 'master'

Resolve L2SS-247 "2021 07 06 branched from master attribute testing"

Closes L2SS-247

See merge request !78
parents 678355ed 784891c7
Branches
Tags
1 merge request!78Resolve L2SS-247 "2021 07 06 branched from master attribute testing"
from tango.server import attribute
from tango import AttrWriteType
import numpy
from devices.device_decorators import only_when_on, fault_on_error
......@@ -34,16 +33,17 @@ class attribute_wrapper(attribute):
self.comms_id = comms_id # store data that can be used to identify the comms interface to use. not used by the wrapper itself
self.comms_annotation = comms_annotation # store data that can be used by the comms interface. not used by the wrapper itself
self.numpy_type = datatype # tango changes our attribute to their representation (E.g numpy.int64 becomes "DevLong64")
self.init_value = init_value
is_scalar = dims == (1,)
# tango doesn't recognise numpy.str_, for consistencies sake we convert it here and hide this from the top level
# NOTE: discuss, idk if this is an important detail somewhere else
if datatype is numpy.str_:
if datatype is numpy.str_ or datatype is numpy.str:
datatype = str
self.numpy_type = datatype # tango changes our attribute to their representation (E.g numpy.int64 becomes "DevLong64")
# check if not scalar
if is_scalar:
# scalar, just set the single dimension.
......@@ -131,7 +131,15 @@ class attribute_wrapper(attribute):
else:
numpy_dims = dims
if self.dim_x == 1:
if self.numpy_type == str:
value = ''
else:
value = self.numpy_type(0)
else:
value = numpy.zeros(numpy_dims, dtype=self.numpy_type)
return value
def set_comm_client(self, client):
......
......@@ -22,8 +22,6 @@ numpy_to_OPCua_dict = {
numpy.float32: opcua.ua.VariantType.Float,
numpy.double: opcua.ua.VariantType.Double,
numpy.float64: opcua.ua.VariantType.Double,
numpy.str_: opcua.ua.VariantType.String,
numpy.str: opcua.ua.VariantType.String,
str: opcua.ua.VariantType.String
}
......@@ -95,7 +93,7 @@ class OPCUAConnection(CommClient):
print(i.get_browse_name())
for j in i.get_children():
try:
print(j.get_browse_name(), j.get_data_type_as_variant_type())
print(j.get_browse_name(), j.get_data_type_as_variant_type(), j.get_value())
except:
print(j.get_browse_name())
finally:
......
......@@ -20,12 +20,13 @@ from tango import DevState, DebugIt
from clients.attribute_wrapper import attribute_wrapper
from common.lofar_logging import log_exceptions
import logging
__all__ = ["hardware_device"]
from devices.device_decorators import only_in_states, fault_on_error
import logging
logger = logging.getLogger()
class AbstractDeviceMetas(DeviceMeta, ABCMeta):
......
......@@ -147,8 +147,7 @@ class PCC(hardware_device):
self.function_mapping["CLK_off"] = {}
# set up the OPC ua client
self.OPCua_client = OPCUAConnection("opc.tcp://{}:{}/".format(self.OPC_Server_Name, self.OPC_Server_Port), "http://lofar.eu",
self.OPC_Time_Out, self.Fault, self)
self.OPCua_client = OPCUAConnection("opc.tcp://{}:{}/".format(self.OPC_Server_Name, self.OPC_Server_Port), "http://lofar.eu", self.OPC_Time_Out, self.Fault, self)
# map an access helper class
for i in self.attr_list():
......
from clients.comms_client import CommClient
import snmp
......
This diff is collapsed.
from clients.comms_client import CommClient
# External imports
import numpy
import os
# <class 'numpy.bool_'>
# Test imports
from clients.comms_client import CommClient
class test_client(CommClient):
"""
......@@ -75,15 +76,16 @@ class test_client(CommClient):
takes all gathered data to configure and return the correct read and write functions
"""
value = numpy.zeros(dims, dtype)
self.value = numpy.zeros(dims, dtype)
def read_function():
self.streams.debug_stream("from read_function, reading {} array of type {}".format(dims, dtype))
return value
return self.value
def write_function(write_value):
self.streams.debug_stream("from write_function, writing {} array of type {}".format(dims, dtype))
value = write_value
self.value = write_value
return
self.streams.debug_stream("created and bound example_client read/write functions to attribute_wrapper object")
return read_function, write_function
......
# -*- 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.
""" test Device Server
"""
# TODO(Corne): Remove sys.path.append hack once packaging is in place!
import os, sys
currentdir = os.path.dirname(os.path.realpath(__file__))
parentdir = os.path.dirname(currentdir)
parentdir = os.path.dirname(parentdir)
sys.path.append(parentdir)
# PyTango imports
from tango.server import run
from tango.server import device_property
from tango import DevState
# Additional import
from test.clients.test_client import test_client
from clients.attribute_wrapper import *
from devices.hardware_device import *
__all__ = ["test_device", "main"]
class test_device(hardware_device):
# -----------------
# Device Properties
# -----------------
OPC_Server_Name = device_property(
dtype='DevString',
)
OPC_Server_Port = device_property(
dtype='DevULong',
)
OPC_Time_Out = device_property(
dtype='DevDouble',
)
# ----------
# Attributes
# ----------
bool_scalar_R = attribute_wrapper(comms_annotation="numpy.bool_ type read scalar", datatype=numpy.bool_)
bool_scalar_RW = attribute_wrapper(comms_annotation="numpy.bool_ type read/write scalar", datatype=numpy.bool_, access=AttrWriteType.READ_WRITE)
int32_spectrum_R = attribute_wrapper(comms_annotation="numpy.int32 type read spectrum (len = 8)", datatype=numpy.int32, dims=(8,))
int32_spectrum_RW = attribute_wrapper(comms_annotation="numpy.int32 type read spectrum (len = 8)", datatype=numpy.int32, dims=(8,),
access=AttrWriteType.READ_WRITE)
double_image_R = attribute_wrapper(comms_annotation="numpy.double type read image (dims = 2x8)", datatype=numpy.double, dims=(2, 8))
double_image_RW = attribute_wrapper(comms_annotation="numpy.double type read/write image (dims = 8x2)", datatype=numpy.double, dims=(8, 2),
access=AttrWriteType.READ_WRITE)
int32_scalar_R = attribute_wrapper(comms_annotation="numpy.int32 type read scalar", datatype=numpy.int32)
uint16_spectrum_RW = attribute_wrapper(comms_annotation="numpy.uint16 type read/write spectrum (len = 8)", datatype=numpy.uint16, dims=(8,),
access=AttrWriteType.READ_WRITE)
float32_image_R = attribute_wrapper(comms_annotation="numpy.float32 type read image (dims = 8x2)", datatype=numpy.float32, dims=(8, 2))
uint8_image_RW = attribute_wrapper(comms_annotation="numpy.uint8 type read/write image (dims = 2x8)", datatype=numpy.uint8, dims=(2, 8),
access=AttrWriteType.READ_WRITE)
# --------
# overloaded functions
# --------
def configure_for_initialise(self):
""" user code here. is called when the sate is set to INIT """
"""Initialises the attributes and properties of the PCC."""
self.set_state(DevState.INIT)
# set up the test client
self.test_client = test_client(self.Fault, self)
# map an access helper class
for i in self.attr_list():
i.set_comm_client(self.test_client)
self.test_client.start()
# ----------
# Run server
# ----------
def main(args=None, **kwargs):
"""Main function of the example module."""
return run((test_device,), args=args, **kwargs)
if __name__ == '__main__':
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment