blob: e4862d8c65747cb2402318b2eb1e0cf537519e67 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
// NodePage.qml — Monitors a single OPC UA node.
// Two instances demonstrate visibility lifecycle: switching pages
// stops monitoring on the hidden page automatically.
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Bobink
Page {
id: nodePage
required property StackView stackRef
required property int pageNumber
required property var logFunction
property string monitoredNodeId: ""
property string nodeDescription: ""
property bool nodeWritable: true
property bool metadataLoaded: false
BobinkNode {
id: node
nodeId: nodePage.monitoredNodeId
onAttributeRead: (name, val) => {
if (name === "DisplayName")
nodePage.nodeDescription = val.toString();
else if (name === "AccessLevel")
nodePage.nodeWritable = (val & 0x02) !== 0;
nodePage.metadataLoaded = true;
}
onWriteError: (message) => nodePage.logFunction("WRITE: " + message)
}
ColumnLayout {
anchors.fill: parent
anchors.margins: 20
spacing: 12
RowLayout {
Label {
text: "Node Page " + nodePage.pageNumber
font.bold: true
font.pointSize: 14
}
Item { Layout.fillWidth: true }
Button {
text: "Disconnect"
onClicked: BobinkClient.disconnectFromServer()
}
}
RowLayout {
TextField {
id: nodeIdField
Layout.fillWidth: true
placeholderText: "ns=2;s=Temperature"
enabled: !nodePage.monitoredNodeId
}
Button {
text: nodePage.monitoredNodeId ? "Stop" : "Monitor"
onClicked: {
if (nodePage.monitoredNodeId) {
nodePage.monitoredNodeId = "";
nodePage.nodeDescription = "";
nodePage.nodeWritable = true;
nodePage.metadataLoaded = false;
} else {
nodePage.monitoredNodeId = nodeIdField.text;
node.readAttribute("DisplayName");
node.readAttribute("AccessLevel");
}
}
}
}
GroupBox {
Layout.fillWidth: true
visible: nodePage.monitoredNodeId.length > 0
title: nodePage.nodeDescription || nodePage.monitoredNodeId
GridLayout {
columns: 2
width: parent.width
Label { text: "Value:" }
Label {
text: node.value !== undefined ? node.value.toString() : "—"
font.family: "monospace"
font.bold: true
}
Label { text: "Status:" }
Label {
text: node.status === BobinkNode.Good ? "Good"
: node.status === BobinkNode.Uncertain ? "Uncertain"
: "Bad"
color: node.status === BobinkNode.Good ? "green"
: node.status === BobinkNode.Uncertain ? "orange"
: "red"
}
Label { text: "Source TS:" }
Label {
text: node.sourceTimestamp.toLocaleString(
Qt.locale(), "HH:mm:ss.zzz")
font.family: "monospace"
}
Label { text: "Server TS:" }
Label {
text: node.serverTimestamp.toLocaleString(
Qt.locale(), "HH:mm:ss.zzz")
font.family: "monospace"
}
}
}
RowLayout {
visible: nodePage.monitoredNodeId.length > 0
TextField {
id: writeField
Layout.fillWidth: true
enabled: nodePage.nodeWritable
placeholderText: nodePage.metadataLoaded && !nodePage.nodeWritable
? "Read-only node" : "Value to write"
}
Button {
text: "Write"
enabled: nodePage.nodeWritable
onClicked: {
node.value = writeField.text;
writeField.clear();
}
}
}
Label {
visible: nodePage.monitoredNodeId.length > 0
&& nodePage.metadataLoaded && !nodePage.nodeWritable
text: "Read-only node"
font.italic: true
color: "gray"
}
Item { Layout.fillHeight: true }
Button {
Layout.fillWidth: true
text: nodePage.pageNumber === 1 ? "Go to Page 2" : "Back to Page 1"
onClicked: {
if (nodePage.pageNumber === 1)
nodePage.stackRef.push("NodePage.qml", {
stackRef: nodePage.stackRef,
pageNumber: 2,
logFunction: nodePage.logFunction
});
else
nodePage.stackRef.pop();
}
}
}
}
|