From 4537feee8dae955cc9acc6e86924d1e2ee84efc6 Mon Sep 17 00:00:00 2001 From: ximenes Date: Tue, 23 Apr 2024 13:47:39 -0300 Subject: [PATCH] Add Wfm PVs --- siriuspy/siriuspy/pwrsupply/csdev.py | 20 ++ .../siriuspy/pwrsupply/psctrl/pscontroller.py | 23 ++ .../siriuspy/pwrsupply/psctrl/pscwriters.py | 28 +- siriuspy/siriuspy/pwrsupply/psctrl/psmodel.py | 17 + .../pwrsupply/tests/fbp-example.ipynb | 309 ++++++++++++++++-- siriuspy/siriuspy/pwrsupply/tests/utils.py | 14 +- siriuspy/tests/pwrsupply/test_csdev.py | 1 + siriuspy/tests/pwrsupply/variables.py | 1 + 8 files changed, 371 insertions(+), 42 deletions(-) diff --git a/siriuspy/siriuspy/pwrsupply/csdev.py b/siriuspy/siriuspy/pwrsupply/csdev.py index 1f6cebd5e..4d58772bd 100644 --- a/siriuspy/siriuspy/pwrsupply/csdev.py +++ b/siriuspy/siriuspy/pwrsupply/csdev.py @@ -21,6 +21,10 @@ MAX_WFMSIZE_OTHERS = 4096 DEF_WFMSIZE_OTHERS = 3920 DEFAULT_WFM_OTHERS = _np.zeros(DEF_WFMSIZE_OTHERS, dtype=float) +DEFAULT_WFM_SELECTED = 0 +DEFAULT_WFM_FREQUENCY = 2000.0 # [Hz] +DEFAULT_WFM_GAIN = 1.0 +DEFAULT_WFM_OFFSET = 0.0 # [A/V] DEFAULT_WFM = _np.zeros(DEF_WFMSIZE_OTHERS) @@ -1268,6 +1272,22 @@ def _get_ps_basic_propty_database(): 'value': DEFAULT_SIGGEN_CONFIG[5:9]}, 'CycleIndex-Mon': {'type': 'int', 'value': 0, 'unit': 'count'}, # Wfm - UDC + 'WfmSelected-SP': {'type': 'int', 'value': DEFAULT_WFM_SELECTED}, + 'WfmSelected-RB': {'type': 'int', 'value': DEFAULT_WFM_SELECTED}, + 'WfmSyncMode-Sel': { + 'type': 'enum', 'enums': _et.WFMREF_SYNCMODE, 'value': _ConstPSBSMP.E_WFMREFSYNC_ONESHOT}, + 'WfmSyncMode-Sts': { + 'type': 'enum', 'enums': _et.WFMREF_SYNCMODE, 'value': _ConstPSBSMP.E_WFMREFSYNC_ONESHOT}, + 'WfmFreq-SP': {'type': 'float', 'value': DEFAULT_WFM_FREQUENCY, 'unit': 'Hz'}, + 'WfmFreq-RB': {'type': 'float', 'value': DEFAULT_WFM_FREQUENCY, 'unit': 'Hz'}, + 'WfmGain-SP': {'type': 'float', 'value': DEFAULT_WFM_GAIN}, + 'WfmGain-RB': {'type': 'float', 'value': DEFAULT_WFM_GAIN}, + 'WfmOffset-SP': { + 'type': 'float', 'value': DEFAULT_WFM_OFFSET, + 'prec': PS_CURRENT_PRECISION, 'unit': 'A'}, + 'WfmOffset-RB': { + 'type': 'float', 'value': DEFAULT_WFM_OFFSET, + 'prec': PS_CURRENT_PRECISION, 'unit': 'A'}, 'Wfm-SP': {'type': 'float', 'count': len(DEFAULT_WFM), 'value': list(DEFAULT_WFM), 'unit': 'A', 'prec': PS_CURRENT_PRECISION}, diff --git a/siriuspy/siriuspy/pwrsupply/psctrl/pscontroller.py b/siriuspy/siriuspy/pwrsupply/psctrl/pscontroller.py index 15cdf18dc..22edbf1e8 100644 --- a/siriuspy/siriuspy/pwrsupply/psctrl/pscontroller.py +++ b/siriuspy/siriuspy/pwrsupply/psctrl/pscontroller.py @@ -176,6 +176,14 @@ class StandardPSController(PSController): 'CycleAuxParam-SP', # start index of auxparams ] + _WFM_PARMS = [ + 'WfmSelected-SP', + 'WfmSyncMode-SP', + 'WfmFreq-SP', + 'WfmGain-SP', + 'WfmOffset-SP', + ] + def write(self, devname, field, value): """Write value to pv.""" priority_pvs = dict() @@ -188,6 +196,8 @@ def write(self, devname, field, value): self._set_sofb_current(pvname, value, devname, field, priority_pvs) elif field in StandardPSController._SIGGEN_PARMS: self._set_siggen(pvname, value, devname, field, priority_pvs) + elif field in StandardPSController._WFM_PARMS: + self._set_wfm(pvname, value, devname, field, priority_pvs) else: self._writers[pvname].execute(value) @@ -210,6 +220,13 @@ def _set_siggen(self, pvname, value, devname, field, priority_pvs): values[idx] = value self._writers[pvname].execute(values) + def _set_wfm(self, pvname, value, devname, field, priority_pvs): + _ = priority_pvs + idx = StandardPSController._WFM_PARMS.index(field) + values = self._get_wfm_arg_values(devname) + values[idx] = value + self._writers[pvname].execute(values) + def _set_sofb_current(self, pvname, value, devname, field, priority_pvs): _ = field @@ -239,3 +256,9 @@ def _get_siggen_arg_values(self, devname): aux = StandardPSController._SIGGEN_PARMS[-1] args.extend(self._readers[devname + ':' + aux].read()) return args + + def _get_wfm_arg_values(self, devname): + """Get Wfm args.""" + args = [self._readers[devname + ':' + arg].read() + for arg in StandardPSController._WFM_PARMS] + return args diff --git a/siriuspy/siriuspy/pwrsupply/psctrl/pscwriters.py b/siriuspy/siriuspy/pwrsupply/psctrl/pscwriters.py index 8203b99ce..a236c71da 100644 --- a/siriuspy/siriuspy/pwrsupply/psctrl/pscwriters.py +++ b/siriuspy/siriuspy/pwrsupply/psctrl/pscwriters.py @@ -366,6 +366,24 @@ def execute(self, value=None): self._cfg.execute(value) +class CfgWfm(Function): + """Command to configure Wfm.""" + + def __init__(self, device_ids, pru_controller, idx, setpoints=None): + """Init.""" + self._idx = idx + self._setpoints = setpoints + self._cfg = BSMPFunction( + device_ids, pru_controller, _const_psbsmp.F_CFG_WFMREF) + + def execute(self, value=None): + """Execute command.""" + if not self._setpoints or \ + (self._setpoints and + self._setpoints.apply(value[self._idx])): + self._cfg.execute(value) + + class SOFBCurrent(Function): """.""" @@ -438,15 +456,9 @@ def __init__(self, epics_field, epics_database): self.field = epics_field self.value = epics_database['value'] self.database = epics_database - if '-Cmd' in epics_field: - self.is_cmd = True - else: - self.is_cmd = False + self.is_cmd = '-Cmd' in epics_field self.type = epics_database['type'] - if 'count' in epics_database: - self.count = epics_database['count'] - else: - self.count = None + self.count = epics_database.get('count', None) if self.type == 'enum' and 'enums' in epics_database: self.enums = epics_database['enums'] else: diff --git a/siriuspy/siriuspy/pwrsupply/psctrl/psmodel.py b/siriuspy/siriuspy/pwrsupply/psctrl/psmodel.py index 5f34f15f0..35700e3ca 100644 --- a/siriuspy/siriuspy/pwrsupply/psctrl/psmodel.py +++ b/siriuspy/siriuspy/pwrsupply/psctrl/psmodel.py @@ -31,6 +31,12 @@ class _PSModel: 'CycleAmpl-RB': _c.V_SIGGEN_AMPLITUDE, 'CycleOffset-RB': _c.V_SIGGEN_OFFSET, 'CycleAuxParam-RB': _c.V_SIGGEN_AUX_PARAM, + # Wfm + 'WfmSelected-RB': _c.V_WFMREF_SELECTED, + 'WfmSyncMode-Sts': _c.V_WFMREF_SYNC_MODE, + 'WfmFreq-RB': _c.V_WFMREF_FREQUENCY, + 'WfmGain-RB': _c.V_WFMREF_GAIN, + 'WfmOffset-RB': _c.V_WFMREF_OFFSET, # Scope 'ScopeSrcAddr-RB': _c.V_SCOPE_SRC_DATA, 'ScopeFreq-RB': _c.V_SCOPE_FREQUENCY, @@ -296,6 +302,17 @@ def _writer_wfm( if epics_field == 'WfmMonAcq-Sel': return _writers.WfmMonAcq( device_ids, pru_controller, setpoints) + p2i = { + 'WfmSelected-SP': 0, + 'WfmSyncMode-Sel': 1, + 'WfmFreq-SP': 2, + 'WfmGain-SP': 3, + 'WfmOffset-SP': 4, + } + if epics_field in p2i: + idx = p2i[epics_field] + return _writers.CfgWfm( + device_ids, pru_controller, idx, setpoints) return None diff --git a/siriuspy/siriuspy/pwrsupply/tests/fbp-example.ipynb b/siriuspy/siriuspy/pwrsupply/tests/fbp-example.ipynb index d3b524958..0d1bbae1e 100644 --- a/siriuspy/siriuspy/pwrsupply/tests/fbp-example.ipynb +++ b/siriuspy/siriuspy/pwrsupply/tests/fbp-example.ipynb @@ -1,16 +1,27 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Using BSMP Commands" + ] + }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ + "from siriuspy.pwrsupply.bsmp.constants import ConstPSBSMP as _c\n", "from siriuspy.pwrsupply.bsmp.commands import FBP\n", "from siriuspy.pwrsupply.pructrl.pru import PRU\n", "from PRUserial485 import EthBridgeClient as _EthBridgeClient\n", "\n", "\n", + "import utils\n", + "\n", + "\n", "def create_fbp(bbbname, device_id):\n", " \"\"\".\"\"\"\n", " pru = PRU(ethbridgeclnt_class=_EthBridgeClient, bbbname=bbbname)\n", @@ -20,39 +31,31 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 38, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "BEAGLEBONE: LA-RaCtrl:CO-PSCtrl-TB2\n", - "IP_ADDRESS: 10.128.121.104\n" - ] - }, - { - "ename": "timeout", - "evalue": "timed out", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mtimeout\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[4], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# ps = create_fbp(bbbname='IA-11RaCtrl:CO-PSCtrl-SI4', device_id=1) # SI-11C1:PS-CH\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;66;03m# ps = create_fbp(bbbname='PA-RaPSB06:CO-PSCtrl-SI1', device_id=3) # SI-Fam:PS-SDA1\u001b[39;00m\n\u001b[0;32m----> 3\u001b[0m ps \u001b[38;5;241m=\u001b[39m \u001b[43mcreate_fbp\u001b[49m\u001b[43m(\u001b[49m\u001b[43mbbbname\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mLA-RaCtrl:CO-PSCtrl-TB2\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdevice_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m \u001b[38;5;66;03m# TB-01:PS-CH-1\u001b[39;00m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;66;03m# ack, data = ps.remove_all_groups_of_variables(timeout=100)\u001b[39;00m\n\u001b[1;32m 7\u001b[0m \u001b[38;5;66;03m# print('cmd : ', 'remove_all')\u001b[39;00m\n\u001b[1;32m 8\u001b[0m \u001b[38;5;66;03m# print('ack : ', ack)\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 57\u001b[0m \u001b[38;5;66;03m# print('data: ', psnames)\u001b[39;00m\n\u001b[1;32m 58\u001b[0m \u001b[38;5;66;03m# print()\u001b[39;00m\n", - "Cell \u001b[0;32mIn[2], line 8\u001b[0m, in \u001b[0;36mcreate_fbp\u001b[0;34m(bbbname, device_id)\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mcreate_fbp\u001b[39m(bbbname, device_id):\n\u001b[1;32m 7\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\".\"\"\"\u001b[39;00m\n\u001b[0;32m----> 8\u001b[0m pru \u001b[38;5;241m=\u001b[39m \u001b[43mPRU\u001b[49m\u001b[43m(\u001b[49m\u001b[43methbridgeclnt_class\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m_EthBridgeClient\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mbbbname\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mbbbname\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 9\u001b[0m ps \u001b[38;5;241m=\u001b[39m FBP(slave_address\u001b[38;5;241m=\u001b[39mdevice_id, pru\u001b[38;5;241m=\u001b[39mpru)\n\u001b[1;32m 10\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m ps\n", - "File \u001b[0;32m~/repos/dev-packages/siriuspy/siriuspy/pwrsupply/pructrl/pru.py:88\u001b[0m, in \u001b[0;36mPRU.__init__\u001b[0;34m(self, ethbridgeclnt_class, bbbname, ip_address)\u001b[0m\n\u001b[1;32m 85\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_ip_address \u001b[38;5;241m=\u001b[39m ip_address\n\u001b[1;32m 87\u001b[0m \u001b[38;5;66;03m# start communication threads\u001b[39;00m\n\u001b[0;32m---> 88\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_ethbridge \u001b[38;5;241m=\u001b[39m \u001b[43methbridgeclnt_class\u001b[49m\u001b[43m(\u001b[49m\u001b[43mip_address\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mip_address\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 90\u001b[0m \u001b[38;5;66;03m# init PRUserial485 interface\u001b[39;00m\n\u001b[1;32m 91\u001b[0m PRUInterface\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__init__\u001b[39m(\u001b[38;5;28mself\u001b[39m)\n", - "File \u001b[0;32m~/repos/eth-bridge-pru-serial485/client/PRUserial485/PRUserial485.py:458\u001b[0m, in \u001b[0;36mEthBridgeClient.__init__\u001b[0;34m(self, ip_address)\u001b[0m\n\u001b[1;32m 454\u001b[0m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__init__\u001b[39m(ip_address)\n\u001b[1;32m 456\u001b[0m \u001b[38;5;66;03m# NOTE: Should I connect here with option #1, #2 or should I leave\u001b[39;00m\n\u001b[1;32m 457\u001b[0m \u001b[38;5;66;03m# it for the first interaction with the server?\u001b[39;00m\n\u001b[0;32m--> 458\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconnect_socket\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/repos/eth-bridge-pru-serial485/client/PRUserial485/PRUserial485.py:473\u001b[0m, in \u001b[0;36mEthBridgeClient.connect_socket\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 471\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mconnect_socket\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[1;32m 472\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Open a socket connection.\"\"\"\u001b[39;00m\n\u001b[0;32m--> 473\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_socket_connect\u001b[49m\u001b[43m(\u001b[49m\u001b[43mSERVER_PORT_RW\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/repos/eth-bridge-pru-serial485/client/PRUserial485/PRUserial485.py:197\u001b[0m, in \u001b[0;36m_EthBridgeClientCommonInterface._socket_connect\u001b[0;34m(self, conn_port)\u001b[0m\n\u001b[1;32m 194\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msocket \u001b[38;5;241m=\u001b[39m socket\u001b[38;5;241m.\u001b[39msocket(socket\u001b[38;5;241m.\u001b[39mAF_INET, socket\u001b[38;5;241m.\u001b[39mSOCK_STREAM)\n\u001b[1;32m 195\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msocket\u001b[38;5;241m.\u001b[39msettimeout(DEFAULT_TIMEOUT)\n\u001b[0;32m--> 197\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msocket\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconnect\u001b[49m\u001b[43m(\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_bbb_ip\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconn_port\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 198\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msocket\u001b[38;5;241m.\u001b[39msetsockopt(socket\u001b[38;5;241m.\u001b[39mSOL_TCP, socket\u001b[38;5;241m.\u001b[39mTCP_NODELAY, \u001b[38;5;241m1\u001b[39m)\n", - "\u001b[0;31mtimeout\u001b[0m: timed out" + "BEAGLEBONE: IA-01RaCtrl:CO-PSCtrl-BO\n", + "IP_ADDRESS: 10.128.101.105\n", + "cmd : read_variable\n", + "ack : 224\n", + "data: 0.0\n", + "\n", + "cmd : read_group_of_variables\n", + "ack : 224\n", + "data: [390, 0.0, 0.5795004367828369, [b'0', b'.', b'4', b'4', b'.', b'0', b'1', b' ', b' ', b' ', b' ', b'0', b'8', b'/', b'2', b'2', b'0', b'.', b'4', b'4', b'.', b'0', b'1', b' ', b' ', b' ', b' ', b'0', b'8', b'/', b'2', b'2', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00', b'\\x00'], 1037, 21492669, 0, 1, 20, 0.0, 2.0, 10.0, 0.0, [0.0, 0.0, 2.0, 0.0], 0, 2, 2000.0, 1.0, 0.0, 57344, 59302, 57946, 59392, 61350, 61352, 2000.0, 0.5119999647140503, 53256, 25012, 0, 0, 0, 0, 0.5811195373535156, 0.13808594644069672, 7.353515625, 0.0, 0.05750684812664986, 0, 0, 0, 0, 0, 0, 0, 0, 390, 390, 390, 256, 0.0, 0.0, 0.0, 0.0, 0.5793026685714722, -0.5616105198860168, 0.0, 0.0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5806427001953125, -0.562286376953125, -0.0004405975341796875, 0.0, 0, 0, 0, 0]\n", + "\n" ] } ], "source": [ "# ps = create_fbp(bbbname='IA-11RaCtrl:CO-PSCtrl-SI4', device_id=1) # SI-11C1:PS-CH\n", "# ps = create_fbp(bbbname='PA-RaPSB06:CO-PSCtrl-SI1', device_id=3) # SI-Fam:PS-SDA1\n", - "ps = create_fbp(bbbname='LA-RaCtrl:CO-PSCtrl-TB2', device_id=1) # TB-01:PS-CH-1\n", - "\n", + "# ps = create_fbp(bbbname='LA-RaCtrl:CO-PSCtrl-TB2', device_id=1) # TB-01:PS-CH-1\n", + "ps = create_fbp(bbbname='IA-01RaCtrl:CO-PSCtrl-BO', device_id=1) # BO-01U:PS-CH, BO-01U:PS-CV, BO-02D:PS-QS\n", "\n", "# ack, data = ps.remove_all_groups_of_variables(timeout=100)\n", "# print('cmd : ', 'remove_all')\n", @@ -60,17 +63,17 @@ "# print('data: ', data)\n", "# print()\n", "\n", - "# ack, data = ps.read_variable(0, timeout=100)\n", - "# print('cmd : ', 'read_variable')\n", - "# print('ack : ', ack)\n", - "# print('data: ', data)\n", - "# print()\n", + "ack, data = ps.read_variable(_c.V_PS_SETPOINT, timeout=100)\n", + "print('cmd : ', 'read_variable')\n", + "print('ack : ', ack)\n", + "print('data: ', data)\n", + "print()\n", "\n", - "# ack, data = ps.read_group_of_variables(group_id=0, timeout=100)\n", - "# print('cmd : ', 'read_group_of_variables')\n", - "# print('ack : ', ack)\n", - "# print('data: ', data)\n", - "# print()\n", + "ack, data = ps.read_group_of_variables(group_id=0, timeout=100)\n", + "print('cmd : ', 'read_group_of_variables')\n", + "print('ack : ', ack)\n", + "print('data: ', data)\n", + "print()\n", "\n", "# data = ps.parameter_read(eid=8)\n", "# print('cmd : ', 'parameter_read(eid=8)')\n", @@ -109,6 +112,246 @@ "# print()" ] }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(224, 2)" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ps.read_variable(_c.V_WFMREF_SYNC_MODE, timeout=100)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Using BBB" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from PRUserial485 import EthBridgeClient as _EthBridgeClient\n", + "from siriuspy.pwrsupply.factory import BBBFactory\n", + "\n", + "import utils" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# bbbname = 'LA-RaCtrl:CO-PSCtrl-TB2' # TB-01 and TB-02 Chs and CVs\n", + "bbbname = 'IA-01RaCtrl:CO-PSCtrl-BO' # BO-01U:PS-CH, BO-01U:PS-CV, BO-02D:PS-QS" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "BEAGLEBONE: IA-01RaCtrl:CO-PSCtrl-BO\n", + "IP_ADDRESS: 10.128.101.105\n", + "UDC: IA-01RaPS01:PS-UDC-BO , DEVICES: [('BO-01U:PS-CH', 1), ('BO-01U:PS-CV', 2), ('BO-02D:PS-QS', 3)]\n", + "\n", + "PRUController: struct initialization\n", + "devices: [('BO-01U:PS-CH', 1), ('BO-01U:PS-CV', 2), ('BO-02D:PS-QS', 3)]\n", + "device_id: 1, scan_freq: 5.0 Hz\n", + "device_id: 2, scan_freq: 5.0 Hz\n", + "device_id: 3, scan_freq: 5.0 Hz\n", + "\n", + "TIMING struct init [2.077 ms]\n" + ] + } + ], + "source": [ + "bbb, *_ = BBBFactory.create(ethbridgeclnt_class=_EthBridgeClient, bbbname=bbbname)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('BO-01U:PS-CH', 'BO-01U:PS-CV', 'BO-02D:PS-QS')" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "bbb.psnames" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "PRUController: bsmp initialization\n", + " - bsmp_init_devices ( reset groups ) [00008.960] ms\n", + " - bsmp_init_devices ( update groups ) [00020.021] ms\n", + " - bsmp_init_devices ( bufsample_disable ) [00504.051] ms\n", + " - bsmp_init_update ( variable_values ) [00012.053] ms\n", + " - bsmp_init_update ( waveform_values ) [00119.740] ms\n", + " - bsmp_init_update ( sofb_values ) [00001.467] ms\n", + " - bsmp_init_update ( parameter_values ) [01728.054] ms\n", + " - init_threads ( create structures ) [00000.069] ms\n", + "TIMING bsmp init [2395.257 ms]\n", + "\n" + ] + } + ], + "source": [ + "bbb.init(processing=False, scanning=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(6, True)\n", + "(2, False)\n", + "(0, False)\n" + ] + } + ], + "source": [ + "psname = bbb.psnames[0]\n", + "\n", + "utils.update_bbb(bbb)\n", + "\n", + "print(bbb.read(psname, 'OpMode-Sts'))\n", + "print(bbb.read(psname, 'WfmSyncMode-Sts'))\n", + "print(bbb.read(psname, 'WfmSelected-RB'))" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'BO-01U:PS-CH': ,\n", + " 'BO-01U:PS-CV': ,\n", + " 'BO-02D:PS-QS': }" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "bbb.controllers" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "c = bbb.controllers[psname]" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ScopeFreq-RB\n", + "ParamPWMFreq-Cte\n", + "WfmFreq-SP\n", + "ParamHRADCFreqSampling-Cte\n", + "ParamCtrlFreqTimeSlicer-Cte\n", + "ParamCtrlFreqCtrlISR-Cte\n", + "ScopeFreq-SP\n", + "WfmFreq-RB\n", + "ParamScopeSamplingFreq-Cte\n", + "ParamSigGenFreq-Cte\n", + "CycleFreq-SP\n", + "ParamWfmRefFreq-Cte\n", + "CycleFreq-RB\n" + ] + } + ], + "source": [ + "for field in c.fields:\n", + " if 'Freq' in field:\n", + " print(field)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "w = c._writers['TB-01:PS-CV-1:WfmFreq-SP']" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'type': 'float', 'value': 2000.0, 'unit': 'Hz'}" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "w._setpoints.database" + ] + }, { "cell_type": "code", "execution_count": null, @@ -133,7 +376,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.2" + "version": "3.6.8" } }, "nbformat": 4, diff --git a/siriuspy/siriuspy/pwrsupply/tests/utils.py b/siriuspy/siriuspy/pwrsupply/tests/utils.py index 81bc3c4a0..804cb59ac 100644 --- a/siriuspy/siriuspy/pwrsupply/tests/utils.py +++ b/siriuspy/siriuspy/pwrsupply/tests/utils.py @@ -6,6 +6,8 @@ import matplotlib.pyplot as plt import numpy as np +from PRUserial485 import EthBridgeClient as _EthBridgeClient + from siriuspy.search import PSSearch from siriuspy.pwrsupply.pructrl.udc import UDC from siriuspy.pwrsupply.pructrl.pru import PRU @@ -19,7 +21,7 @@ def create_udc(bbbname=BBBNAME, udc_index=None): """Create UDC.""" - pru = PRU(bbbname=bbbname) + pru = PRU(ethbridgeclnt_class=_EthBridgeClient, bbbname=bbbname) if udc_index is not None: udc_list = PSSearch.conv_bbbname_2_udc(bbbname) udcname = udc_list[udc_index] @@ -337,3 +339,13 @@ def test_wfmref_write_rmpwfm(): print_basic_info(all_ps) wfmref_flip(ps5) return udc, all_ps + + +# --- bbb --- + + +def update_bbb(bbb): + for psname in bbb.psnames: + controller = bbb.controllers[psname] + pruc = controller.pru_controller + pruc._bsmp_update() diff --git a/siriuspy/tests/pwrsupply/test_csdev.py b/siriuspy/tests/pwrsupply/test_csdev.py index 54e6d7769..6df234bfa 100755 --- a/siriuspy/tests/pwrsupply/test_csdev.py +++ b/siriuspy/tests/pwrsupply/test_csdev.py @@ -18,6 +18,7 @@ 'DEF_WFMSIZE_OTHERS', 'DEFAULT_WFM_OTHERS', 'DEFAULT_WFM', + 'DEFAULT_WFM_OFFSET', 'PSSOFB_MAX_NR_UDC', 'DEFAULT_SIGGEN_CONFIG', 'PS_CURRENT_PRECISION', diff --git a/siriuspy/tests/pwrsupply/variables.py b/siriuspy/tests/pwrsupply/variables.py index 2531e5dc7..dee2fdf4d 100644 --- a/siriuspy/tests/pwrsupply/variables.py +++ b/siriuspy/tests/pwrsupply/variables.py @@ -59,4 +59,5 @@ 'IntlkSoft-Mon': 0, 'IntlkHard-Mon': 0, 'Current-Mon': 6.722831726074219, + 'WfmOffset-RB': 0.0, 'WfmData-RB': list(range(4000))}