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