author | Edouard Tisserant <edouard@beremiz.fr> |
Fri, 06 Dec 2024 12:16:07 +0100 | |
changeset 4062 | 1994928ce3d2 |
parent 3820 | 46f3ca3f0157 |
permissions | -rw-r--r-- |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
1 |
# opcua/client.py |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
2 |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3718
diff
changeset
|
3 |
|
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
4 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
5 |
import os |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
6 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
7 |
from editors.ConfTreeNodeEditor import ConfTreeNodeEditor |
3339
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
8 |
from PLCControler import LOCATION_CONFNODE, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT |
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
9 |
from .opcua_client_maker import OPCUAClientPanel, OPCUAClientModel, UA_IEC_types, authParams |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
10 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
11 |
import util.paths as paths |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
12 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
13 |
# Paths to open62541 assume that |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
14 |
# - open62541 directory is aside beremiz directory |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
15 |
# - open62541 was just built (not installed) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
16 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
17 |
Open62541Path = paths.ThirdPartyPath("open62541") |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
18 |
Open62541LibraryPath = os.path.join(Open62541Path,"build","bin") |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
19 |
Open62541IncludePaths = [os.path.join(Open62541Path, *dirs) for dirs in [ |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
20 |
("plugins","include"), |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
21 |
("build","src_generated"), |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
22 |
("include",), |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
23 |
("arch",)]] |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
24 |
|
3718
7841b651d601
Tests: OPCUA tests can now use OPCUA_DEFAULT_HOST environment variable to force host to something else than "127.0.0.1" or "localhost"
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3678
diff
changeset
|
25 |
# Tests need to use other default hosts |
7841b651d601
Tests: OPCUA tests can now use OPCUA_DEFAULT_HOST environment variable to force host to something else than "127.0.0.1" or "localhost"
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3678
diff
changeset
|
26 |
OPCUA_DEFAULT_HOST = os.environ.get("OPCUA_DEFAULT_HOST", "127.0.0.1") |
7841b651d601
Tests: OPCUA tests can now use OPCUA_DEFAULT_HOST environment variable to force host to something else than "127.0.0.1" or "localhost"
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3678
diff
changeset
|
27 |
|
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
28 |
class OPCUAClientEditor(ConfTreeNodeEditor): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
29 |
CONFNODEEDITOR_TABS = [ |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
30 |
(_("OPC-UA Client"), "CreateOPCUAClient_UI")] |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
31 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
32 |
def Log(self, msg): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
33 |
self.Controler.GetCTRoot().logger.write(msg) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
34 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
35 |
def CreateOPCUAClient_UI(self, parent): |
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
36 |
return OPCUAClientPanel(parent, self.Controler.GetModelData(), self.Log, self.Controler.GetConfig) |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
37 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
38 |
class OPCUAClient(object): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
39 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
40 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
41 |
<xsd:element name="OPCUAClient"> |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
42 |
<xsd:complexType> |
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
43 |
<xsd:sequence> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
44 |
<xsd:element name="AuthType" minOccurs="0"> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
45 |
<xsd:complexType> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
46 |
<xsd:choice minOccurs="0"> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
47 |
<xsd:element name="x509"> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
48 |
<xsd:complexType> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
49 |
<xsd:sequence> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
50 |
<xsd:element name="Policy"> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
51 |
<xsd:annotation> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
52 |
<xsd:documentation>Default to Basic256Sha256 if not specified</xsd:documentation> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
53 |
</xsd:annotation> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
54 |
<xsd:complexType> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
55 |
<xsd:choice minOccurs="0"> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
56 |
<xsd:element name="Basic256Sha256"/> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
57 |
<xsd:element name="Basic128Rsa15"/> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
58 |
<xsd:element name="Basic256"/> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
59 |
</xsd:choice> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
60 |
</xsd:complexType> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
61 |
</xsd:element> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
62 |
<xsd:element name="Mode"> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
63 |
<xsd:complexType> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
64 |
<xsd:choice minOccurs="0"> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
65 |
<xsd:element name="SignAndEncrypt"/> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
66 |
<xsd:element name="Sign"/> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
67 |
</xsd:choice> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
68 |
</xsd:complexType> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
69 |
</xsd:element> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
70 |
</xsd:sequence> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
71 |
<xsd:attribute name="Certificate" type="xsd:string" use="optional" default="certificate.pem"/> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
72 |
<xsd:attribute name="PrivateKey" type="xsd:string" use="optional" default="private_key.pem"/> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
73 |
</xsd:complexType> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
74 |
</xsd:element> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
75 |
<xsd:element name="UserPassword"> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
76 |
<xsd:complexType> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
77 |
<xsd:attribute name="User" type="xsd:string" use="optional"/> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
78 |
<xsd:attribute name="Password" type="xsd:string" use="optional"/> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
79 |
</xsd:complexType> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
80 |
</xsd:element> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
81 |
</xsd:choice> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
82 |
</xsd:complexType> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
83 |
</xsd:element> |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
84 |
</xsd:sequence> |
3718
7841b651d601
Tests: OPCUA tests can now use OPCUA_DEFAULT_HOST environment variable to force host to something else than "127.0.0.1" or "localhost"
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3678
diff
changeset
|
85 |
<xsd:attribute name="Server_URI" type="xsd:string" use="optional" default="opc.tcp://"""+OPCUA_DEFAULT_HOST+""":4840"/> |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
86 |
</xsd:complexType> |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
87 |
</xsd:element> |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
88 |
</xsd:schema> |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
89 |
""" |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
90 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
91 |
EditorType = OPCUAClientEditor |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
92 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
93 |
def __init__(self): |
3674
d10a7907fb43
OPC-UA: Update CTN "ChangesToSave" status when variable selection change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3652
diff
changeset
|
94 |
self.modeldata = OPCUAClientModel(self.Log, self.CTNMarkModified) |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
95 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
96 |
filepath = self.GetFileName() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
97 |
if os.path.isfile(filepath): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
98 |
self.modeldata.LoadCSV(filepath) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
99 |
|
3378
e655ec8162e1
OPC-UA: fix types in model not being preserved after reload of CSV file, leading to exception when changing selection lists content.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3339
diff
changeset
|
100 |
def Log(self, msg): |
e655ec8162e1
OPC-UA: fix types in model not being preserved after reload of CSV file, leading to exception when changing selection lists content.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3339
diff
changeset
|
101 |
self.GetCTRoot().logger.write(msg) |
e655ec8162e1
OPC-UA: fix types in model not being preserved after reload of CSV file, leading to exception when changing selection lists content.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3339
diff
changeset
|
102 |
|
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
103 |
def GetModelData(self): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
104 |
return self.modeldata |
3674
d10a7907fb43
OPC-UA: Update CTN "ChangesToSave" status when variable selection change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3652
diff
changeset
|
105 |
|
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
106 |
def GetConfig(self): |
3678
6c496a8ed2a9
OPC-UA: tolerate better pre-encryption formated client configuration file.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3674
diff
changeset
|
107 |
def cfg(path): |
6c496a8ed2a9
OPC-UA: tolerate better pre-encryption formated client configuration file.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3674
diff
changeset
|
108 |
try: |
6c496a8ed2a9
OPC-UA: tolerate better pre-encryption formated client configuration file.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3674
diff
changeset
|
109 |
attr=self.GetParamsAttributes("OPCUAClient."+path) |
6c496a8ed2a9
OPC-UA: tolerate better pre-encryption formated client configuration file.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3674
diff
changeset
|
110 |
except ValueError: |
6c496a8ed2a9
OPC-UA: tolerate better pre-encryption formated client configuration file.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3674
diff
changeset
|
111 |
return None |
6c496a8ed2a9
OPC-UA: tolerate better pre-encryption formated client configuration file.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3674
diff
changeset
|
112 |
return attr["value"] |
6c496a8ed2a9
OPC-UA: tolerate better pre-encryption formated client configuration file.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3674
diff
changeset
|
113 |
|
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
114 |
AuthType = cfg("AuthType") |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
115 |
res = dict(URI=cfg("Server_URI"), AuthType=AuthType) |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
116 |
|
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
117 |
paramList = authParams.get(AuthType, None) |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
118 |
if paramList: |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
119 |
for name,default in paramList: |
3591
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
120 |
value = cfg("AuthType."+name) |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
121 |
if value == "" or value is None: |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
122 |
value = default |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
123 |
# cryptomaterial is expected to be in project's user provide file directory |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
124 |
if name in ["Certificate","PrivateKey"]: |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
125 |
value = os.path.join(self.GetCTRoot()._getProjectFilesPath(), value) |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
126 |
res[name] = value |
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
127 |
|
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
128 |
return res |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
129 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
130 |
def GetFileName(self): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
131 |
return os.path.join(self.CTNPath(), 'selected.csv') |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
132 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
133 |
def OnCTNSave(self, from_project_path=None): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
134 |
self.modeldata.SaveCSV(self.GetFileName()) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
135 |
return True |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
136 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
137 |
def CTNGenerate_C(self, buildpath, locations): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
138 |
current_location = self.GetCurrentLocation() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
139 |
locstr = "_".join(map(str, current_location)) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
140 |
c_path = os.path.join(buildpath, "opcua_client__%s.c" % locstr) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
141 |
|
3612
428fb2472f43
OPC-UA: add logging to help user to understang what went wrong when connecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3611
diff
changeset
|
142 |
c_code = '#include "beremiz.h"\n' |
428fb2472f43
OPC-UA: add logging to help user to understang what went wrong when connecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3611
diff
changeset
|
143 |
c_code += self.modeldata.GenerateC(c_path, locstr, self.GetConfig()) |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
144 |
|
3820
46f3ca3f0157
OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3750
diff
changeset
|
145 |
with open(c_path, 'w') as c_file: |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
146 |
c_file.write(c_code) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
147 |
|
3611
2c041d3d6ee3
OPC-UA: fix LDFLAG, missing OpenSSL's -lcrypto
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3591
diff
changeset
|
148 |
LDFLAGS = ['"' + os.path.join(Open62541LibraryPath, "libopen62541.a") + '"', '-lcrypto'] |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
149 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
150 |
CFLAGS = ' '.join(['-I"' + path + '"' for path in Open62541IncludePaths]) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
151 |
|
3591
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
152 |
# Note: all user provided files are systematicaly copied, including cryptomaterial |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
153 |
|
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
154 |
return [(c_path, CFLAGS)], LDFLAGS, True |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
155 |
|
3339
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
156 |
def GetVariableLocationTree(self): |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
157 |
current_location = self.GetCurrentLocation() |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
158 |
locstr = "_".join(map(str, current_location)) |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
159 |
name = self.BaseParams.getName() |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
160 |
entries = [] |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3718
diff
changeset
|
161 |
for direction, data in self.modeldata.items(): |
3339
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
162 |
iec_direction_prefix = {"input": "__I", "output": "__Q"}[direction] |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
163 |
for row in data: |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
164 |
dname, ua_nsidx, ua_nodeid_type, _ua_node_id, ua_type, iec_number = row |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
165 |
iec_type, C_type, iec_size_prefix, ua_type_enum, ua_type = UA_IEC_types[ua_type] |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
166 |
c_loc_name = iec_direction_prefix + iec_size_prefix + locstr + "_" + str(iec_number) |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
167 |
entries.append({ |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
168 |
"name": dname, |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
169 |
"type": {"input": LOCATION_VAR_INPUT, "output": LOCATION_VAR_OUTPUT}[direction], |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
170 |
"size": {"X":1, "B":8, "W":16, "D":32, "L":64}[iec_size_prefix], |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
171 |
"IEC_type": iec_type, |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
172 |
"var_name": c_loc_name, |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
173 |
"location": iec_size_prefix + ".".join([str(i) for i in current_location]) + "." + str(iec_number), |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
174 |
"description": "", |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
175 |
"children": []}) |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
176 |
return {"name": name, |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
177 |
"type": LOCATION_CONFNODE, |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
178 |
"location": ".".join([str(i) for i in current_location]) + ".x", |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
179 |
"children": entries} |
057b4ba30c35
OPCUA: Add browsing of variables exposed by client when selecting location from variable panel.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
180 |