Skip to content
Snippets Groups Projects
Commit b3cf2dca authored by Jan David Mol's avatar Jan David Mol
Browse files

Merged master into working copy, fixed merge conflicts.

parents 1fce05d2 0ff6210e
No related branches found
No related tags found
1 merge request!5Create a branch that contains the only working copy as of 2020-12-7
**/env
**/__pycache__
**/*.pyc
...@@ -4,14 +4,66 @@ Python OPC-UA server to control the I2C devices in the LTS. ...@@ -4,14 +4,66 @@ Python OPC-UA server to control the I2C devices in the LTS.
+ opcuserv.py: OPC-UA server that expose (visible) variables and methods. + opcuserv.py: OPC-UA server that expose (visible) variables and methods.
# LTS structure: # Prerequisites
## Requirements
This Python3 code uses other Python3 modules:
- opcua
- pyyaml
- numpy
We recommend to install a virtual environment and then install the dependencies there. For convenience we have added the relevant modules to the file `requirements.txt` that can be used to install them with pip3: `python3 -m pip install -r requirements.txt`
Below are step-by-step instructions that show how to install the dependencies neatly in a Python3 virtual environment.
```bash
# Create a Python3 virtual environment with the name "env"
python3 -m venv env
# Activate the virtual environment
. env/bin/activate
# Update the already installed modules in the virtual environment since they are usually outdated
python3 -m pip install --upgrade pip wheel
# Deactivate the virtual environment and start it again
deactivate
. env/bin/activate
# And finally install the module dependencies
python3 -m pip install -r requirements.txt
```
# Execute it
The software can be simply executed with Python3: `python3 opcuaserv.py`
Optional parameters are explained when the `-h` or `--help` parameter is supplied:
```bash
python3 opcuaserv.py --help
cryptography is not installed, use of crypto disabled
cryptography is not installed, use of crypto disabled
usage: opcuaserv.py [-h] [-s] [--no-lib-hack] [-p PORT]
optional arguments:
-h, --help show this help message and exit
-s, --simulator Do not connect to I2c, but simulate behaviour.
--no-lib-hack Do not require a hacked opcua library. Breaks behaviour.
-p PORT, --port PORT Port number to listen on [4842].
```
# LTS structure
Raspberry pi (LTS_pypcc.yaml -> I2C controller on raspberry pi) Raspberry pi (LTS_pypcc.yaml -> I2C controller on raspberry pi)
> Control PCB (LTS_switch.yaml -> I2C switch) > Control PCB (LTS_switch.yaml -> I2C switch)
>
> > RCU2 PCB (LTS_RCUx.yaml -> I2C devices) > > RCU2 PCB (LTS_RCUx.yaml -> I2C devices)
> >
> > > RCU2 Dither source (LTS_RCU2_dither.yaml -> I2C bitbang) > > > RCU2 Dither source (LTS_RCU2_dither.yaml -> I2C bitbang)
> > > >
> > > ADC (LTS_RCU2_ADC.yaml -> SPI bitbang2) > > > ADC (LTS_RCU2_ADC.yaml -> SPI bitbang2)
> > > >
> > Clock PCB (LTS_clk.yaml -> I2C device) > > Clock PCB (LTS_clk.yaml -> I2C device)
> >
> > > PLL (LTS_clkPLL.yaml -> SPI bitbang1) > > > PLL (LTS_clkPLL.yaml -> SPI bitbang1)
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
import yaml; import yaml;
import importlib import importlib
import sys, inspect import sys, inspect
YAMLDIR='yaml/' YAMLDIR='YAML/'
class hwdev: class hwdev:
def __init__(self,configfile): def __init__(self,configfile):
print("Loading:",configfile) print("Loading:",configfile)
......
...@@ -5,17 +5,25 @@ sys.path.insert(0, "..") ...@@ -5,17 +5,25 @@ sys.path.insert(0, "..")
import time import time
from opcua import ua, Server from opcua import ua, Server
from datetime import datetime; from datetime import datetime;
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--simulator", help="Do not connect to I2c, but simulate behaviour.", action="store_true")
parser.add_argument("--no-lib-hack", help="Do not require a hacked opcua library. Breaks behaviour.", action="store_true")
parser.add_argument("-p", "--port", help="Port number to listen on [%(default)s].", type=int, default=4842)
args = parser.parse_args()
import pypcc; if args.simulator:
#import pypcc_test as pypcc; import pypcc_test as pypcc
P1=pypcc.pypcc("LTS_pypcc.yaml") else:
import pypcc
P1=pypcc.pypcc("LTS_pypcc.yaml")
if True: if True:
# setup our server # setup our server
server = Server() server = Server()
server.set_endpoint("opc.tcp://0.0.0.0:4842/PCC/") server.set_endpoint("opc.tcp://0.0.0.0:{}/PCC/".format(args.port))
idx = server.register_namespace("http://lofar.eu") idx = server.register_namespace("http://lofar.eu")
# uri = "http://examples.freeopcua.github.io" # uri = "http://examples.freeopcua.github.io"
...@@ -77,6 +85,10 @@ class SubHandler(object): ...@@ -77,6 +85,10 @@ class SubHandler(object):
# print(Vars_R,Vars_R.values()) # print(Vars_R,Vars_R.values())
for vname2,myvar2,oldvalue in Vars_R.values(): for vname2,myvar2,oldvalue in Vars_R.values():
if vname2==vname: if vname2==vname:
if args.simulator:
res=True
print("Simulating fallthrough _RW->_R for",vname,": Result:",res,oldvalue)
else:
res=P1.GetVarValue(vname,val) res=P1.GetVarValue(vname,val)
print("Read callback",vname,": Result:",res,oldvalue) print("Read callback",vname,": Result:",res,oldvalue)
if res: if res:
...@@ -113,6 +125,7 @@ def AddVar(name,dtype=0,RW=0,cnt=1): ...@@ -113,6 +125,7 @@ def AddVar(name,dtype=0,RW=0,cnt=1):
Vars_R[myvar.nodeid.Identifier]=[name,myvar.get_data_value(),varvalue2] Vars_R[myvar.nodeid.Identifier]=[name,myvar.get_data_value(),varvalue2]
ValCallback(myvar.nodeid,force=True) ValCallback(myvar.nodeid,force=True)
# print(myvar.get_value()) # print(myvar.get_value())
if not args.no_lib_hack:
server.set_attribute_callback(myvar.nodeid, ValCallback) server.set_attribute_callback(myvar.nodeid, ValCallback)
# varvalue=myvar.get_data_value().Value # varvalue=myvar.get_data_value().Value
# Vars_R[myvar.nodeid.Identifier][2]=varvalue # Vars_R[myvar.nodeid.Identifier][2]=varvalue
......
#import pypcc; import pypcc;
import pypcc_test as pypcc; #import pypcc_test as pypcc;
P1=pypcc.pypcc("LTS_pypcc.yaml") P1=pypcc.pypcc("LTS_pypcc.yaml")
...@@ -9,8 +9,10 @@ def AddMethod(name): ...@@ -9,8 +9,10 @@ def AddMethod(name):
P1.GetMethodNames("",AddMethod); P1.GetMethodNames("",AddMethod);
##Print all the visible variables ##Print all the visible variables
def AddVar(name,dtype=0,RW=0): def AddVar(name,dtype=0,RW=3,cnt=1):
print("Var:",name,dtype,RW) Types={0:'int',1:'float'}
RWs={0:'hidden',1:'RO',2:'WO',3:'RW'}
print("Var:",name,Types[dtype],RWs[RW],cnt)
P1.GetVarNames("",AddVar); P1.GetVarNames("",AddVar);
a=[0] a=[0]
......
...@@ -17,10 +17,11 @@ def AddMethod(name): ...@@ -17,10 +17,11 @@ def AddMethod(name):
print("Method:",name) print("Method:",name)
P1.GetMethodNames("",AddMethod); P1.GetMethodNames("",AddMethod);
def AddVar(name,dtype=0,RW=3): def AddVar(name,dtype=0,RW=3,cnt=1):
Types={0:'int',1:'float'} Types={0:'int',1:'float'}
RWs={0:'hidden',1:'RO',2:'WO',3:'RW'} RWs={0:'hidden',1:'RO',2:'WO',3:'RW'}
print("Var:",name,Types[dtype],RWs[RW]) print("Var:",name,Types[dtype],RWs[RW],cnt)
P1.GetVarNames("",AddVar); P1.GetVarNames("",AddVar);
#exit() #exit()
#P1.CallMethod("RCU01_RCU_on",None) #P1.CallMethod("RCU01_RCU_on",None)
......
import pypcc;
#import pypcc_test as pypcc;
P1=pypcc.pypcc("LTS_pypcc.yaml")
##Print all the visible methods
def AddMethod(name):
print("Method:",name)
P1.GetMethodNames("",AddMethod);
##Print all the visible variables
def AddVar(name,dtype=0,RW=0,dim=1):
print("Var:",name,dtype,RW,dim)
P1.GetVarNames("",AddVar);
a=[0]
##Setup ADC RCU1
P1.CallMethod("RCU01_RCU_off",None)
P1.CallMethod("RCU01_RCU_on",None)
#P1.GetVarValue("RCU01_ADC1_locked",a);print(a[0]);
P1.GetVarValue("RCU01_ADC1_SYNC",a);print(a[0]);
P1.GetVarValue("RCU01_ADC1_CML",a);print(a[0]);
P1.GetVarValue("RCU01_ADC1_JESD",a);print(a[0]);
P1.GetVarValue("RCU01_ADC2_SYNC",a);print(a[0]);
P1.GetVarValue("RCU01_ADC2_CML",a);print(a[0]);
P1.GetVarValue("RCU01_ADC2_JESD",a);print(a[0]);
P1.GetVarValue("RCU01_ADC3_SYNC",a);print(a[0]);
P1.GetVarValue("RCU01_ADC3_CML",a);print(a[0]);
P1.GetVarValue("RCU01_ADC3_JESD",a);print(a[0]);
#P1.GetVarValue("RCU01_ADC1_JESD_control1",a);print(a[0]);
#P1.GetVarValue("RCU01_ADC1_CML_level",a);print(a[0]);
#P1.GetVarValue("RCU01_ADC1_locked",a);print(a[0]);
#P1.GetVarValue("RCU01_ADC1_locked",a);print(a[0]);
# - ADC1.SYNC_control: [1] #Setup ADCs
# - ADC1.JESD_control1: [14] #Setup ADCs
# - ADC1.CML_level: [0x7]
# - ADC1.Update: [1] #Needed to update ADC registers
exit()
##Setup ADC RCU3
P1.CallMethod("RCU01_RCU_off",None)
P1.CallMethod("RCU03_RCU_on",None)
P1.GetVarValue("RCU03_ADC1_locked",a);print(a[0]);
P1.GetVarValue("RCU03_ADC2_locked",a);print(a[0]);
P1.GetVarValue("RCU03_ADC3_locked",a);print(a[0]);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment