diff --git a/jupyter-notebooks/.ipynb_checkpoints/test_device-checkpoint.ipynb b/jupyter-notebooks/.ipynb_checkpoints/test_device-checkpoint.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..16749ce8b9e2f50e6cae56615790b9e5f19211ef --- /dev/null +++ b/jupyter-notebooks/.ipynb_checkpoints/test_device-checkpoint.ipynb @@ -0,0 +1,163 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "id": "waiting-chance", + "metadata": {}, + "outputs": [], + "source": [ + "import time\n", + "import numpy" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "moving-alexandria", + "metadata": {}, + "outputs": [ + { + "ename": "DevFailed", + "evalue": "DevFailed[\nDevError[\n desc = device lts/xst/1 not defined in the database !\n origin = DataBase::ImportDevice()\n reason = DB_DeviceNotDefined\nseverity = ERR]\n\nDevError[\n desc = Failed to execute command_inout on device sys/database/2, command DbImportDevice\n origin = Connection::command_inout()\n reason = API_CommandFailed\nseverity = ERR]\n\nDevError[\n desc = Can't connect to device lts/xst/1\n origin = DeviceProxy::DeviceProxy\n reason = API_DeviceNotDefined\nseverity = ERR]\n]", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mDevFailed\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/tmp/ipykernel_22/3496973635.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0md\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mDeviceProxy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"LTS/XST/1\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m/usr/local/lib/python3.7/dist-packages/tango/device_proxy.py\u001b[0m in \u001b[0;36m__DeviceProxy__init__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 205\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_executors\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mGreenMode\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGevent\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpop\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'threadpool'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 206\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_executors\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mGreenMode\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mAsyncio\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpop\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'asyncio_executor'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 207\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mDeviceProxy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__init_orig__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 208\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 209\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mDevFailed\u001b[0m: DevFailed[\nDevError[\n desc = device lts/xst/1 not defined in the database !\n origin = DataBase::ImportDevice()\n reason = DB_DeviceNotDefined\nseverity = ERR]\n\nDevError[\n desc = Failed to execute command_inout on device sys/database/2, command DbImportDevice\n origin = Connection::command_inout()\n reason = API_CommandFailed\nseverity = ERR]\n\nDevError[\n desc = Can't connect to device lts/xst/1\n origin = DeviceProxy::DeviceProxy\n reason = API_DeviceNotDefined\nseverity = ERR]\n]" + ] + } + ], + "source": [ + "d=DeviceProxy(\"LTS/XST/1\")" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "ranking-aluminum", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'd' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/tmp/ipykernel_22/3213548382.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mstate\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0md\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mstate\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"OFF\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0md\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minitialise\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mNameError\u001b[0m: name 'd' is not defined" + ] + } + ], + "source": [ + "state = str(d.state())\n", + "\n", + "if state == \"OFF\":\n", + " d.initialise()\n", + " time.sleep(1)\n", + "state = str(d.state())\n", + "if state == \"STANDBY\":\n", + " d.on()\n", + "state = str(d.state())\n", + "if state == \"ON\":\n", + " print(\"Device is now in on state\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "id": "beneficial-evidence", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "packet_count_R [55]\n", + "last_packet_timestamp_R [1623249385]\n", + "queue_percentage_used_R [0.]\n", + "State <function __get_command_func.<locals>.f at 0x7fcb205fd0d0>\n", + "Status <function __get_command_func.<locals>.f at 0x7fcb205fd0d0>\n" + ] + } + ], + "source": [ + "attr_names = d.get_attribute_list()\n", + "\n", + "for i in attr_names:\n", + " exec(\"value = print(i, d.{})\".format(i))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "sporting-current", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.0" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "d.RCU_mask_RW = [False, False, False, False, False, False, False, False, False, False, False, False,\n", + " False, False, False, False, False, False, False, False, False, False, False, False,\n", + " False, False, False, False, False, False, False, False,]\n", + "time.sleep(1)\n", + "print(d.RCU_mask_RW)\n", + "\n", + "monitor_rate = d.RCU_monitor_rate_RW\n", + "print(\"current monitoring rate: {}, setting to {}\".format(monitor_rate, monitor_rate + 1))\n", + "monitor_rate = monitor_rate + 1\n", + "\n", + "time.sleep(1)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "sharing-mechanics", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ruled-tracy", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "StationControl", + "language": "python", + "name": "stationcontrol" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/jupyter-notebooks/test_device.ipynb b/jupyter-notebooks/test_device.ipynb index 13942fd93928b06510c6650200b4d1a48034807a..3a718f2cc744d99d9cc7c96e295aaf30b3a371ca 100644 --- a/jupyter-notebooks/test_device.ipynb +++ b/jupyter-notebooks/test_device.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 61, + "execution_count": 15, "id": "waiting-chance", "metadata": {}, "outputs": [], @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 16, "id": "moving-alexandria", "metadata": {}, "outputs": [], @@ -23,7 +23,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 17, "id": "ranking-aluminum", "metadata": {}, "outputs": [ @@ -46,12 +46,14 @@ " d.on()\n", "state = str(d.state())\n", "if state == \"ON\":\n", - " print(\"Device is now in on state\")\n" + " print(\"Device is now in on state\")\n", + "else:\n", + " print(f\"Device is now in {state} state\")" ] }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 18, "id": "beneficial-evidence", "metadata": {}, "outputs": [ @@ -59,64 +61,107 @@ "name": "stdout", "output_type": "stream", "text": [ - "packet_count_R [55]\n", - "last_packet_timestamp_R [1623249385]\n", - "queue_percentage_used_R [0.]\n", - "State <function __get_command_func.<locals>.f at 0x7fcb205fd0d0>\n", - "Status <function __get_command_func.<locals>.f at 0x7fcb205fd0d0>\n" + "['version_R', 'opcua_missing_attributes_R', 'UNB2TR_translator_busy_R', 'UNB2_DC_DC_48V_12V_IOUT_R', 'UNB2_DC_DC_48V_12V_TEMP_R', 'UNB2_DC_DC_48V_12V_VIN_R', 'UNB2_DC_DC_48V_12V_VOUT_R', 'UNB2_EEPROM_Serial_Number_R', 'UNB2_EEPROM_Unique_ID_R', 'UNB2_FPGA_DDR4_SLOT_TEMP_R', 'UNB2_FPGA_POL_CORE_IOUT_R', 'UNB2_FPGA_POL_CORE_TEMP_R', 'UNB2_FPGA_POL_CORE_VOUT_R', 'UNB2_FPGA_POL_ERAM_IOUT_R', 'UNB2_FPGA_POL_ERAM_TEMP_R', 'UNB2_FPGA_POL_ERAM_VOUT_R', 'UNB2_FPGA_POL_HGXB_IOUT_R', 'UNB2_FPGA_POL_HGXB_TEMP_R', 'UNB2_FPGA_POL_HGXB_VOUT_R', 'UNB2_FPGA_POL_PGM_IOUT_R', 'UNB2_FPGA_POL_PGM_TEMP_R', 'UNB2_FPGA_POL_PGM_VOUT_R', 'UNB2_FPGA_POL_RXGXB_IOUT_R', 'UNB2_FPGA_POL_RXGXB_TEMP_R', 'UNB2_FPGA_POL_RXGXB_VOUT_R', 'UNB2_FPGA_POL_TXGXB_IOUT_R', 'UNB2_FPGA_POL_TXGXB_TEMP_R', 'UNB2_FPGA_POL_TXGXB_VOUT_R', 'UNB2_FPGA_QSFP_CAGE_LOS_R', 'UNB2_FPGA_QSFP_CAGE_TEMP_R', 'UNB2_Front_Panel_LED_R', 'UNB2_Front_Panel_LED_RW', 'UNB2_I2C_bus_DDR4_error_R', 'UNB2_I2C_bus_error_R', 'UNB2_I2C_bus_FPGA_PS_error_R', 'UNB2_I2C_bus_PS_error_R', 'UNB2_I2C_bus_QSFP_error_R', 'UNB2_mask_RW', 'UNB2_POL_CLOCK_IOUT_R', 'UNB2_POL_CLOCK_TEMP_R', 'UNB2_POL_CLOCK_VOUT_R', 'UNB2_POL_QSFP_N01_IOUT_R', 'UNB2_POL_QSFP_N01_TEMP_R', 'UNB2_POL_QSFP_N01_VOUT_R', 'UNB2_POL_QSFP_N23_IOUT_R', 'UNB2_POL_QSFP_N23_TEMP_R', 'UNB2_POL_QSFP_N23_VOUT_R', 'UNB2_POL_SWITCH_1V2_IOUT_R', 'UNB2_POL_SWITCH_1V2_TEMP_R', 'UNB2_POL_SWITCH_1V2_VOUT_R', 'UNB2_POL_SWITCH_PHY_IOUT_R', 'UNB2_POL_SWITCH_PHY_TEMP_R', 'UNB2_POL_SWITCH_PHY_VOUT_R', 'UNB2_PWR_off_R', 'UNB2_PWR_off_RW', 'State', 'Status']\n", + "\r\n", + "Attributes:\n", + ">>>\t version_R\n", + ">>>\t opcua_missing_attributes_R\n", + ">>>\t UNB2TR_translator_busy_R\n", + ">>>\t UNB2_DC_DC_48V_12V_IOUT_R\n", + ">>>\t UNB2_DC_DC_48V_12V_TEMP_R\n", + ">>>\t UNB2_DC_DC_48V_12V_VIN_R\n", + ">>>\t UNB2_DC_DC_48V_12V_VOUT_R\n", + ">>>\t UNB2_EEPROM_Serial_Number_R\n", + ">>>\t UNB2_EEPROM_Unique_ID_R\n", + ">>>\t UNB2_FPGA_DDR4_SLOT_TEMP_R\n", + ">>>\t UNB2_FPGA_POL_CORE_IOUT_R\n", + ">>>\t UNB2_FPGA_POL_CORE_TEMP_R\n", + ">>>\t UNB2_FPGA_POL_CORE_VOUT_R\n", + ">>>\t UNB2_FPGA_POL_ERAM_IOUT_R\n", + ">>>\t UNB2_FPGA_POL_ERAM_TEMP_R\n", + ">>>\t UNB2_FPGA_POL_ERAM_VOUT_R\n", + ">>>\t UNB2_FPGA_POL_HGXB_IOUT_R\n", + ">>>\t UNB2_FPGA_POL_HGXB_TEMP_R\n", + ">>>\t UNB2_FPGA_POL_HGXB_VOUT_R\n", + ">>>\t UNB2_FPGA_POL_PGM_IOUT_R\n", + ">>>\t UNB2_FPGA_POL_PGM_TEMP_R\n", + ">>>\t UNB2_FPGA_POL_PGM_VOUT_R\n", + ">>>\t UNB2_FPGA_POL_RXGXB_IOUT_R\n", + ">>>\t UNB2_FPGA_POL_RXGXB_TEMP_R\n", + ">>>\t UNB2_FPGA_POL_RXGXB_VOUT_R\n", + ">>>\t UNB2_FPGA_POL_TXGXB_IOUT_R\n", + ">>>\t UNB2_FPGA_POL_TXGXB_TEMP_R\n", + ">>>\t UNB2_FPGA_POL_TXGXB_VOUT_R\n", + ">>>\t UNB2_FPGA_QSFP_CAGE_LOS_R\n", + ">>>\t UNB2_FPGA_QSFP_CAGE_TEMP_R\n", + ">>>\t UNB2_Front_Panel_LED_R\n", + ">>>\t UNB2_Front_Panel_LED_RW\n", + ">>>\t UNB2_I2C_bus_DDR4_error_R\n", + ">>>\t UNB2_I2C_bus_error_R\n", + ">>>\t UNB2_I2C_bus_FPGA_PS_error_R\n", + ">>>\t UNB2_I2C_bus_PS_error_R\n", + ">>>\t UNB2_I2C_bus_QSFP_error_R\n", + ">>>\t UNB2_mask_RW\n", + ">>>\t UNB2_POL_CLOCK_IOUT_R\n", + ">>>\t UNB2_POL_CLOCK_TEMP_R\n", + ">>>\t UNB2_POL_CLOCK_VOUT_R\n", + ">>>\t UNB2_POL_QSFP_N01_IOUT_R\n", + ">>>\t UNB2_POL_QSFP_N01_TEMP_R\n", + ">>>\t UNB2_POL_QSFP_N01_VOUT_R\n", + ">>>\t UNB2_POL_QSFP_N23_IOUT_R\n", + ">>>\t UNB2_POL_QSFP_N23_TEMP_R\n", + ">>>\t UNB2_POL_QSFP_N23_VOUT_R\n", + ">>>\t UNB2_POL_SWITCH_1V2_IOUT_R\n", + ">>>\t UNB2_POL_SWITCH_1V2_TEMP_R\n", + ">>>\t UNB2_POL_SWITCH_1V2_VOUT_R\n", + ">>>\t UNB2_POL_SWITCH_PHY_IOUT_R\n", + ">>>\t UNB2_POL_SWITCH_PHY_TEMP_R\n", + ">>>\t UNB2_POL_SWITCH_PHY_VOUT_R\n", + ">>>\t UNB2_PWR_off_R\n", + ">>>\t UNB2_PWR_off_RW\n", + ">>>\t State\n", + ">>>\t Status\n", + "Missing Attributes: \n", + " ('2:UNB2TR_translator_busy_R', '2:UNB2_EEPROM_Serial_Number_R', '2:UNB2_I2C_bus_DDR4_error_R', '2:UNB2_I2C_bus_error_R', '2:UNB2_I2C_bus_FPGA_PS_error_R', '2:UNB2_I2C_bus_PS_error_R', '2:UNB2_I2C_bus_QSFP_error_R', '2:UNB2_PWR_off_R', '2:UNB2_PWR_off_RW')\n" ] } ], "source": [ "attr_names = d.get_attribute_list()\n", + "print(attr_names)\n", "\n", + "print(\"\\r\\nAttributes:\")\n", "for i in attr_names:\n", - " exec(\"value = print(i, d.{})\".format(i))\n" + " print(\">>>\\t\",i)\n", + " #exec(\"value = print(i, d.{})\".format(i))\n", + "print(\"Missing Attributes: \\n\", d.opcua_missing_attributes_R)" ] }, { "cell_type": "code", - "execution_count": 39, - "id": "sporting-current", + "execution_count": 20, + "id": "252e49de", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "3.0" + "array([0., 0.])" ] }, - "execution_count": 39, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "d.RCU_mask_RW = [False, False, False, False, False, False, False, False, False, False, False, False,\n", - " False, False, False, False, False, False, False, False, False, False, False, False,\n", - " False, False, False, False, False, False, False, False,]\n", - "time.sleep(1)\n", - "print(d.RCU_mask_RW)\n", - "\n", - "monitor_rate = d.RCU_monitor_rate_RW\n", - "print(\"current monitoring rate: {}, setting to {}\".format(monitor_rate, monitor_rate + 1))\n", - "monitor_rate = monitor_rate + 1\n", - "\n", - "time.sleep(1)\n" + "d.UNB2_POL_QSFP_N23_TEMP_R" ] }, { "cell_type": "code", "execution_count": null, - "id": "sharing-mechanics", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ruled-tracy", + "id": "d348a3c6", "metadata": {}, "outputs": [], "source": [] diff --git a/tangostationcontrol/tangostationcontrol/clients/attribute_wrapper.py b/tangostationcontrol/tangostationcontrol/clients/attribute_wrapper.py index f9cc13b3bfa8738414fa265c5a2154c0c471a493..718ea431d6d24962ad7f437e3941e7609f89927f 100644 --- a/tangostationcontrol/tangostationcontrol/clients/attribute_wrapper.py +++ b/tangostationcontrol/tangostationcontrol/clients/attribute_wrapper.py @@ -154,7 +154,7 @@ class attribute_wrapper(attribute): try: self.read_function, self.write_function = client.setup_attribute(self.comms_annotation, self) except Exception as e: - raise Exception(f"Exception while setting {client.__class__.__name__} attribute with annotation: {self.comms_annotation}") from e + raise Exception(f"Exception while setting {client.__class__.__name__} attribute with annotation: '{self.comms_annotation}'") from e async def async_set_comm_client(self, client): """ @@ -163,7 +163,8 @@ class attribute_wrapper(attribute): try: self.read_function, self.write_function = await client.setup_attribute(self.comms_annotation, self) except Exception as e: - raise Exception(f"Exception while setting {client.__class__.__name__} attribute with annotation: {self.comms_annotation}") from e + raise Exception(f"Exception while setting {client.__class__.__name__} attribute with annotation: '{self.comms_annotation}'") from e + def set_pass_func(self): def pass_func(value=None): diff --git a/tangostationcontrol/tangostationcontrol/clients/comms_client.py b/tangostationcontrol/tangostationcontrol/clients/comms_client.py index 31dfc99ce4092d8f1025bfe3b10fc8a9c561ebe8..2c28d2c70214935d32ffdcb21386ba841e7e5668 100644 --- a/tangostationcontrol/tangostationcontrol/clients/comms_client.py +++ b/tangostationcontrol/tangostationcontrol/clients/comms_client.py @@ -48,13 +48,12 @@ class CommClient(AbstractCommClient, Thread): primitives. """ - def __init__(self, fault_func, streams, try_interval=2): + def __init__(self, fault_func, try_interval=2): """ """ self.fault_func = fault_func self.try_interval = try_interval - self.streams = streams self.stopping = False self.connected = False @@ -83,7 +82,7 @@ class CommClient(AbstractCommClient, Thread): try: self.connect() except Exception as e: - self.streams.error_stream("Fault condition in communication detected.", e) + logger.exception("Fault condition in communication detected.") self.fault_func() return @@ -93,7 +92,7 @@ class CommClient(AbstractCommClient, Thread): self.ping() time.sleep(self.try_interval) except Exception as e: - self.streams.error_stream("Fault condition in communication detected.", e) + logger.exception("Fault condition in communication detected.") # technically, we may not have dropped the connection, but encounter a different error. so explicitly disconnect. self.disconnect() @@ -266,3 +265,4 @@ class AsyncCommClient(object): future = asyncio.run_coroutine_threadsafe(self.stop(), self.event_loop) return future.result() + diff --git a/tangostationcontrol/tangostationcontrol/clients/opcua_client.py b/tangostationcontrol/tangostationcontrol/clients/opcua_client.py index 55e9fa0e695f3414d0b7da0005611c7436f59ca6..ce4447de3b9c8339bd36cc1e75a04ec6867b04de 100644 --- a/tangostationcontrol/tangostationcontrol/clients/opcua_client.py +++ b/tangostationcontrol/tangostationcontrol/clients/opcua_client.py @@ -152,7 +152,7 @@ class OPCUAConnection(AsyncCommClient): try: # NOTE: debug statement tries to get the qualified name, this may not always work. in that case forgo the name and just print the path node_name = str(node.get_browse_name())[len("QualifiedName(2:"):] - self.streams.debug_stream("connected OPC ua node {} of type {} to attribute with dimensions: {} x {} ".format(str(node_name)[:len(node_name)-1], str(ua_type)[len("VariantType."):], dim_x, dim_y)) + logger.debug("connected OPC ua node {} of type {} to attribute with dimensions: {} x {} ".format(str(node_name)[:len(node_name)-1], str(ua_type)[len("VariantType."):], dim_x, dim_y)) except: pass diff --git a/tangostationcontrol/tangostationcontrol/devices/boot.py b/tangostationcontrol/tangostationcontrol/devices/boot.py index b0f4295433053c2d6f0c1d095c0690fb085a3221..355a8c944361feaee09b70196450a5401c598565 100644 --- a/tangostationcontrol/tangostationcontrol/devices/boot.py +++ b/tangostationcontrol/tangostationcontrol/devices/boot.py @@ -235,10 +235,10 @@ class Boot(lofar_device): 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...") + logger.debug("Shutting down...") self.Off() - self.debug_stream("Shut down. Good bye.") + logger.debug("Shut down. Good bye.") # -------- # overloaded functions @@ -249,7 +249,7 @@ class Boot(lofar_device): try: self.initialiser.stop() except Exception as e: - self.warn_stream("Exception while stopping OPC ua connection in configure_for_off function: {}. Exception ignored".format(e)) + logger.warning("Exception while stopping OPC ua connection in configure_for_off function: {}. Exception ignored".format(e)) @log_exceptions() def configure_for_initialise(self): diff --git a/tangostationcontrol/tangostationcontrol/devices/device_decorators.py b/tangostationcontrol/tangostationcontrol/devices/device_decorators.py index c4f333eb6e9dff5d2e5cf6f0b52129b2915e0cac..b3f203bfff1fec77efbc0b2d95d8c464a97dcb71 100644 --- a/tangostationcontrol/tangostationcontrol/devices/device_decorators.py +++ b/tangostationcontrol/tangostationcontrol/devices/device_decorators.py @@ -2,6 +2,9 @@ from tango import DevState, Except from functools import wraps import traceback +import logging +logger = logging.getLogger() + __all__ = ["only_in_states", "only_when_on", "fault_on_error"] def only_in_states(allowed_states): @@ -15,7 +18,7 @@ def only_in_states(allowed_states): if self.get_state() in allowed_states: return func(self, *args, **kwargs) - self.warn_stream("Illegal command: Function %s can only be called in states %s. Current state: %s" % (func.__name__, allowed_states, self.get_state())) + logger.warning("Illegal command: Function %s can only be called in states %s. Current state: %s" % (func.__name__, allowed_states, self.get_state())) Except.throw_exception("IllegalCommand", "Function can only be called in states %s. Current state: %s" % (allowed_states, self.get_state()), func.__name__) return state_check_wrapper @@ -50,8 +53,10 @@ def fault_on_error(): try: return func(self, *args, **kwargs) except Exception as e: - self.error_stream("Function failed. Trace: %s", traceback.format_exc()) + + logger.exception("Function failed.") self.Fault(f"FAULT in {func.__name__}: {e.__class__.__name__}: {e}") + return None return error_wrapper diff --git a/tangostationcontrol/tangostationcontrol/devices/docker_device.py b/tangostationcontrol/tangostationcontrol/devices/docker_device.py index b7193ecb1408e58394e84de1e317dbae5e569a5f..5ed02acdb942f2fb6ec33c3c433ac18687962bc8 100644 --- a/tangostationcontrol/tangostationcontrol/devices/docker_device.py +++ b/tangostationcontrol/tangostationcontrol/devices/docker_device.py @@ -28,6 +28,9 @@ from tangostationcontrol.clients.attribute_wrapper import attribute_wrapper from tangostationcontrol.devices.lofar_device import lofar_device from tangostationcontrol.common.lofar_logging import device_logging_to_python, log_exceptions +import logging +logger = logging.getLogger() + __all__ = ["Docker", "main"] @device_logging_to_python() @@ -98,7 +101,7 @@ class Docker(lofar_device): try: self.docker_client.sync_stop() except Exception as e: - self.warn_stream("Exception while stopping docker client in configure_for_off function: {}. Exception ignored".format(e)) + logger.warning("Exception while stopping docker client in configure_for_off function: {}. Exception ignored".format(e)) @log_exceptions() def configure_for_initialise(self): diff --git a/tangostationcontrol/tangostationcontrol/devices/lofar_device.py b/tangostationcontrol/tangostationcontrol/devices/lofar_device.py index 44005726ab168e90d00f858f03fac0f4a762367c..8886abd8a40b38df1fa9ec181783d9f4a2ff08ae 100644 --- a/tangostationcontrol/tangostationcontrol/devices/lofar_device.py +++ b/tangostationcontrol/tangostationcontrol/devices/lofar_device.py @@ -255,7 +255,7 @@ class lofar_device(Device, metaclass=AbstractDeviceMetas): default_value = getattr(self, f"{name}_default") # set the attribute to the configured default - self.debug_stream(f"Setting attribute {name} to {default_value}") + logger.debug(f"Setting attribute {name} to {default_value}") self.proxy.write_attribute(name, default_value) except Exception as e: # log which attribute we're addressing diff --git a/tangostationcontrol/tangostationcontrol/devices/observation.py b/tangostationcontrol/tangostationcontrol/devices/observation.py index 0c38ed93c76f0e03aa71de0a0d880d8ede6d8251..d43ecdf677d33ff942cdfb18d792b5b1a0609a22 100644 --- a/tangostationcontrol/tangostationcontrol/devices/observation.py +++ b/tangostationcontrol/tangostationcontrol/devices/observation.py @@ -18,6 +18,9 @@ from tangostationcontrol.devices.device_decorators import * from json import loads +import logging +logger = logging.getLogger() + __all__ = ["Observation", "main"] @device_logging_to_python() @@ -49,10 +52,10 @@ class Observation(Device): This method is called by the device destructor and by the device Init command (a Tango built-in). """ - self.debug_stream("Shutting down...") + logger.debug("Shutting down...") if self.get_state() != DevState.OFF: self.Off() - self.debug_stream("Shut down. Good bye.") + logger.debug("Shut down. Good bye.") # Lifecycle functions @command(dtype_in = DevString) @@ -70,21 +73,21 @@ class Observation(Device): self._observation_id = int(self.observation_parameters.get("id")) self._stop_time = float(self.observation_parameters.get("stop_time")) self.set_state(DevState.STANDBY) - self.info_stream("The observation with ID={} is configured. It will begin as soon as On() is called and it is supposed to stop at {}.".format(self._observation_id, self._stop_time)) + logger.info("The observation with ID={} is configured. It will begin as soon as On() is called and it is supposed to stop at {}.".format(self._observation_id, self._stop_time)) @command() @only_in_states([DevState.STANDBY]) @log_exceptions() def On(self): self.set_state(DevState.ON) - self.info_stream("Started the observation with ID={}.".format(self._observation_id)) + logger.info("Started the observation with ID={}.".format(self._observation_id)) @command() @log_exceptions() def Off(self): self.stop_polling(True) self.set_state(DevState.OFF) - self.info_stream("Stopped the observation with ID={}.".format(self._observation_id)) + logger.info("Stopped the observation with ID={}.".format(self._observation_id)) @only_when_on() @fault_on_error() diff --git a/tangostationcontrol/tangostationcontrol/devices/observation_control.py b/tangostationcontrol/tangostationcontrol/devices/observation_control.py index 0383b9ab7e0b69e54feddd40af2bdc6eb4da3bb0..2bdae2e850a2b33955fcadc9512e4e6241d0452c 100644 --- a/tangostationcontrol/tangostationcontrol/devices/observation_control.py +++ b/tangostationcontrol/tangostationcontrol/devices/observation_control.py @@ -20,6 +20,8 @@ from tangostationcontrol.common.lofar_version import get_version from tangostationcontrol.devices.device_decorators import * from tangostationcontrol.devices.observation import Observation +import logging +logger = logging.getLogger() __all__ = ["ObservationControl", "main"] @@ -151,7 +153,7 @@ class ObservationControl(Device): @log_exceptions() def read_running_observations_R(self): obs = [ key for key in self.running_observations ] - self.debug_stream("{}".format(obs)) + logger.debug("{}".format(obs)) return obs @log_exceptions() @@ -165,7 +167,7 @@ class ObservationControl(Device): """ if event.err: # Something is fishy with this event. - self.warn_stream("The Observation device {} sent an event but the event signals an error. It is advised to check the logs for any indication that something went wrong in that device. Event data={} ".format(event.device, event)) + logger.warning("The Observation device {} sent an event but the event signals an error. It is advised to check the logs for any indication that something went wrong in that device. Event data={} ".format(event.device, event)) return # Get the Observation ID from the sending device. @@ -175,7 +177,7 @@ class ObservationControl(Device): running_obs = self.running_observations.copy() if not running_obs: # No obs is running??? - self.warn_stream("Received an observation_running event for the observation with ID={}. According to the records in ObservationControl, this observation is not supposed to run. Please check previous logs, especially around the time an observation with this ID was started. Will continue and ignore this event.".format(obs_id)) + logger.warning("Received an observation_running event for the observation with ID={}. According to the records in ObservationControl, this observation is not supposed to run. Please check previous logs, especially around the time an observation with this ID was started. Will continue and ignore this event.".format(obs_id)) return if id in running_obs: @@ -206,7 +208,7 @@ class ObservationControl(Device): # Convert the input parameter to a dict. parameter_dict = loads(parameters) - self.debug_stream("incoming parameter_array = {}, parameter_dict = {}".format(parameters, parameter_dict)) + logger.debug("incoming parameter_array = {}, parameter_dict = {}".format(parameters, parameter_dict)) # Parameter check, do not execute an observation in case # the parameters are not sufficiently defined. @@ -238,10 +240,10 @@ class ObservationControl(Device): except DevFailed as ex: # It is OK if this fails. This likely means that the device did # never exist in the Tango DB. Still add a warning to the logs. - self.warn_stream("Something went wrong when it was attempted to remove the device {} from the Tango DB. You should better go and check the logs. Exception: {}".format(device_name, ex)) + logger.warning("Something went wrong when it was attempted to remove the device {} from the Tango DB. You should better go and check the logs. Exception: {}".format(device_name, ex)) pass else: - self.error_stream("Cannot delete a device from the Tango DB if the device's class name or the device name are not provided: class_name={}, device_name={}".format(class_name, device_name)) + logger.error("Cannot delete a device from the Tango DB if the device's class name or the device name are not provided: class_name={}, device_name={}".format(class_name, device_name)) def create_dynamic_device(self, class_name: str = None, device_name: str = None): """ @@ -254,7 +256,7 @@ class ObservationControl(Device): except DevFailed as ex: self.delete_dynamic_device(class_name, device_name) error_string = "Cannot start the device {} for the device class {}. Exception: {}".format(device_name, class_name, ex) - self.error_stream("{}, {}".format(error_string, ex)) + logger.exception(error_string) Except.re_throw_exception(ex, "DevFailed", error_string, __name__) # API @@ -281,7 +283,7 @@ class ObservationControl(Device): self.create_dynamic_device(class_name, device_name) except DevFailed as ex: error_string = "Cannot create the Observation device instance {} for ID={}. This means that the observation did not start.".format(device_name, obs_id) - self.error_stream(error_string) + logger.exception(error_string) Except.re_throw_exception(ex, "DevFailed", error_string, __name__) try: @@ -301,7 +303,7 @@ class ObservationControl(Device): # Remove the device again. self.delete_dynamic_device(class_name, device_name) error_string = "Cannot access the Observation device instance for observation ID={} with device class name={} and device instance name={}. This means that the observation likely did not start but certainly cannot be controlled and/or forcefully be stopped.".format(obs_id, class_name, device_name) - self.error_stream("{}, {}".format(error_string, ex)) + logger.exception(error_string) Except.re_throw_exception(ex, "DevFailed", error_string, __name__) try: @@ -331,11 +333,11 @@ class ObservationControl(Device): # Finally update the self.running_observation dict's entry of this # observation with the complete set of info. self.running_observations[obs_id] = observation - self.info_stream("Successfully started an observation with ID={}.".format(obs_id)) + logger.info("Successfully started an observation with ID={}.".format(obs_id)) except DevFailed as ex: self.delete_dynamic_device(class_name, device_name) error_string = "Cannot access the Observation device instance for observation ID={} with device class name={} and device instance name={}. This means that the observation cannot be controlled and/or forcefully be stopped.".format(obs_id, Observation.__name__, device_name) - self.error_stream("{}, {}".format(error_string, ex)) + logger.exception(error_string) Except.re_throw_exception(ex, "DevFailed", error_string, __name__) @command(dtype_in = numpy.int64) @@ -352,7 +354,7 @@ class ObservationControl(Device): error = "Cannot stop an observation with ID={}, because the observation is not running.".format(obs_id) Except.throw_exception("IllegalCommand", error, __name__) - self.info_stream("Stopping the observation with ID={}.".format(obs_id)) + logger.info("Stopping the observation with ID={}.".format(obs_id)) # Fetch the obs data and remove it from the dict of # currently running observations. observation = self.running_observations.pop(obs_id) @@ -362,7 +364,7 @@ class ObservationControl(Device): try: device_proxy.ping() except DevFailed: - self.warn_stream("The device for the Observation with ID={} has unexpectedly already disappeared. It is advised to check the logs up to 10s prior to this message to see what happened.".format(obs_id)) + logger.warning("The device for the Observation with ID={} has unexpectedly already disappeared. It is advised to check the logs up to 10s prior to this message to see what happened.".format(obs_id)) else: # Unsubscribe from the subscribed event. event_id = observation.pop("event_id") @@ -387,15 +389,15 @@ class ObservationControl(Device): remaining_wait_time = remaining_wait_time - sleep_time # Check if the observation object is really in OFF state. if stopped: - self.info_stream("Successfully stopped the observation with ID={}.".format(obs_id)) + logger.info("Successfully stopped the observation with ID={}.".format(obs_id)) else: - self.warn_stream("Could not shut down the Observation device (\"{}\") for observation ID={}. This means that there is a chance for a memory leak. Will continue anyway and forcefully delete the Observation object.".format(observation["device_name"], obs_id)) + logger.warning("Could not shut down the Observation device (\"{}\") for observation ID={}. This means that there is a chance for a memory leak. Will continue anyway and forcefully delete the Observation object.".format(observation["device_name"], obs_id)) # Finally remove the device object from the Tango DB. try: self.delete_dynamic_device(observation["class_name"], observation["device_name"]) except DevFailed: - self.warn_stream("Something went wrong when the device {} was removed from the Tango DB. There is nothing that can be done about this here at this moment but you should check the Tango DB yourself.".format(observation["device_name"])) + logger.warning("Something went wrong when the device {} was removed from the Tango DB. There is nothing that can be done about this here at this moment but you should check the Tango DB yourself.".format(observation["device_name"])) @command() @only_when_on() @@ -423,9 +425,9 @@ class ObservationControl(Device): observation = self.running_observations.get(obs_id) info = "An observation with ID={} is".format(obs_id) if observation is not None: - self.debug_stream("{} running.".format(info)) + logger.debug("{} running.".format(info)) return True - self.debug_stream("{} not running.".format(info)) + logger.debug("{} not running.".format(info)) return False @command(dtype_out = DevBoolean) diff --git a/tangostationcontrol/tangostationcontrol/devices/opcua_device.py b/tangostationcontrol/tangostationcontrol/devices/opcua_device.py index c88cedfb840ad434fa80d9435b36045e0070d334..9f846533533e5211cbb7a5aa5018b87364f08463 100644 --- a/tangostationcontrol/tangostationcontrol/devices/opcua_device.py +++ b/tangostationcontrol/tangostationcontrol/devices/opcua_device.py @@ -30,6 +30,9 @@ from tangostationcontrol.clients.opcua_client import OPCUAConnection from tangostationcontrol.devices.device_decorators import * from tangostationcontrol.devices.lofar_device import lofar_device +import logging +logger = logging.getLogger() + __all__ = ["opcua_device", "main"] class opcua_device(lofar_device): @@ -116,7 +119,7 @@ class opcua_device(lofar_device): i.set_pass_func() self.opcua_missing_attributes.append(",".join(self.opcua_connection.get_node_path(i.comms_annotation))) - self.warn_stream("error while setting the attribute {} read/write function. {}".format(i, e)) + logger.warning("error while setting the attribute {} read/write function. {}".format(i, e)) @log_exceptions() def configure_for_off(self): @@ -125,4 +128,4 @@ class opcua_device(lofar_device): # disconnect self.opcua_connection.sync_stop() except Exception as e: - self.warn_stream("Exception while stopping OPC ua connection in configure_for_off function: {}. Exception ignored".format(e)) + logger.warning("Exception while stopping OPC ua connection in configure_for_off function: {}. Exception ignored".format(e)) diff --git a/tangostationcontrol/tangostationcontrol/devices/sdp/statistics.py b/tangostationcontrol/tangostationcontrol/devices/sdp/statistics.py index aa56e71f047ebd8412deb77fa315dd6e2a7d8c16..4b03f2db7848cf37d1b2d8ccacfcf0ac81e928cc 100644 --- a/tangostationcontrol/tangostationcontrol/devices/sdp/statistics.py +++ b/tangostationcontrol/tangostationcontrol/devices/sdp/statistics.py @@ -135,7 +135,7 @@ class Statistics(opcua_device, metaclass=ABCMeta): except Exception as e: # use the pass function instead of setting read/write fails i.set_pass_func() - self.warn_stream("error while setting the sst attribute {} read/write function. {}. using pass function instead".format(i, e)) + logger.warning("error while setting the sst attribute {} read/write function. {}. using pass function instead".format(i, e)) await self.statistics_client.start() diff --git a/tangostationcontrol/tangostationcontrol/examples/HW_device_template.py b/tangostationcontrol/tangostationcontrol/examples/HW_device_template.py index abb08a06a6cdbfbef0215df1d37552ff12b11931..f7994ec1fea9892a3ae2ab44b57ff87a2b2f1958 100644 --- a/tangostationcontrol/tangostationcontrol/examples/HW_device_template.py +++ b/tangostationcontrol/tangostationcontrol/examples/HW_device_template.py @@ -15,6 +15,8 @@ from tango.server import run from tangostationcontrol.devices.lofar_device import lofar_device +import logging +logger = logging.getLogger() __all__ = ["HW_dev"] @@ -46,10 +48,10 @@ class HW_dev(lofar_device): 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...") + logger.debug("Shutting down...") self.Off() - self.debug_stream("Shut down. Good bye.") + logger.debug("Shut down. Good bye.") # -------- # overloaded functions diff --git a/tangostationcontrol/tangostationcontrol/examples/load_from_disk/ini_client.py b/tangostationcontrol/tangostationcontrol/examples/load_from_disk/ini_client.py index 82c57a685e105527625c7dd3c0acdb77e59e1c8c..e5fbf03711fe220cfa56fa9327cbede7168b4e86 100644 --- a/tangostationcontrol/tangostationcontrol/examples/load_from_disk/ini_client.py +++ b/tangostationcontrol/tangostationcontrol/examples/load_from_disk/ini_client.py @@ -2,6 +2,9 @@ from tangostationcontrol.clients.comms_client import CommClient import configparser import numpy +import logging +logger = logging.getLogger() + __all__ = ["ini_client"] @@ -39,14 +42,14 @@ class ini_client(CommClient): def start(self): super().start() - def __init__(self, filename, fault_func, streams, try_interval=2): + def __init__(self, filename, fault_func, try_interval=2): """ initialises the class and tries to connect to the client. """ self.config = configparser.ConfigParser() self.filename = filename - super().__init__(fault_func, streams, try_interval) + super().__init__(fault_func, try_interval) # Explicitly connect if not self.connect(): @@ -62,7 +65,7 @@ class ini_client(CommClient): def disconnect(self): self.connected = False # always force a reconnect, regardless of a successful disconnect - self.streams.debug_stream("disconnected from the 'client' ") + logger.debug("disconnected from the 'client' ") def _setup_annotation(self, annotation): """ @@ -81,7 +84,7 @@ class ini_client(CommClient): """ # as this is an example, just print the annotation - self.streams.debug_stream("annotation: {}".format(annotation)) + logger.debug("annotation: {}".format(annotation)) name = annotation.get('name') if name is None: ValueError("ini client requires a variable `name` in the annotation to set/get") diff --git a/tangostationcontrol/tangostationcontrol/examples/load_from_disk/ini_device.py b/tangostationcontrol/tangostationcontrol/examples/load_from_disk/ini_device.py index 6195ff8a51544173554da24f046945ff8c2e6917..032c9b01b2a5447111d6245ffcba1bd610b3b655 100644 --- a/tangostationcontrol/tangostationcontrol/examples/load_from_disk/ini_device.py +++ b/tangostationcontrol/tangostationcontrol/examples/load_from_disk/ini_device.py @@ -21,6 +21,10 @@ from tangostationcontrol.clients.attribute_wrapper import attribute_wrapper from tangostationcontrol.devices.lofar_device import lofar_device from tangostationcontrol.examples.load_from_disk.ini_client import * +import logging +logger = logging.getLogger() + + __all__ = ["ini_device"] @@ -110,7 +114,7 @@ class ini_device(lofar_device): # use the pass function instead of setting read/write fails i.set_pass_func() - self.warn_stream("error while setting the ini attribute {} read/write function. {}".format(i, e)) + logger.warning("error while setting the ini attribute {} read/write function. {}".format(i, e)) self.ini_client.start() diff --git a/tangostationcontrol/tangostationcontrol/examples/snmp/snmp.py b/tangostationcontrol/tangostationcontrol/examples/snmp/snmp.py index ddcba3910b1780b040737f153bb83894be59b72c..3c962da9911abf9a0b9cbb4d7ecd4ff19c6e95d5 100644 --- a/tangostationcontrol/tangostationcontrol/examples/snmp/snmp.py +++ b/tangostationcontrol/tangostationcontrol/examples/snmp/snmp.py @@ -23,6 +23,9 @@ from tangostationcontrol.devices.lofar_device import lofar_device import numpy +import logging +logger = logging.getLogger() + __all__ = ["SNMP", "main"] @@ -95,7 +98,7 @@ class SNMP(lofar_device): except Exception as e: # use the pass function instead of setting read/write fails i.set_pass_func() - self.warn_stream("error while setting the SNMP attribute {} read/write function. {}".format(i, e)) + logger.warning("error while setting the SNMP attribute {} read/write function. {}".format(i, e)) self.snmp_manager.start() diff --git a/tangostationcontrol/tangostationcontrol/examples/snmp/snmp_client.py b/tangostationcontrol/tangostationcontrol/examples/snmp/snmp_client.py index 00464f37d92800207fec524279126e494886d01a..7c18baa9a6954e03ab07eb85fe35b6e342867650 100644 --- a/tangostationcontrol/tangostationcontrol/examples/snmp/snmp_client.py +++ b/tangostationcontrol/tangostationcontrol/examples/snmp/snmp_client.py @@ -4,7 +4,9 @@ from tangostationcontrol.clients.comms_client import CommClient import snmp import numpy -import traceback +import logging + +logger = logging.getLogger() __all__ = ["SNMP_client"] @@ -38,11 +40,11 @@ class SNMP_client(CommClient): def start(self): super().start() - def __init__(self, community, host, timeout, fault_func, streams, try_interval=2): + def __init__(self, community, host, timeout, fault_func, try_interval=2): """ Create the SNMP and connect() to it """ - super().__init__(fault_func, streams, try_interval) + super().__init__(fault_func, try_interval) self.community = community self.host = host @@ -58,7 +60,7 @@ class SNMP_client(CommClient): """ Try to connect to the client """ - self.streams.debug_stream("Connecting to community: %s, host: %s", self.community, self.host) + logger.debug("Connecting to community: %s, host: %s", self.community, self.host) self.connected = True return True diff --git a/tangostationcontrol/tangostationcontrol/test/clients/test_attr_wrapper.py b/tangostationcontrol/tangostationcontrol/test/clients/test_attr_wrapper.py index 553f2d96d122b54d41dee6c04fdd421943a72950..24ba5f506023f4260a35958cba568936cb2ad76f 100644 --- a/tangostationcontrol/tangostationcontrol/test/clients/test_attr_wrapper.py +++ b/tangostationcontrol/tangostationcontrol/test/clients/test_attr_wrapper.py @@ -33,7 +33,7 @@ str_image_val = [['1','1'],['1','1'],['1','1']] def dev_init(device): device.set_state(DevState.INIT) - device.test_client = test_client(device.Fault, device) + device.test_client = test_client(device.Fault) for i in device.attr_list(): asyncio.run(i.async_set_comm_client(device.test_client)) device.test_client.start() diff --git a/tangostationcontrol/tangostationcontrol/test/clients/test_client.py b/tangostationcontrol/tangostationcontrol/test/clients/test_client.py index ee3e0faf62b780dfb83a252dcf99897690090a35..ea03e850d4021d0d4c40e82a60d4fd1f0a9d67ea 100644 --- a/tangostationcontrol/tangostationcontrol/test/clients/test_client.py +++ b/tangostationcontrol/tangostationcontrol/test/clients/test_client.py @@ -5,6 +5,8 @@ import numpy # Test imports from tangostationcontrol.clients.comms_client import CommClient +import logging +logger = logging.getLogger() class test_client(CommClient): """ @@ -15,11 +17,11 @@ class test_client(CommClient): def start(self): super().start() - def __init__(self, fault_func, streams, try_interval=2): + def __init__(self, fault_func, try_interval=2): """ initialises the class and tries to connect to the client. """ - super().__init__(fault_func, streams, try_interval) + super().__init__(fault_func, try_interval) # Explicitly connect self.connect() @@ -28,13 +30,13 @@ class test_client(CommClient): """ this function provides a location for the code neccecary to connect to the client """ - self.streams.debug_stream("the example client doesn't actually connect to anything silly") + logger.debug("the example client doesn't actually connect to anything silly") self.connected = True # set connected to true def disconnect(self): self.connected = False # always force a reconnect, regardless of a successful disconnect - self.streams.debug_stream("disconnected from the 'client' ") + logger.debug("disconnected from the 'client' ") def _setup_annotation(self, annotation): """ @@ -50,7 +52,7 @@ class test_client(CommClient): """ # as this is an example, just print the annotation - self.streams.debug_stream("annotation: {}".format(annotation)) + logger.debug("annotation: {}".format(annotation)) def _setup_value_conversion(self, attribute): """ @@ -75,16 +77,16 @@ class test_client(CommClient): self.value = numpy.zeros(dims, dtype) def read_function(): - self.streams.debug_stream("from read_function, reading {} array of type {}".format(dims, dtype)) + logger.debug("from read_function, reading {} array of type {}".format(dims, dtype)) return self.value def write_function(write_value): - self.streams.debug_stream("from write_function, writing {} array of type {}".format(dims, dtype)) + logger.debug("from write_function, writing {} array of type {}".format(dims, dtype)) self.value = write_value return - self.streams.debug_stream("created and bound example_client read/write functions to attribute_wrapper object") + logger.debug("created and bound example_client read/write functions to attribute_wrapper object") return read_function, write_function async def setup_attribute(self, annotation=None, attribute=None):