author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Thu, 06 Oct 2022 10:02:46 +0200 | |
branch | wxPython4 |
changeset 3630 | 921f620577e8 |
parent 3620 | 1cf21430ed4a |
child 3633 | 837e7782d83e |
permissions | -rw-r--r-- |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
1 |
from __future__ import print_function |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
2 |
from __future__ import absolute_import |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
3 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
4 |
import csv |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
5 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
6 |
from opcua import Client |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
7 |
from opcua import ua |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
8 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
9 |
import wx |
3371
d486b98d7005
Backed out changeset c646a1f0fb0b - was on wrong branch
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3369
diff
changeset
|
10 |
import wx.lib.gizmos as gizmos # Formerly wx.gizmos in Classic |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
11 |
import wx.dataview as dv |
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 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
14 |
UA_IEC_types = dict( |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
15 |
# pyopcua | IEC61131| C type | sz | open62541 enum | open62541 |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
16 |
Boolean = ("BOOL" , "uint8_t" , "X", "UA_TYPES_BOOLEAN", "UA_Boolean"), |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
17 |
SByte = ("SINT" , "int8_t" , "B", "UA_TYPES_SBYTE" , "UA_SByte" ), |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
18 |
Byte = ("USINT", "uint8_t" , "B", "UA_TYPES_BYTE" , "UA_Byte" ), |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
19 |
Int16 = ("INT" , "int16_t" , "W", "UA_TYPES_INT16" , "UA_Int16" ), |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
20 |
UInt16 = ("UINT" , "uint16_t", "W", "UA_TYPES_UINT16" , "UA_UInt16" ), |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
21 |
Int32 = ("DINT" , "uint32_t", "D", "UA_TYPES_INT32" , "UA_Int32" ), |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
22 |
UInt32 = ("UDINT", "int32_t" , "D", "UA_TYPES_UINT32" , "UA_UInt32" ), |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
23 |
Int64 = ("LINT" , "int64_t" , "L", "UA_TYPES_INT64" , "UA_Int64" ), |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
24 |
UInt64 = ("ULINT", "uint64_t", "L", "UA_TYPES_UINT64" , "UA_UInt64" ), |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
25 |
Float = ("REAL" , "float" , "D", "UA_TYPES_FLOAT" , "UA_Float" ), |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
26 |
Double = ("LREAL", "double" , "L", "UA_TYPES_DOUBLE" , "UA_Double" ), |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
27 |
) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
28 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
29 |
UA_NODE_ID_types = { |
3338
fe0da9a8a225
OPCUS client: fix handling of string type Node Identifier
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
30 |
"int" : ("UA_NODEID_NUMERIC", "{}" ), |
fe0da9a8a225
OPCUS client: fix handling of string type Node Identifier
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
31 |
"str" : ("UA_NODEID_STRING" , '"{}"'), |
3406
3aac4241dafa
OPC-UA: cosmetic fix and armless typo
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3392
diff
changeset
|
32 |
"UUID" : ("UA_NODEID_UUID" , '"{}"'), |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
33 |
} |
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 |
lstcolnames = [ "Name", "NSIdx", "IdType", "Id", "Type", "IEC"] |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
36 |
lstcolwidths = [ 100, 50, 100, 100, 100, 50] |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
37 |
lstcoltypess = [ str, int, str, str, str, int] |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
38 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
39 |
directions = ["input", "output"] |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
40 |
|
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
41 |
authParams = { |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
42 |
"x509":[ |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
43 |
("Certificate", "certificate.der"), |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
44 |
("PrivateKey", "private_key.pem"), |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
45 |
("Policy", "Basic256Sha256"), |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
46 |
("Mode", "SignAndEncrypt")], |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
47 |
"UserPassword":[ |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
48 |
("User", None), |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
49 |
("Password", None)]} |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
50 |
|
3371
d486b98d7005
Backed out changeset c646a1f0fb0b - was on wrong branch
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3369
diff
changeset
|
51 |
class OPCUASubListModel(dv.DataViewIndexListModel): |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
52 |
def __init__(self, data, log): |
3371
d486b98d7005
Backed out changeset c646a1f0fb0b - was on wrong branch
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3369
diff
changeset
|
53 |
dv.DataViewIndexListModel.__init__(self, len(data)) |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
54 |
self.data = data |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
55 |
self.log = log |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
56 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
57 |
def GetColumnType(self, col): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
58 |
return "string" |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
59 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
60 |
def GetValueByRow(self, row, col): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
61 |
return str(self.data[row][col]) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
62 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
63 |
# This method is called when the user edits a data item in the view. |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
64 |
def SetValueByRow(self, value, row, col): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
65 |
expectedtype = lstcoltypess[col] |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
66 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
67 |
try: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
68 |
v = expectedtype(value) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
69 |
except ValueError: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
70 |
self.log("String {} is invalid for type {}\n".format(value,expectedtype.__name__)) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
71 |
return False |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
72 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
73 |
if col == lstcolnames.index("IdType") and v not in UA_NODE_ID_types: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
74 |
self.log("{} is invalid for IdType\n".format(value)) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
75 |
return False |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
76 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
77 |
self.data[row][col] = v |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
78 |
return True |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
79 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
80 |
# Report how many columns this model provides data for. |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
81 |
def GetColumnCount(self): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
82 |
return len(lstcolnames) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
83 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
84 |
# Report the number of rows in the model |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
85 |
def GetCount(self): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
86 |
#self.log.write('GetCount') |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
87 |
return len(self.data) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
88 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
89 |
# Called to check if non-standard attributes should be used in the |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
90 |
# cell at (row, col) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
91 |
def GetAttrByRow(self, row, col, attr): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
92 |
if col == 5: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
93 |
attr.SetColour('blue') |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
94 |
attr.SetBold(True) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
95 |
return True |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
96 |
return False |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
97 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
98 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
99 |
def DeleteRows(self, rows): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
100 |
# make a copy since we'll be sorting(mutating) the list |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
101 |
# use reverse order so the indexes don't change as we remove items |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
102 |
rows = sorted(rows, reverse=True) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
103 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
104 |
for row in rows: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
105 |
# remove it from our data structure |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
106 |
del self.data[row] |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
107 |
# notify the view(s) using this model that it has been removed |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
108 |
self.RowDeleted(row) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
109 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
110 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
111 |
def AddRow(self, value): |
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:
3377
diff
changeset
|
112 |
if self.data.append(value): |
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:
3377
diff
changeset
|
113 |
# notify views |
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:
3377
diff
changeset
|
114 |
self.RowAppended() |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
115 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
116 |
def ResetData(self): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
117 |
self.Reset(len(self.data)) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
118 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
119 |
OPCUAClientDndMagicWord = "text/beremiz-opcuaclient" |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
120 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
121 |
class NodeDropTarget(wx.DropTarget): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
122 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
123 |
def __init__(self, parent): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
124 |
data = wx.CustomDataObject(OPCUAClientDndMagicWord) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
125 |
wx.DropTarget.__init__(self, data) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
126 |
self.ParentWindow = parent |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
127 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
128 |
def OnDrop(self, x, y): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
129 |
self.ParentWindow.OnNodeDnD() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
130 |
return True |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
131 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
132 |
class OPCUASubListPanel(wx.Panel): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
133 |
def __init__(self, parent, log, model, direction): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
134 |
self.log = log |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
135 |
wx.Panel.__init__(self, parent, -1) |
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 |
self.dvc = dv.DataViewCtrl(self, |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
138 |
style=wx.BORDER_THEME |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
139 |
| dv.DV_ROW_LINES |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
140 |
| dv.DV_HORIZ_RULES |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
141 |
| dv.DV_VERT_RULES |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
142 |
| dv.DV_MULTIPLE |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
143 |
) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
144 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
145 |
self.model = model |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
146 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
147 |
self.dvc.AssociateModel(self.model) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
148 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
149 |
for idx,(colname,width) in enumerate(zip(lstcolnames,lstcolwidths)): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
150 |
self.dvc.AppendTextColumn(colname, idx, width=width, mode=dv.DATAVIEW_CELL_EDITABLE) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
151 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
152 |
DropTarget = NodeDropTarget(self) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
153 |
self.dvc.SetDropTarget(DropTarget) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
154 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
155 |
self.Sizer = wx.BoxSizer(wx.VERTICAL) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
156 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
157 |
self.direction = direction |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
158 |
titlestr = direction + " variables" |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
159 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
160 |
title = wx.StaticText(self, label = titlestr) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
161 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
162 |
delbt = wx.Button(self, label="Delete Row(s)") |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
163 |
self.Bind(wx.EVT_BUTTON, self.OnDeleteRows, delbt) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
164 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
165 |
topsizer = wx.BoxSizer(wx.HORIZONTAL) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
166 |
topsizer.Add(title, 1, wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, 5) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
167 |
topsizer.Add(delbt, 0, wx.LEFT|wx.RIGHT, 5) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
168 |
self.Sizer.Add(topsizer, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
169 |
self.Sizer.Add(self.dvc, 1, wx.EXPAND) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
170 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
171 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
172 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
173 |
def OnDeleteRows(self, evt): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
174 |
items = self.dvc.GetSelections() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
175 |
rows = [self.model.GetRow(item) for item in items] |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
176 |
self.model.DeleteRows(rows) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
177 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
178 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
179 |
def OnNodeDnD(self): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
180 |
# Have to find OPC-UA client extension panel from here |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
181 |
# in order to avoid keeping reference (otherwise __del__ isn't called) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
182 |
# splitter. panel. splitter |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
183 |
ClientPanel = self.GetParent().GetParent().GetParent() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
184 |
nodes = ClientPanel.GetSelectedNodes() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
185 |
for node in nodes: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
186 |
cname = node.get_node_class().name |
3377
c25a752b664e
OPC-UA: Removed more "LocalizedText()", this time in selected variable list
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3369
diff
changeset
|
187 |
dname = node.get_display_name().Text |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
188 |
if cname != "Variable": |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
189 |
self.log("Node {} ignored (not a variable)".format(dname)) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
190 |
continue |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
191 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
192 |
tname = node.get_data_type_as_variant_type().name |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
193 |
if tname not in UA_IEC_types: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
194 |
self.log("Node {} ignored (unsupported type)".format(dname)) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
195 |
continue |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
196 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
197 |
access = node.get_access_level() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
198 |
if {"input":ua.AccessLevel.CurrentRead, |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
199 |
"output":ua.AccessLevel.CurrentWrite}[self.direction] not in access: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
200 |
self.log("Node {} ignored because of insuficient access rights".format(dname)) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
201 |
continue |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
202 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
203 |
nsid = node.nodeid.NamespaceIndex |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
204 |
nid = node.nodeid.Identifier |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
205 |
nid_type = type(nid).__name__ |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
206 |
iecid = nid |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
207 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
208 |
value = [dname, |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
209 |
nsid, |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
210 |
nid_type, |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
211 |
nid, |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
212 |
tname, |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
213 |
iecid] |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
214 |
self.model.AddRow(value) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
215 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
216 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
217 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
218 |
il = None |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
219 |
fldridx = None |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
220 |
fldropenidx = None |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
221 |
fileidx = None |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
222 |
smileidx = None |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
223 |
isz = (16,16) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
224 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
225 |
treecolnames = [ "Name", "Class", "NSIdx", "Id"] |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
226 |
treecolwidths = [ 250, 100, 50, 200] |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
227 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
228 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
229 |
def prepare_image_list(): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
230 |
global il, fldridx, fldropenidx, fileidx, smileidx |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
231 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
232 |
if il is not None: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
233 |
return |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
234 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
235 |
il = wx.ImageList(isz[0], isz[1]) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
236 |
fldridx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz)) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
237 |
fldropenidx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, isz)) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
238 |
fileidx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, isz)) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
239 |
smileidx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_ADD_BOOKMARK, wx.ART_OTHER, isz)) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
240 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
241 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
242 |
class OPCUAClientPanel(wx.SplitterWindow): |
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
243 |
def __init__(self, parent, modeldata, log, config_getter): |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
244 |
self.log = log |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
245 |
wx.SplitterWindow.__init__(self, parent, -1) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
246 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
247 |
self.ordered_nodes = [] |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
248 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
249 |
self.inout_panel = wx.Panel(self) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
250 |
self.inout_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
251 |
self.inout_sizer.AddGrowableCol(0) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
252 |
self.inout_sizer.AddGrowableRow(1) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
253 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
254 |
self.client = None |
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
255 |
self.config_getter = config_getter |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
256 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
257 |
self.connect_button = wx.ToggleButton(self.inout_panel, -1, "Browse Server") |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
258 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
259 |
self.selected_splitter = wx.SplitterWindow(self.inout_panel, style=wx.SUNKEN_BORDER | wx.SP_3D) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
260 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
261 |
self.selected_datas = modeldata |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
262 |
self.selected_models = { direction:OPCUASubListModel(self.selected_datas[direction], log) for direction in directions } |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
263 |
self.selected_lists = { direction:OPCUASubListPanel( |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
264 |
self.selected_splitter, log, |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
265 |
self.selected_models[direction], direction) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
266 |
for direction in directions } |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
267 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
268 |
self.selected_splitter.SplitHorizontally(*[self.selected_lists[direction] for direction in directions]+[300]) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
269 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
270 |
self.inout_sizer.Add(self.connect_button, flag=wx.GROW) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
271 |
self.inout_sizer.Add(self.selected_splitter, flag=wx.GROW) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
272 |
self.inout_sizer.Layout() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
273 |
self.inout_panel.SetAutoLayout(True) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
274 |
self.inout_panel.SetSizer(self.inout_sizer) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
275 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
276 |
self.Initialize(self.inout_panel) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
277 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
278 |
self.Bind(wx.EVT_TOGGLEBUTTON, self.OnConnectButton, self.connect_button) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
279 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
280 |
def OnClose(self): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
281 |
if self.client is not None: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
282 |
self.client.disconnect() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
283 |
self.client = None |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
284 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
285 |
def __del__(self): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
286 |
self.OnClose() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
287 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
288 |
def OnConnectButton(self, event): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
289 |
if self.connect_button.GetValue(): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
290 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
291 |
self.tree_panel = wx.Panel(self) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
292 |
self.tree_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
293 |
self.tree_sizer.AddGrowableCol(0) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
294 |
self.tree_sizer.AddGrowableRow(0) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
295 |
|
3371
d486b98d7005
Backed out changeset c646a1f0fb0b - was on wrong branch
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3369
diff
changeset
|
296 |
self.tree = gizmos.TreeListCtrl(self.tree_panel, -1, style=0, agwStyle= |
d486b98d7005
Backed out changeset c646a1f0fb0b - was on wrong branch
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3369
diff
changeset
|
297 |
gizmos.TR_DEFAULT_STYLE |
d486b98d7005
Backed out changeset c646a1f0fb0b - was on wrong branch
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3369
diff
changeset
|
298 |
| gizmos.TR_MULTIPLE |
d486b98d7005
Backed out changeset c646a1f0fb0b - was on wrong branch
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3369
diff
changeset
|
299 |
| gizmos.TR_FULL_ROW_HIGHLIGHT |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
300 |
) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
301 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
302 |
prepare_image_list() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
303 |
self.tree.SetImageList(il) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
304 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
305 |
for idx,(colname, width) in enumerate(zip(treecolnames, treecolwidths)): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
306 |
self.tree.AddColumn(colname) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
307 |
self.tree.SetColumnWidth(idx, width) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
308 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
309 |
self.tree.SetMainColumn(0) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
310 |
|
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
311 |
config = self.config_getter() |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
312 |
self.client = Client(config["URI"]) |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
313 |
|
3591
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
314 |
AuthType = config["AuthType"] |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
315 |
if AuthType=="UserPasword": |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
316 |
self.client.set_user(config["User"]) |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
317 |
self.client.set_password(config["Password"]) |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
318 |
elif AuthType=="x509": |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
319 |
self.client.set_security_string( |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
320 |
"{Policy},{Mode},{Certificate},{PrivateKey}".format(**config)) |
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
321 |
|
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
322 |
self.client.connect() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
323 |
self.client.load_type_definitions() # load definition of server specific structures/extension objects |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
324 |
rootnode = self.client.get_root_node() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
325 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
326 |
rootitem = self.AddNodeItem(self.tree.AddRoot, rootnode) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
327 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
328 |
# Populate first level so that root can be expanded |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
329 |
self.CreateSubItems(rootitem) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
330 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
331 |
self.tree.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnExpand) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
332 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
333 |
self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnTreeNodeSelection) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
334 |
self.tree.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnTreeBeginDrag) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
335 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
336 |
self.tree.Expand(rootitem) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
337 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
338 |
hint = wx.StaticText(self, label = "Drag'n'drop desired variables from tree to Input or Output list") |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
339 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
340 |
self.tree_sizer.Add(self.tree, flag=wx.GROW) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
341 |
self.tree_sizer.Add(hint, flag=wx.GROW) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
342 |
self.tree_sizer.Layout() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
343 |
self.tree_panel.SetAutoLayout(True) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
344 |
self.tree_panel.SetSizer(self.tree_sizer) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
345 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
346 |
self.SplitVertically(self.tree_panel, self.inout_panel, 500) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
347 |
else: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
348 |
self.client.disconnect() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
349 |
self.client = None |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
350 |
self.Unsplit(self.tree_panel) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
351 |
self.tree_panel.Destroy() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
352 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
353 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
354 |
def CreateSubItems(self, item): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
355 |
node, browsed = self.tree.GetPyData(item) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
356 |
if not browsed: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
357 |
for subnode in node.get_children(): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
358 |
self.AddNodeItem(lambda n: self.tree.AppendItem(item, n), subnode) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
359 |
self.tree.SetPyData(item,(node, True)) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
360 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
361 |
def AddNodeItem(self, item_creation_func, node): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
362 |
nsid = node.nodeid.NamespaceIndex |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
363 |
nid = node.nodeid.Identifier |
3340
a13da70a8ae4
OPCUA: fix display names appearing with a "LocalizedText(" prefix when browsing localized server.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3338
diff
changeset
|
364 |
dname = node.get_display_name().Text |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
365 |
cname = node.get_node_class().name |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
366 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
367 |
item = item_creation_func(dname) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
368 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
369 |
if cname == "Variable": |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
370 |
access = node.get_access_level() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
371 |
normalidx = fileidx |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
372 |
r = ua.AccessLevel.CurrentRead in access |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
373 |
w = ua.AccessLevel.CurrentWrite in access |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
374 |
if r and w: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
375 |
ext = "RW" |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
376 |
elif r: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
377 |
ext = "RO" |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
378 |
elif w: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
379 |
ext = "WO" # not sure this one exist |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
380 |
else: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
381 |
ext = "no access" # not sure this one exist |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
382 |
cname = "Var "+node.get_data_type_as_variant_type().name+" (" + ext + ")" |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
383 |
else: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
384 |
normalidx = fldridx |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
385 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
386 |
self.tree.SetPyData(item,(node, False)) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
387 |
self.tree.SetItemText(item, cname, 1) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
388 |
self.tree.SetItemText(item, str(nsid), 2) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
389 |
self.tree.SetItemText(item, type(nid).__name__+": "+str(nid), 3) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
390 |
self.tree.SetItemImage(item, normalidx, which = wx.TreeItemIcon_Normal) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
391 |
self.tree.SetItemImage(item, fldropenidx, which = wx.TreeItemIcon_Expanded) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
392 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
393 |
return item |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
394 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
395 |
def OnExpand(self, evt): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
396 |
for item in evt.GetItem().GetChildren(): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
397 |
self.CreateSubItems(item) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
398 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
399 |
# def OnActivate(self, evt): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
400 |
# item = evt.GetItem() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
401 |
# node, browsed = self.tree.GetPyData(item) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
402 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
403 |
def OnTreeNodeSelection(self, event): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
404 |
items = self.tree.GetSelections() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
405 |
items_pydata = [self.tree.GetPyData(item) for item in items] |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
406 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
407 |
nodes = [node for node, _unused in items_pydata] |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
408 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
409 |
# append new nodes to ordered list |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
410 |
for node in nodes: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
411 |
if node not in self.ordered_nodes: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
412 |
self.ordered_nodes.append(node) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
413 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
414 |
# filter out vanished items |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
415 |
self.ordered_nodes = [ |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
416 |
node |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
417 |
for node in self.ordered_nodes |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
418 |
if node in nodes] |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
419 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
420 |
def GetSelectedNodes(self): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
421 |
return self.ordered_nodes |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
422 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
423 |
def OnTreeBeginDrag(self, event): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
424 |
""" |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
425 |
Called when a drag is started in tree |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
426 |
@param event: wx.TreeEvent |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
427 |
""" |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
428 |
if self.ordered_nodes: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
429 |
# Just send a recognizable mime-type, drop destination |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
430 |
# will get python data from parent |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
431 |
data = wx.CustomDataObject(OPCUAClientDndMagicWord) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
432 |
dragSource = wx.DropSource(self) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
433 |
dragSource.SetData(data) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
434 |
dragSource.DoDragDrop() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
435 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
436 |
def Reset(self): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
437 |
for direction in directions: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
438 |
self.selected_models[direction].ResetData() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
439 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
440 |
|
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:
3377
diff
changeset
|
441 |
class OPCUAClientList(list): |
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:
3377
diff
changeset
|
442 |
def __init__(self, log = lambda m:None): |
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:
3377
diff
changeset
|
443 |
super(OPCUAClientList, self).__init__(self) |
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:
3377
diff
changeset
|
444 |
self.log = log |
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:
3377
diff
changeset
|
445 |
|
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:
3377
diff
changeset
|
446 |
def append(self, value): |
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:
3377
diff
changeset
|
447 |
v = dict(zip(lstcolnames, value)) |
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:
3377
diff
changeset
|
448 |
|
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:
3377
diff
changeset
|
449 |
if type(v["IEC"]) != int: |
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:
3377
diff
changeset
|
450 |
if len(self) == 0: |
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:
3377
diff
changeset
|
451 |
v["IEC"] = 0 |
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:
3377
diff
changeset
|
452 |
else: |
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:
3377
diff
changeset
|
453 |
iecnums = set(zip(*self)[lstcolnames.index("IEC")]) |
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:
3377
diff
changeset
|
454 |
greatest = max(iecnums) |
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:
3377
diff
changeset
|
455 |
holes = set(range(greatest)) - iecnums |
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:
3377
diff
changeset
|
456 |
v["IEC"] = min(holes) if holes else greatest+1 |
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:
3377
diff
changeset
|
457 |
|
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:
3377
diff
changeset
|
458 |
if v["IdType"] not in UA_NODE_ID_types: |
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:
3377
diff
changeset
|
459 |
self.log("Unknown IdType\n".format(value)) |
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:
3377
diff
changeset
|
460 |
return False |
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:
3377
diff
changeset
|
461 |
|
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:
3377
diff
changeset
|
462 |
try: |
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:
3377
diff
changeset
|
463 |
for t,n in zip(lstcoltypess, lstcolnames): |
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:
3377
diff
changeset
|
464 |
v[n] = t(v[n]) |
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:
3377
diff
changeset
|
465 |
except ValueError: |
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:
3377
diff
changeset
|
466 |
self.log("Variable {} (Id={}) has invalid type\n".format(v["Name"],v["Id"])) |
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:
3377
diff
changeset
|
467 |
return False |
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:
3377
diff
changeset
|
468 |
|
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:
3377
diff
changeset
|
469 |
if len(self)>0 and v["Id"] in zip(*self)[lstcolnames.index("Id")]: |
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:
3377
diff
changeset
|
470 |
self.log("Variable {} (Id={}) already in list\n".format(v["Name"],v["Id"])) |
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:
3377
diff
changeset
|
471 |
return False |
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:
3377
diff
changeset
|
472 |
|
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:
3377
diff
changeset
|
473 |
list.append(self, [v[n] for n in lstcolnames]) |
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:
3377
diff
changeset
|
474 |
|
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:
3377
diff
changeset
|
475 |
return True |
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:
3377
diff
changeset
|
476 |
|
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
477 |
class OPCUAClientModel(dict): |
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:
3377
diff
changeset
|
478 |
def __init__(self, log = lambda m:None): |
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:
3377
diff
changeset
|
479 |
super(OPCUAClientModel, self).__init__() |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
480 |
for direction in directions: |
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:
3377
diff
changeset
|
481 |
self[direction] = OPCUAClientList(log) |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
482 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
483 |
def LoadCSV(self,path): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
484 |
with open(path, 'rb') as csvfile: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
485 |
reader = csv.reader(csvfile, delimiter=',', quotechar='"') |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
486 |
buf = {direction:[] for direction, _model in self.iteritems()} |
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:
3377
diff
changeset
|
487 |
for direction, model in self.iteritems(): |
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:
3377
diff
changeset
|
488 |
self[direction][:] = [] |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
489 |
for row in reader: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
490 |
direction = row[0] |
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:
3377
diff
changeset
|
491 |
self[direction].append(row[1:]) |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
492 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
493 |
def SaveCSV(self,path): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
494 |
with open(path, 'wb') as csvfile: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
495 |
for direction, data in self.iteritems(): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
496 |
writer = csv.writer(csvfile, delimiter=',', |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
497 |
quotechar='"', quoting=csv.QUOTE_MINIMAL) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
498 |
for row in data: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
499 |
writer.writerow([direction] + row) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
500 |
|
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
501 |
def GenerateC(self, path, locstr, config): |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
502 |
template = """/* code generated by beremiz OPC-UA extension */ |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
503 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
504 |
#include <open62541/client_config_default.h> |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
505 |
#include <open62541/client_highlevel.h> |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
506 |
#include <open62541/plugin/log_stdout.h> |
3591
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
507 |
#include <open62541/plugin/securitypolicy.h> |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
508 |
|
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
509 |
#include <open62541/types.h> |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
510 |
#include <open62541/types_generated_handling.h> |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
511 |
|
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
512 |
static UA_INLINE UA_ByteString |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
513 |
loadFile(const char *const path) {{ |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
514 |
UA_ByteString fileContents = UA_STRING_NULL; |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
515 |
|
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
516 |
FILE *fp = fopen(path, "rb"); |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
517 |
if(!fp) {{ |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
518 |
errno = 0; |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
519 |
return fileContents; |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
520 |
}} |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
521 |
|
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
522 |
fseek(fp, 0, SEEK_END); |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
523 |
fileContents.length = (size_t)ftell(fp); |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
524 |
fileContents.data = (UA_Byte *)UA_malloc(fileContents.length * sizeof(UA_Byte)); |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
525 |
if(fileContents.data) {{ |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
526 |
fseek(fp, 0, SEEK_SET); |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
527 |
size_t read = fread(fileContents.data, sizeof(UA_Byte), fileContents.length, fp); |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
528 |
if(read != fileContents.length) |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
529 |
UA_ByteString_clear(&fileContents); |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
530 |
}} else {{ |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
531 |
fileContents.length = 0; |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
532 |
}} |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
533 |
fclose(fp); |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
534 |
|
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
535 |
return fileContents; |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
536 |
}} |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
537 |
|
3407
2f5c30054d50
OPC-UA client: "static" class was forgotten for open62541 client structure preventing multiple client.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3406
diff
changeset
|
538 |
static UA_Client *client; |
3591
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
539 |
static UA_ClientConfig *cc; |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
540 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
541 |
#define DECL_VAR(ua_type, C_type, c_loc_name) \\ |
3407
2f5c30054d50
OPC-UA client: "static" class was forgotten for open62541 client structure preventing multiple client.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3406
diff
changeset
|
542 |
static UA_Variant c_loc_name##_variant; \\ |
2f5c30054d50
OPC-UA client: "static" class was forgotten for open62541 client structure preventing multiple client.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3406
diff
changeset
|
543 |
static C_type c_loc_name##_buf = 0; \\ |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
544 |
C_type *c_loc_name = &c_loc_name##_buf; |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
545 |
|
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
546 |
{decl} |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
547 |
|
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
548 |
void __cleanup_{locstr}(void) |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
549 |
{{ |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
550 |
UA_Client_disconnect(client); |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
551 |
UA_Client_delete(client); |
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
552 |
}} |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
553 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
554 |
|
3612
428fb2472f43
OPC-UA: add logging to help user to understang what went wrong when connecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3591
diff
changeset
|
555 |
#define _Log(level, ...) \\ |
428fb2472f43
OPC-UA: add logging to help user to understang what went wrong when connecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3591
diff
changeset
|
556 |
{{ \\ |
428fb2472f43
OPC-UA: add logging to help user to understang what went wrong when connecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3591
diff
changeset
|
557 |
char mstr[256]; \\ |
428fb2472f43
OPC-UA: add logging to help user to understang what went wrong when connecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3591
diff
changeset
|
558 |
snprintf(mstr, 255, __VA_ARGS__); \\ |
428fb2472f43
OPC-UA: add logging to help user to understang what went wrong when connecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3591
diff
changeset
|
559 |
LogMessage(level, mstr, strlen(mstr)); \\ |
428fb2472f43
OPC-UA: add logging to help user to understang what went wrong when connecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3591
diff
changeset
|
560 |
}} |
428fb2472f43
OPC-UA: add logging to help user to understang what went wrong when connecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3591
diff
changeset
|
561 |
|
428fb2472f43
OPC-UA: add logging to help user to understang what went wrong when connecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3591
diff
changeset
|
562 |
#define LogInfo(...) _Log(LOG_INFO, __VA_ARGS__); |
428fb2472f43
OPC-UA: add logging to help user to understang what went wrong when connecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3591
diff
changeset
|
563 |
#define LogError(...) _Log(LOG_CRITICAL, __VA_ARGS__); |
428fb2472f43
OPC-UA: add logging to help user to understang what went wrong when connecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3591
diff
changeset
|
564 |
#define LogWarning(...) _Log(LOG_WARNING, __VA_ARGS__); |
428fb2472f43
OPC-UA: add logging to help user to understang what went wrong when connecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3591
diff
changeset
|
565 |
|
3591
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
566 |
#define INIT_NoAuth() \\ |
3620
1cf21430ed4a
OPCUA: cosmetic fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3612
diff
changeset
|
567 |
LogInfo("OPC-UA Init no auth"); \\ |
3591
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
568 |
UA_ClientConfig_setDefault(cc); \\ |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
569 |
retval = UA_Client_connect(client, uri); |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
570 |
|
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
571 |
/* Note : Policy is ignored here since open62541 client supports all policies by default */ |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
572 |
#define INIT_x509(Policy, UpperCaseMode, PrivateKey, Certificate) \\ |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
573 |
/* TODO try paths given in runtime CLI */ \\ |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
574 |
UA_ByteString certificate = loadFile(Certificate); \\ |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
575 |
UA_ByteString privateKey = loadFile(PrivateKey); \\ |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
576 |
\\ |
3620
1cf21430ed4a
OPCUA: cosmetic fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3612
diff
changeset
|
577 |
LogInfo("OPC-UA Init x509 %s,%s,%s,%s", #Policy, #UpperCaseMode, PrivateKey, Certificate); \\ |
3591
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
578 |
cc->securityMode = UA_MESSAGESECURITYMODE_##UpperCaseMode; \\ |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
579 |
UA_ClientConfig_setDefaultEncryption(cc, certificate, privateKey, NULL, 0, NULL, 0); \\ |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
580 |
\\ |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
581 |
retval = UA_Client_connect(client, uri); \\ |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
582 |
\\ |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
583 |
UA_ByteString_clear(&certificate); \\ |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
584 |
UA_ByteString_clear(&privateKey); |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
585 |
|
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
586 |
#define INIT_UserPassword(User, Password) \\ |
3620
1cf21430ed4a
OPCUA: cosmetic fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3612
diff
changeset
|
587 |
LogInfo("OPC-UA Init UserPassword %s,%s", User, Password); \\ |
3612
428fb2472f43
OPC-UA: add logging to help user to understang what went wrong when connecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3591
diff
changeset
|
588 |
UA_ClientConfig_setDefault(cc); \\ |
3591
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
589 |
retval = UA_Client_connectUsername(client, uri, User, Password); |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
590 |
|
3406
3aac4241dafa
OPC-UA: cosmetic fix and armless typo
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3392
diff
changeset
|
591 |
#define INIT_READ_VARIANT(ua_type, c_loc_name) \\ |
3392
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
592 |
UA_Variant_init(&c_loc_name##_variant); |
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
593 |
|
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
594 |
#define INIT_WRITE_VARIANT(ua_type, ua_type_enum, c_loc_name) \\ |
3392
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
595 |
UA_Variant_setScalar(&c_loc_name##_variant, (ua_type*)c_loc_name, &UA_TYPES[ua_type_enum]); |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
596 |
|
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
597 |
int __init_{locstr}(int argc,char **argv) |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
598 |
{{ |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
599 |
UA_StatusCode retval; |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
600 |
client = UA_Client_new(); |
3591
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
601 |
cc = UA_Client_getConfig(client); |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
602 |
char *uri = "{uri}"; |
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
603 |
{init} |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
604 |
|
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
605 |
if(retval != UA_STATUSCODE_GOOD) {{ |
3620
1cf21430ed4a
OPCUA: cosmetic fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3612
diff
changeset
|
606 |
LogError("OPC-UA Init Failed %d", retval); |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
607 |
UA_Client_delete(client); |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
608 |
return EXIT_FAILURE; |
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
609 |
}} |
3612
428fb2472f43
OPC-UA: add logging to help user to understang what went wrong when connecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3591
diff
changeset
|
610 |
return 0; |
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
611 |
}} |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
612 |
|
3392
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
613 |
#define READ_VALUE(ua_type, ua_type_enum, c_loc_name, ua_nodeid_type, ua_nsidx, ua_node_id) \\ |
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
614 |
retval = UA_Client_readValueAttribute( \\ |
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
615 |
client, ua_nodeid_type(ua_nsidx, ua_node_id), &c_loc_name##_variant); \\ |
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
616 |
if(retval == UA_STATUSCODE_GOOD && UA_Variant_isScalar(&c_loc_name##_variant) && \\ |
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
617 |
c_loc_name##_variant.type == &UA_TYPES[ua_type_enum]) {{ \\ |
3392
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
618 |
c_loc_name##_buf = *(ua_type*)c_loc_name##_variant.data; \\ |
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
619 |
UA_Variant_clear(&c_loc_name##_variant); /* Unalloc requiered on each read ! */ \\ |
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
620 |
}} |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
621 |
|
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
622 |
void __retrieve_{locstr}(void) |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
623 |
{{ |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
624 |
UA_StatusCode retval; |
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
625 |
{retrieve} |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
626 |
}} |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
627 |
|
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
628 |
#define WRITE_VALUE(ua_type, c_loc_name, ua_nodeid_type, ua_nsidx, ua_node_id) \\ |
3392
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
629 |
UA_Client_writeValueAttribute( \\ |
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
630 |
client, ua_nodeid_type(ua_nsidx, ua_node_id), &c_loc_name##_variant); |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
631 |
|
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
632 |
void __publish_{locstr}(void) |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
633 |
{{ |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
634 |
{publish} |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
635 |
}} |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
636 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
637 |
""" |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
638 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
639 |
formatdict = dict( |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
640 |
locstr = locstr, |
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
641 |
uri = config["URI"], |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
642 |
decl = "", |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
643 |
cleanup = "", |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
644 |
init = "", |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
645 |
retrieve = "", |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
646 |
publish = "" |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
647 |
) |
3591
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
648 |
|
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
649 |
AuthType = config["AuthType"] |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
650 |
if AuthType == "x509": |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
651 |
config["UpperCaseMode"] = config["Mode"].upper() |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
652 |
formatdict["init"] += """ |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
653 |
INIT_x509({Policy}, {UpperCaseMode}, "{PrivateKey}", "{Certificate}")""".format(**config) |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
654 |
elif AuthType == "UserPassword": |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
655 |
formatdict["init"] += """ |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
656 |
INIT_UserPassword("{User}", "{Password}")""".format(**config) |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
657 |
else: |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
658 |
formatdict["init"] += """ |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
659 |
INIT_NoAuth()""" |
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
660 |
|
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
661 |
for direction, data in self.iteritems(): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
662 |
iec_direction_prefix = {"input": "__I", "output": "__Q"}[direction] |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
663 |
for row in data: |
3338
fe0da9a8a225
OPCUS client: fix handling of string type Node Identifier
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
664 |
name, ua_nsidx, ua_nodeid_type, _ua_node_id, ua_type, iec_number = row |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
665 |
iec_type, C_type, iec_size_prefix, ua_type_enum, ua_type = UA_IEC_types[ua_type] |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
666 |
c_loc_name = iec_direction_prefix + iec_size_prefix + locstr + "_" + str(iec_number) |
3338
fe0da9a8a225
OPCUS client: fix handling of string type Node Identifier
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
667 |
ua_nodeid_type, id_formating = UA_NODE_ID_types[ua_nodeid_type] |
fe0da9a8a225
OPCUS client: fix handling of string type Node Identifier
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3337
diff
changeset
|
668 |
ua_node_id = id_formating.format(_ua_node_id) |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
669 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
670 |
formatdict["decl"] += """ |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
671 |
DECL_VAR({ua_type}, {C_type}, {c_loc_name})""".format(**locals()) |
3392
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
672 |
|
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
673 |
if direction == "input": |
3591
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
674 |
formatdict["init"] += """ |
3392
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
675 |
INIT_READ_VARIANT({ua_type}, {c_loc_name})""".format(**locals()) |
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
676 |
formatdict["retrieve"] += """ |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
677 |
READ_VALUE({ua_type}, {ua_type_enum}, {c_loc_name}, {ua_nodeid_type}, {ua_nsidx}, {ua_node_id})""".format(**locals()) |
3392
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
678 |
|
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
679 |
if direction == "output": |
3591
50600b946ea7
OPC-US client: add support for x509 and user+password authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3589
diff
changeset
|
680 |
formatdict["init"] += """ |
3392
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
681 |
INIT_WRITE_VARIANT({ua_type}, {ua_type_enum}, {c_loc_name})""".format(**locals()) |
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
682 |
formatdict["publish"] += """ |
4353c56a53d1
OPC-UA client: generated code now take UA_Variants on the stack directly, avoid useless allocation on write, and unalloc implicitely allocated data on read
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3378
diff
changeset
|
683 |
WRITE_VALUE({ua_type}, {c_loc_name}, {ua_nodeid_type}, {ua_nsidx}, {ua_node_id})""".format(**locals()) |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
684 |
|
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
685 |
Ccode = template.format(**formatdict) |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
686 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
687 |
return Ccode |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
688 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
689 |
if __name__ == "__main__": |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
690 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
691 |
import wx.lib.mixins.inspection as wit |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
692 |
import sys,os |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
693 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
694 |
app = wit.InspectableApp() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
695 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
696 |
frame = wx.Frame(None, -1, "OPCUA Client Test App", size=(800,600)) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
697 |
|
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
698 |
argc = len(sys.argv) |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
699 |
|
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
700 |
config={} |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
701 |
config["URI"] = sys.argv[1] if argc>1 else "opc.tcp://localhost:4840" |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
702 |
|
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
703 |
if argc > 2: |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
704 |
AuthType = sys.argv[2] |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
705 |
config["AuthType"] = AuthType |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
706 |
for (name, default), value in izip_longest(authParams[AuthType], sys.argv[3:]): |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
707 |
if value is None: |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
708 |
if default is None: |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
709 |
raise Exception(name+" param expected") |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
710 |
value = default |
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
711 |
config[name] = value |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
712 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
713 |
test_panel = wx.Panel(frame) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
714 |
test_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
715 |
test_sizer.AddGrowableCol(0) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
716 |
test_sizer.AddGrowableRow(0) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
717 |
|
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:
3377
diff
changeset
|
718 |
modeldata = OPCUAClientModel(print) |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
719 |
|
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
720 |
opcuatestpanel = OPCUAClientPanel(test_panel, modeldata, print, lambda:config) |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
721 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
722 |
def OnGenerate(evt): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
723 |
dlg = wx.FileDialog( |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
724 |
frame, message="Generate file as ...", defaultDir=os.getcwd(), |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
725 |
defaultFile="", |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
726 |
wildcard="C (*.c)|*.c", style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
727 |
) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
728 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
729 |
if dlg.ShowModal() == wx.ID_OK: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
730 |
path = dlg.GetPath() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
731 |
Ccode = """ |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
732 |
/* |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
733 |
In case open62541 was built just aside beremiz, you can build this test with: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
734 |
gcc %s -o %s \\ |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
735 |
-I ../../open62541/plugins/include/ \\ |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
736 |
-I ../../open62541/build/src_generated/ \\ |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
737 |
-I ../../open62541/include/ \\ |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
738 |
-I ../../open62541/arch/ ../../open62541/build/bin/libopen62541.a |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
739 |
*/ |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
740 |
|
3589
a0b645a934c9
OPC-UA, IDE: add CTN parameters to support OPC-UA encryption and authentication.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3422
diff
changeset
|
741 |
"""%(path, path[:-2]) + modeldata.GenerateC(path, "test", config) + """ |
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
742 |
|
3612
428fb2472f43
OPC-UA: add logging to help user to understang what went wrong when connecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3591
diff
changeset
|
743 |
int LogMessage(uint8_t level, char* buf, uint32_t size){ |
3620
1cf21430ed4a
OPCUA: cosmetic fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3612
diff
changeset
|
744 |
printf("log level:%d message:'%.*s'\\n", level, size, buf); |
3612
428fb2472f43
OPC-UA: add logging to help user to understang what went wrong when connecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3591
diff
changeset
|
745 |
}; |
428fb2472f43
OPC-UA: add logging to help user to understang what went wrong when connecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3591
diff
changeset
|
746 |
|
3337
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
747 |
int main(int argc, char *argv[]) { |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
748 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
749 |
__init_test(arc,argv); |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
750 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
751 |
__retrieve_test(); |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
752 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
753 |
__publish_test(); |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
754 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
755 |
__cleanup_test(); |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
756 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
757 |
return EXIT_SUCCESS; |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
758 |
} |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
759 |
""" |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
760 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
761 |
with open(path, 'wb') as Cfile: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
762 |
Cfile.write(Ccode) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
763 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
764 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
765 |
dlg.Destroy() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
766 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
767 |
def OnLoad(evt): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
768 |
dlg = wx.FileDialog( |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
769 |
frame, message="Choose a file", |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
770 |
defaultDir=os.getcwd(), |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
771 |
defaultFile="", |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
772 |
wildcard="CSV (*.csv)|*.csv", |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
773 |
style=wx.FD_OPEN | wx.FD_CHANGE_DIR | wx.FD_FILE_MUST_EXIST ) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
774 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
775 |
if dlg.ShowModal() == wx.ID_OK: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
776 |
path = dlg.GetPath() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
777 |
modeldata.LoadCSV(path) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
778 |
opcuatestpanel.Reset() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
779 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
780 |
dlg.Destroy() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
781 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
782 |
def OnSave(evt): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
783 |
dlg = wx.FileDialog( |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
784 |
frame, message="Save file as ...", defaultDir=os.getcwd(), |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
785 |
defaultFile="", |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
786 |
wildcard="CSV (*.csv)|*.csv", style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
787 |
) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
788 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
789 |
if dlg.ShowModal() == wx.ID_OK: |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
790 |
path = dlg.GetPath() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
791 |
modeldata.SaveCSV(path) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
792 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
793 |
dlg.Destroy() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
794 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
795 |
test_sizer.Add(opcuatestpanel, flag=wx.GROW) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
796 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
797 |
testbt_sizer = wx.BoxSizer(wx.HORIZONTAL) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
798 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
799 |
loadbt = wx.Button(test_panel, label="Load") |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
800 |
test_panel.Bind(wx.EVT_BUTTON, OnLoad, loadbt) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
801 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
802 |
savebt = wx.Button(test_panel, label="Save") |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
803 |
test_panel.Bind(wx.EVT_BUTTON, OnSave, savebt) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
804 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
805 |
genbt = wx.Button(test_panel, label="Generate") |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
806 |
test_panel.Bind(wx.EVT_BUTTON, OnGenerate, genbt) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
807 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
808 |
testbt_sizer.Add(loadbt, 0, wx.LEFT|wx.RIGHT, 5) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
809 |
testbt_sizer.Add(savebt, 0, wx.LEFT|wx.RIGHT, 5) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
810 |
testbt_sizer.Add(genbt, 0, wx.LEFT|wx.RIGHT, 5) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
811 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
812 |
test_sizer.Add(testbt_sizer, flag=wx.GROW) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
813 |
test_sizer.Layout() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
814 |
test_panel.SetAutoLayout(True) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
815 |
test_panel.SetSizer(test_sizer) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
816 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
817 |
def OnClose(evt): |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
818 |
opcuatestpanel.OnClose() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
819 |
evt.Skip() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
820 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
821 |
frame.Bind(wx.EVT_CLOSE, OnClose) |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
822 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
823 |
frame.Show() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
824 |
|
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
825 |
app.MainLoop() |
6097bca230e8
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
826 |