author | Edouard Tisserant |
Thu, 09 Nov 2023 11:20:39 +0100 | |
changeset 3855 | beccb995b10e |
parent 3407 | 2f5c30054d50 |
child 3422 | 700b39cb4525 |
permissions | -rw-r--r-- |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
1 |
from __future__ import print_function |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
2 |
from __future__ import absolute_import |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
3 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
4 |
import csv |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
5 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
6 |
from opcua import Client |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
7 |
from opcua import ua |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
8 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
9 |
import wx |
3370
3c31dce1a661
Make OPC-UA client compatible with wxPython3, util wxPython4 branch deserve to be merged
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3367
diff
changeset
|
10 |
from wx.lib.agw.hypertreelist import HyperTreeList as TreeListCtrl |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
11 |
import wx.dataview as dv |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
12 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
13 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
14 |
UA_IEC_types = dict( |
fa2365fa6154
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 |
fa2365fa6154
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"), |
fa2365fa6154
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" ), |
fa2365fa6154
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" ), |
fa2365fa6154
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" ), |
fa2365fa6154
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" ), |
fa2365fa6154
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" ), |
fa2365fa6154
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" ), |
fa2365fa6154
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" ), |
fa2365fa6154
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" ), |
fa2365fa6154
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" ), |
fa2365fa6154
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" ), |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
27 |
) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
28 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
29 |
UA_NODE_ID_types = { |
3365
9f7c9051c9ba
OPCUA client: fix handling of string type Node Identifier
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3364
diff
changeset
|
30 |
"int" : ("UA_NODEID_NUMERIC", "{}" ), |
9f7c9051c9ba
OPCUA client: fix handling of string type Node Identifier
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3364
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" , '"{}"'), |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
33 |
} |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
34 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
35 |
lstcolnames = [ "Name", "NSIdx", "IdType", "Id", "Type", "IEC"] |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
36 |
lstcolwidths = [ 100, 50, 100, 100, 100, 50] |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
37 |
lstcoltypess = [ str, int, str, str, str, int] |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
38 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
39 |
directions = ["input", "output"] |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
40 |
|
3370
3c31dce1a661
Make OPC-UA client compatible with wxPython3, util wxPython4 branch deserve to be merged
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3367
diff
changeset
|
41 |
class OPCUASubListModel(dv.PyDataViewIndexListModel): |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
42 |
def __init__(self, data, log): |
3370
3c31dce1a661
Make OPC-UA client compatible with wxPython3, util wxPython4 branch deserve to be merged
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3367
diff
changeset
|
43 |
dv.PyDataViewIndexListModel.__init__(self, len(data)) |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
44 |
self.data = data |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
45 |
self.log = log |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
46 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
47 |
def GetColumnType(self, col): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
48 |
return "string" |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
49 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
50 |
def GetValueByRow(self, row, col): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
51 |
return str(self.data[row][col]) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
52 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
53 |
# This method is called when the user edits a data item in the view. |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
54 |
def SetValueByRow(self, value, row, col): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
55 |
expectedtype = lstcoltypess[col] |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
56 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
57 |
try: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
58 |
v = expectedtype(value) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
59 |
except ValueError: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
60 |
self.log("String {} is invalid for type {}\n".format(value,expectedtype.__name__)) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
61 |
return False |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
62 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
63 |
if col == lstcolnames.index("IdType") and v not in UA_NODE_ID_types: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
64 |
self.log("{} is invalid for IdType\n".format(value)) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
65 |
return False |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
66 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
67 |
self.data[row][col] = v |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
68 |
return True |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
69 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
70 |
# Report how many columns this model provides data for. |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
71 |
def GetColumnCount(self): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
72 |
return len(lstcolnames) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
73 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
74 |
# Report the number of rows in the model |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
75 |
def GetCount(self): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
76 |
#self.log.write('GetCount') |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
77 |
return len(self.data) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
78 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
79 |
# Called to check if non-standard attributes should be used in the |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
80 |
# cell at (row, col) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
81 |
def GetAttrByRow(self, row, col, attr): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
82 |
if col == 5: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
83 |
attr.SetColour('blue') |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
84 |
attr.SetBold(True) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
85 |
return True |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
86 |
return False |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
87 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
88 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
89 |
def DeleteRows(self, rows): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
90 |
# make a copy since we'll be sorting(mutating) the list |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
91 |
# use reverse order so the indexes don't change as we remove items |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
92 |
rows = sorted(rows, reverse=True) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
93 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
94 |
for row in rows: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
95 |
# remove it from our data structure |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
96 |
del self.data[row] |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
97 |
# notify the view(s) using this model that it has been removed |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
98 |
self.RowDeleted(row) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
99 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
100 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
101 |
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
|
102 |
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
|
103 |
# 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
|
104 |
self.RowAppended() |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
105 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
106 |
def ResetData(self): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
107 |
self.Reset(len(self.data)) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
108 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
109 |
OPCUAClientDndMagicWord = "text/beremiz-opcuaclient" |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
110 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
111 |
class NodeDropTarget(wx.DropTarget): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
112 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
113 |
def __init__(self, parent): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
114 |
data = wx.CustomDataObject(OPCUAClientDndMagicWord) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
115 |
wx.DropTarget.__init__(self, data) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
116 |
self.ParentWindow = parent |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
117 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
118 |
def OnDrop(self, x, y): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
119 |
self.ParentWindow.OnNodeDnD() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
120 |
return True |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
121 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
122 |
class OPCUASubListPanel(wx.Panel): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
123 |
def __init__(self, parent, log, model, direction): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
124 |
self.log = log |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
125 |
wx.Panel.__init__(self, parent, -1) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
126 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
127 |
self.dvc = dv.DataViewCtrl(self, |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
128 |
style=wx.BORDER_THEME |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
129 |
| dv.DV_ROW_LINES |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
130 |
| dv.DV_HORIZ_RULES |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
131 |
| dv.DV_VERT_RULES |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
132 |
| dv.DV_MULTIPLE |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
133 |
) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
134 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
135 |
self.model = model |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
136 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
137 |
self.dvc.AssociateModel(self.model) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
138 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
139 |
for idx,(colname,width) in enumerate(zip(lstcolnames,lstcolwidths)): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
140 |
self.dvc.AppendTextColumn(colname, idx, width=width, mode=dv.DATAVIEW_CELL_EDITABLE) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
141 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
142 |
DropTarget = NodeDropTarget(self) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
143 |
self.dvc.SetDropTarget(DropTarget) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
144 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
145 |
self.Sizer = wx.BoxSizer(wx.VERTICAL) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
146 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
147 |
self.direction = direction |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
148 |
titlestr = direction + " variables" |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
149 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
150 |
title = wx.StaticText(self, label = titlestr) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
151 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
152 |
delbt = wx.Button(self, label="Delete Row(s)") |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
153 |
self.Bind(wx.EVT_BUTTON, self.OnDeleteRows, delbt) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
154 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
155 |
topsizer = wx.BoxSizer(wx.HORIZONTAL) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
156 |
topsizer.Add(title, 1, wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, 5) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
157 |
topsizer.Add(delbt, 0, wx.LEFT|wx.RIGHT, 5) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
158 |
self.Sizer.Add(topsizer, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
159 |
self.Sizer.Add(self.dvc, 1, wx.EXPAND) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
160 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
161 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
162 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
163 |
def OnDeleteRows(self, evt): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
164 |
items = self.dvc.GetSelections() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
165 |
rows = [self.model.GetRow(item) for item in items] |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
166 |
self.model.DeleteRows(rows) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
167 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
168 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
169 |
def OnNodeDnD(self): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
170 |
# Have to find OPC-UA client extension panel from here |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
171 |
# in order to avoid keeping reference (otherwise __del__ isn't called) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
172 |
# splitter. panel. splitter |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
173 |
ClientPanel = self.GetParent().GetParent().GetParent() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
174 |
nodes = ClientPanel.GetSelectedNodes() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
175 |
for node in nodes: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
176 |
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:
3370
diff
changeset
|
177 |
dname = node.get_display_name().Text |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
178 |
if cname != "Variable": |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
179 |
self.log("Node {} ignored (not a variable)".format(dname)) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
180 |
continue |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
181 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
182 |
tname = node.get_data_type_as_variant_type().name |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
183 |
if tname not in UA_IEC_types: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
184 |
self.log("Node {} ignored (unsupported type)".format(dname)) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
185 |
continue |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
186 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
187 |
access = node.get_access_level() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
188 |
if {"input":ua.AccessLevel.CurrentRead, |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
189 |
"output":ua.AccessLevel.CurrentWrite}[self.direction] not in access: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
190 |
self.log("Node {} ignored because of insuficient access rights".format(dname)) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
191 |
continue |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
192 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
193 |
nsid = node.nodeid.NamespaceIndex |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
194 |
nid = node.nodeid.Identifier |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
195 |
nid_type = type(nid).__name__ |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
196 |
iecid = nid |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
197 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
198 |
value = [dname, |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
199 |
nsid, |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
200 |
nid_type, |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
201 |
nid, |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
202 |
tname, |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
203 |
iecid] |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
204 |
self.model.AddRow(value) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
205 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
206 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
207 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
208 |
il = None |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
209 |
fldridx = None |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
210 |
fldropenidx = None |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
211 |
fileidx = None |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
212 |
smileidx = None |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
213 |
isz = (16,16) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
214 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
215 |
treecolnames = [ "Name", "Class", "NSIdx", "Id"] |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
216 |
treecolwidths = [ 250, 100, 50, 200] |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
217 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
218 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
219 |
def prepare_image_list(): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
220 |
global il, fldridx, fldropenidx, fileidx, smileidx |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
221 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
222 |
if il is not None: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
223 |
return |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
224 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
225 |
il = wx.ImageList(isz[0], isz[1]) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
226 |
fldridx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz)) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
227 |
fldropenidx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, isz)) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
228 |
fileidx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, isz)) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
229 |
smileidx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_ADD_BOOKMARK, wx.ART_OTHER, isz)) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
230 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
231 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
232 |
class OPCUAClientPanel(wx.SplitterWindow): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
233 |
def __init__(self, parent, modeldata, log, uri_getter): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
234 |
self.log = log |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
235 |
wx.SplitterWindow.__init__(self, parent, -1) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
236 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
237 |
self.ordered_nodes = [] |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
238 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
239 |
self.inout_panel = wx.Panel(self) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
240 |
self.inout_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
241 |
self.inout_sizer.AddGrowableCol(0) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
242 |
self.inout_sizer.AddGrowableRow(1) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
243 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
244 |
self.client = None |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
245 |
self.uri_getter = uri_getter |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
246 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
247 |
self.connect_button = wx.ToggleButton(self.inout_panel, -1, "Browse Server") |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
248 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
249 |
self.selected_splitter = wx.SplitterWindow(self.inout_panel, style=wx.SUNKEN_BORDER | wx.SP_3D) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
250 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
251 |
self.selected_datas = modeldata |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
252 |
self.selected_models = { direction:OPCUASubListModel(self.selected_datas[direction], log) for direction in directions } |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
253 |
self.selected_lists = { direction:OPCUASubListPanel( |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
254 |
self.selected_splitter, log, |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
255 |
self.selected_models[direction], direction) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
256 |
for direction in directions } |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
257 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
258 |
self.selected_splitter.SplitHorizontally(*[self.selected_lists[direction] for direction in directions]+[300]) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
259 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
260 |
self.inout_sizer.Add(self.connect_button, flag=wx.GROW) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
261 |
self.inout_sizer.Add(self.selected_splitter, flag=wx.GROW) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
262 |
self.inout_sizer.Layout() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
263 |
self.inout_panel.SetAutoLayout(True) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
264 |
self.inout_panel.SetSizer(self.inout_sizer) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
265 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
266 |
self.Initialize(self.inout_panel) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
267 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
268 |
self.Bind(wx.EVT_TOGGLEBUTTON, self.OnConnectButton, self.connect_button) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
269 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
270 |
def OnClose(self): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
271 |
if self.client is not None: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
272 |
self.client.disconnect() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
273 |
self.client = None |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
274 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
275 |
def __del__(self): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
276 |
self.OnClose() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
277 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
278 |
def OnConnectButton(self, event): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
279 |
if self.connect_button.GetValue(): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
280 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
281 |
self.tree_panel = wx.Panel(self) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
282 |
self.tree_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
283 |
self.tree_sizer.AddGrowableCol(0) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
284 |
self.tree_sizer.AddGrowableRow(0) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
285 |
|
3370
3c31dce1a661
Make OPC-UA client compatible with wxPython3, util wxPython4 branch deserve to be merged
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3367
diff
changeset
|
286 |
self.tree = TreeListCtrl(self.tree_panel, -1, style=0, agwStyle= |
3c31dce1a661
Make OPC-UA client compatible with wxPython3, util wxPython4 branch deserve to be merged
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3367
diff
changeset
|
287 |
wx.TR_DEFAULT_STYLE |
3c31dce1a661
Make OPC-UA client compatible with wxPython3, util wxPython4 branch deserve to be merged
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3367
diff
changeset
|
288 |
| wx.TR_MULTIPLE |
3c31dce1a661
Make OPC-UA client compatible with wxPython3, util wxPython4 branch deserve to be merged
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3367
diff
changeset
|
289 |
| wx.TR_FULL_ROW_HIGHLIGHT |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
290 |
) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
291 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
292 |
prepare_image_list() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
293 |
self.tree.SetImageList(il) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
294 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
295 |
for idx,(colname, width) in enumerate(zip(treecolnames, treecolwidths)): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
296 |
self.tree.AddColumn(colname) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
297 |
self.tree.SetColumnWidth(idx, width) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
298 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
299 |
self.tree.SetMainColumn(0) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
300 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
301 |
self.client = Client(self.uri_getter()) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
302 |
self.client.connect() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
303 |
self.client.load_type_definitions() # load definition of server specific structures/extension objects |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
304 |
rootnode = self.client.get_root_node() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
305 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
306 |
rootitem = self.AddNodeItem(self.tree.AddRoot, rootnode) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
307 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
308 |
# Populate first level so that root can be expanded |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
309 |
self.CreateSubItems(rootitem) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
310 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
311 |
self.tree.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnExpand) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
312 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
313 |
self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnTreeNodeSelection) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
314 |
self.tree.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnTreeBeginDrag) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
315 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
316 |
self.tree.Expand(rootitem) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
317 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
318 |
hint = wx.StaticText(self, label = "Drag'n'drop desired variables from tree to Input or Output list") |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
319 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
320 |
self.tree_sizer.Add(self.tree, flag=wx.GROW) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
321 |
self.tree_sizer.Add(hint, flag=wx.GROW) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
322 |
self.tree_sizer.Layout() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
323 |
self.tree_panel.SetAutoLayout(True) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
324 |
self.tree_panel.SetSizer(self.tree_sizer) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
325 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
326 |
self.SplitVertically(self.tree_panel, self.inout_panel, 500) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
327 |
else: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
328 |
self.client.disconnect() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
329 |
self.client = None |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
330 |
self.Unsplit(self.tree_panel) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
331 |
self.tree_panel.Destroy() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
332 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
333 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
334 |
def CreateSubItems(self, item): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
335 |
node, browsed = self.tree.GetPyData(item) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
336 |
if not browsed: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
337 |
for subnode in node.get_children(): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
338 |
self.AddNodeItem(lambda n: self.tree.AppendItem(item, n), subnode) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
339 |
self.tree.SetPyData(item,(node, True)) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
340 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
341 |
def AddNodeItem(self, item_creation_func, node): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
342 |
nsid = node.nodeid.NamespaceIndex |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
343 |
nid = node.nodeid.Identifier |
3367
3656d0d235c4
OPCUA: fix display names appearing with a "LocalizedText(" prefix when browsing localized server.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3365
diff
changeset
|
344 |
dname = node.get_display_name().Text |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
345 |
cname = node.get_node_class().name |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
346 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
347 |
item = item_creation_func(dname) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
348 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
349 |
if cname == "Variable": |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
350 |
access = node.get_access_level() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
351 |
normalidx = fileidx |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
352 |
r = ua.AccessLevel.CurrentRead in access |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
353 |
w = ua.AccessLevel.CurrentWrite in access |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
354 |
if r and w: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
355 |
ext = "RW" |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
356 |
elif r: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
357 |
ext = "RO" |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
358 |
elif w: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
359 |
ext = "WO" # not sure this one exist |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
360 |
else: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
361 |
ext = "no access" # not sure this one exist |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
362 |
cname = "Var "+node.get_data_type_as_variant_type().name+" (" + ext + ")" |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
363 |
else: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
364 |
normalidx = fldridx |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
365 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
366 |
self.tree.SetPyData(item,(node, False)) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
367 |
self.tree.SetItemText(item, cname, 1) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
368 |
self.tree.SetItemText(item, str(nsid), 2) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
369 |
self.tree.SetItemText(item, type(nid).__name__+": "+str(nid), 3) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
370 |
self.tree.SetItemImage(item, normalidx, which = wx.TreeItemIcon_Normal) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
371 |
self.tree.SetItemImage(item, fldropenidx, which = wx.TreeItemIcon_Expanded) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
372 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
373 |
return item |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
374 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
375 |
def OnExpand(self, evt): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
376 |
for item in evt.GetItem().GetChildren(): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
377 |
self.CreateSubItems(item) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
378 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
379 |
# def OnActivate(self, evt): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
380 |
# item = evt.GetItem() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
381 |
# node, browsed = self.tree.GetPyData(item) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
382 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
383 |
def OnTreeNodeSelection(self, event): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
384 |
items = self.tree.GetSelections() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
385 |
items_pydata = [self.tree.GetPyData(item) for item in items] |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
386 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
387 |
nodes = [node for node, _unused in items_pydata] |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
388 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
389 |
# append new nodes to ordered list |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
390 |
for node in nodes: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
391 |
if node not in self.ordered_nodes: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
392 |
self.ordered_nodes.append(node) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
393 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
394 |
# filter out vanished items |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
395 |
self.ordered_nodes = [ |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
396 |
node |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
397 |
for node in self.ordered_nodes |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
398 |
if node in nodes] |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
399 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
400 |
def GetSelectedNodes(self): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
401 |
return self.ordered_nodes |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
402 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
403 |
def OnTreeBeginDrag(self, event): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
404 |
""" |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
405 |
Called when a drag is started in tree |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
406 |
@param event: wx.TreeEvent |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
407 |
""" |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
408 |
if self.ordered_nodes: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
409 |
# Just send a recognizable mime-type, drop destination |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
410 |
# will get python data from parent |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
411 |
data = wx.CustomDataObject(OPCUAClientDndMagicWord) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
412 |
dragSource = wx.DropSource(self) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
413 |
dragSource.SetData(data) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
414 |
dragSource.DoDragDrop() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
415 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
416 |
def Reset(self): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
417 |
for direction in directions: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
418 |
self.selected_models[direction].ResetData() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
419 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
420 |
|
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
|
421 |
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
|
422 |
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
|
423 |
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
|
424 |
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
|
425 |
|
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
|
426 |
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
|
427 |
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
|
428 |
|
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
|
429 |
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
|
430 |
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
|
431 |
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
|
432 |
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
|
433 |
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
|
434 |
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
|
435 |
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
|
436 |
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
|
437 |
|
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
|
438 |
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
|
439 |
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
|
440 |
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
|
441 |
|
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 |
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
|
443 |
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
|
444 |
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
|
445 |
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
|
446 |
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
|
447 |
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
|
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 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
|
450 |
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
|
451 |
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
|
452 |
|
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 |
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
|
454 |
|
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 |
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
|
456 |
|
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
457 |
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
|
458 |
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
|
459 |
super(OPCUAClientModel, self).__init__() |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
460 |
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
|
461 |
self[direction] = OPCUAClientList(log) |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
462 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
463 |
def LoadCSV(self,path): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
464 |
with open(path, 'rb') as csvfile: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
465 |
reader = csv.reader(csvfile, delimiter=',', quotechar='"') |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
466 |
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
|
467 |
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
|
468 |
self[direction][:] = [] |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
469 |
for row in reader: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
470 |
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
|
471 |
self[direction].append(row[1:]) |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
472 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
473 |
def SaveCSV(self,path): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
474 |
with open(path, 'wb') as csvfile: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
475 |
for direction, data in self.iteritems(): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
476 |
writer = csv.writer(csvfile, delimiter=',', |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
477 |
quotechar='"', quoting=csv.QUOTE_MINIMAL) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
478 |
for row in data: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
479 |
writer.writerow([direction] + row) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
480 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
481 |
def GenerateC(self, path, locstr, server_uri): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
482 |
template = """/* code generated by beremiz OPC-UA extension */ |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
483 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
484 |
#include <open62541/client_config_default.h> |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
485 |
#include <open62541/client_highlevel.h> |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
486 |
#include <open62541/plugin/log_stdout.h> |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
487 |
|
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
|
488 |
static UA_Client *client; |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
489 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
490 |
#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
|
491 |
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
|
492 |
static C_type c_loc_name##_buf = 0; \\ |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
493 |
C_type *c_loc_name = &c_loc_name##_buf; |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
494 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
495 |
%(decl)s |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
496 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
497 |
void __cleanup_%(locstr)s(void) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
498 |
{ |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
499 |
UA_Client_disconnect(client); |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
500 |
UA_Client_delete(client); |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
501 |
} |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
502 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
503 |
|
3406
3aac4241dafa
OPC-UA: cosmetic fix and armless typo
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3392
diff
changeset
|
504 |
#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
|
505 |
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
|
506 |
|
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
|
507 |
#define INIT_WRITE_VARIANT(ua_type, ua_type_enum, c_loc_name) \\ |
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
|
508 |
UA_Variant_setScalar(&c_loc_name##_variant, (ua_type*)c_loc_name, &UA_TYPES[ua_type_enum]); |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
509 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
510 |
int __init_%(locstr)s(int argc,char **argv) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
511 |
{ |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
512 |
UA_StatusCode retval; |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
513 |
client = UA_Client_new(); |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
514 |
UA_ClientConfig_setDefault(UA_Client_getConfig(client)); |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
515 |
%(init)s |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
516 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
517 |
/* Connect to server */ |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
518 |
retval = UA_Client_connect(client, "%(uri)s"); |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
519 |
if(retval != UA_STATUSCODE_GOOD) { |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
520 |
UA_Client_delete(client); |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
521 |
return EXIT_FAILURE; |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
522 |
} |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
523 |
} |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
524 |
|
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
|
525 |
#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
|
526 |
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
|
527 |
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
|
528 |
if(retval == UA_STATUSCODE_GOOD && UA_Variant_isScalar(&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
|
529 |
c_loc_name##_variant.type == &UA_TYPES[ua_type_enum]) { \\ |
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
|
530 |
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
|
531 |
UA_Variant_clear(&c_loc_name##_variant); /* Unalloc requiered on each read ! */ \\ |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
532 |
} |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
533 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
534 |
void __retrieve_%(locstr)s(void) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
535 |
{ |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
536 |
UA_StatusCode retval; |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
537 |
%(retrieve)s |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
538 |
} |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
539 |
|
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
|
540 |
#define WRITE_VALUE(ua_type, 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
|
541 |
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
|
542 |
client, ua_nodeid_type(ua_nsidx, ua_node_id), &c_loc_name##_variant); |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
543 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
544 |
void __publish_%(locstr)s(void) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
545 |
{ |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
546 |
%(publish)s |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
547 |
} |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
548 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
549 |
""" |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
550 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
551 |
formatdict = dict( |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
552 |
locstr = locstr, |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
553 |
uri = server_uri, |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
554 |
decl = "", |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
555 |
cleanup = "", |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
556 |
init = "", |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
557 |
retrieve = "", |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
558 |
publish = "" |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
559 |
) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
560 |
for direction, data in self.iteritems(): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
561 |
iec_direction_prefix = {"input": "__I", "output": "__Q"}[direction] |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
562 |
for row in data: |
3365
9f7c9051c9ba
OPCUA client: fix handling of string type Node Identifier
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3364
diff
changeset
|
563 |
name, ua_nsidx, ua_nodeid_type, _ua_node_id, ua_type, iec_number = row |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
564 |
iec_type, C_type, iec_size_prefix, ua_type_enum, ua_type = UA_IEC_types[ua_type] |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
565 |
c_loc_name = iec_direction_prefix + iec_size_prefix + locstr + "_" + str(iec_number) |
3365
9f7c9051c9ba
OPCUA client: fix handling of string type Node Identifier
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3364
diff
changeset
|
566 |
ua_nodeid_type, id_formating = UA_NODE_ID_types[ua_nodeid_type] |
9f7c9051c9ba
OPCUA client: fix handling of string type Node Identifier
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3364
diff
changeset
|
567 |
ua_node_id = id_formating.format(_ua_node_id) |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
568 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
569 |
formatdict["decl"] += """ |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
570 |
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
|
571 |
|
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
|
572 |
if direction == "input": |
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
|
573 |
formatdict["init"] +=""" |
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
|
574 |
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
|
575 |
formatdict["retrieve"] += """ |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
576 |
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
|
577 |
|
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
|
578 |
if direction == "output": |
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
|
579 |
formatdict["init"] +=""" |
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
|
580 |
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
|
581 |
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
|
582 |
WRITE_VALUE({ua_type}, {c_loc_name}, {ua_nodeid_type}, {ua_nsidx}, {ua_node_id})""".format(**locals()) |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
583 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
584 |
Ccode = template%formatdict |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
585 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
586 |
return Ccode |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
587 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
588 |
if __name__ == "__main__": |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
589 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
590 |
import wx.lib.mixins.inspection as wit |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
591 |
import sys,os |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
592 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
593 |
app = wit.InspectableApp() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
594 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
595 |
frame = wx.Frame(None, -1, "OPCUA Client Test App", size=(800,600)) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
596 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
597 |
uri = sys.argv[1] if len(sys.argv)>1 else "opc.tcp://localhost:4840" |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
598 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
599 |
test_panel = wx.Panel(frame) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
600 |
test_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
601 |
test_sizer.AddGrowableCol(0) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
602 |
test_sizer.AddGrowableRow(0) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
603 |
|
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
|
604 |
modeldata = OPCUAClientModel(print) |
3364
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
605 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
606 |
opcuatestpanel = OPCUAClientPanel(test_panel, modeldata, print, lambda:uri) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
607 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
608 |
def OnGenerate(evt): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
609 |
dlg = wx.FileDialog( |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
610 |
frame, message="Generate file as ...", defaultDir=os.getcwd(), |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
611 |
defaultFile="", |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
612 |
wildcard="C (*.c)|*.c", style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
613 |
) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
614 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
615 |
if dlg.ShowModal() == wx.ID_OK: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
616 |
path = dlg.GetPath() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
617 |
Ccode = """ |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
618 |
/* |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
619 |
In case open62541 was built just aside beremiz, you can build this test with: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
620 |
gcc %s -o %s \\ |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
621 |
-I ../../open62541/plugins/include/ \\ |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
622 |
-I ../../open62541/build/src_generated/ \\ |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
623 |
-I ../../open62541/include/ \\ |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
624 |
-I ../../open62541/arch/ ../../open62541/build/bin/libopen62541.a |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
625 |
*/ |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
626 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
627 |
"""%(path, path[:-2]) + modeldata.GenerateC(path, "test", uri) + """ |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
628 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
629 |
int main(int argc, char *argv[]) { |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
630 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
631 |
__init_test(arc,argv); |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
632 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
633 |
__retrieve_test(); |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
634 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
635 |
__publish_test(); |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
636 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
637 |
__cleanup_test(); |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
638 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
639 |
return EXIT_SUCCESS; |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
640 |
} |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
641 |
""" |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
642 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
643 |
with open(path, 'wb') as Cfile: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
644 |
Cfile.write(Ccode) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
645 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
646 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
647 |
dlg.Destroy() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
648 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
649 |
def OnLoad(evt): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
650 |
dlg = wx.FileDialog( |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
651 |
frame, message="Choose a file", |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
652 |
defaultDir=os.getcwd(), |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
653 |
defaultFile="", |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
654 |
wildcard="CSV (*.csv)|*.csv", |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
655 |
style=wx.FD_OPEN | wx.FD_CHANGE_DIR | wx.FD_FILE_MUST_EXIST ) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
656 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
657 |
if dlg.ShowModal() == wx.ID_OK: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
658 |
path = dlg.GetPath() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
659 |
modeldata.LoadCSV(path) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
660 |
opcuatestpanel.Reset() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
661 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
662 |
dlg.Destroy() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
663 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
664 |
def OnSave(evt): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
665 |
dlg = wx.FileDialog( |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
666 |
frame, message="Save file as ...", defaultDir=os.getcwd(), |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
667 |
defaultFile="", |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
668 |
wildcard="CSV (*.csv)|*.csv", style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
669 |
) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
670 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
671 |
if dlg.ShowModal() == wx.ID_OK: |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
672 |
path = dlg.GetPath() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
673 |
modeldata.SaveCSV(path) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
674 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
675 |
dlg.Destroy() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
676 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
677 |
test_sizer.Add(opcuatestpanel, flag=wx.GROW) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
678 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
679 |
testbt_sizer = wx.BoxSizer(wx.HORIZONTAL) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
680 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
681 |
loadbt = wx.Button(test_panel, label="Load") |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
682 |
test_panel.Bind(wx.EVT_BUTTON, OnLoad, loadbt) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
683 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
684 |
savebt = wx.Button(test_panel, label="Save") |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
685 |
test_panel.Bind(wx.EVT_BUTTON, OnSave, savebt) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
686 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
687 |
genbt = wx.Button(test_panel, label="Generate") |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
688 |
test_panel.Bind(wx.EVT_BUTTON, OnGenerate, genbt) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
689 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
690 |
testbt_sizer.Add(loadbt, 0, wx.LEFT|wx.RIGHT, 5) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
691 |
testbt_sizer.Add(savebt, 0, wx.LEFT|wx.RIGHT, 5) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
692 |
testbt_sizer.Add(genbt, 0, wx.LEFT|wx.RIGHT, 5) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
693 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
694 |
test_sizer.Add(testbt_sizer, flag=wx.GROW) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
695 |
test_sizer.Layout() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
696 |
test_panel.SetAutoLayout(True) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
697 |
test_panel.SetSizer(test_sizer) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
698 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
699 |
def OnClose(evt): |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
700 |
opcuatestpanel.OnClose() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
701 |
evt.Skip() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
702 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
703 |
frame.Bind(wx.EVT_CLOSE, OnClose) |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
704 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
705 |
frame.Show() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
706 |
|
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
707 |
app.MainLoop() |
fa2365fa6154
Add OPC-UA simple synchronous client extension.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
708 |