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