loupedeck-commander 1.3.3 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
File without changes
File without changes
package/common/button.mjs CHANGED
@@ -383,24 +383,27 @@ export class Button {
383
383
  async buttonStateChanged(buttonID, attribute, nodeid, val) {
384
384
 
385
385
  //
386
- if (attribute == "nodeid" && nodeid == this.#params.nodeid) {
386
+ if ((attribute == "nodeid" && nodeid == this.#params.nodeid)) {
387
387
  this.#index = 0;
388
- this.#enforcedIndex = -1;
388
+ this.#enforcedIndex = 0;
389
389
  for (let i = 0; i < this.#keys.length; i++) {
390
390
  let stateStr = this.#keys[i].toString()
391
391
  let valStr = val.toString()
392
392
  // check if the state-name is same as the value we get from outside:
393
393
  if (valStr == stateStr) {
394
- if (i !== this.#index) {
395
- console.info("Changed index", this.id, nodeid, val, i)
396
- this.#index = i;
397
- console.info("enforce State index", this.id, nodeid, val, i)
398
- this.#enforcedIndex = this.#index;
399
- }
394
+ //if (i !== this.#index) {
395
+ //console.info("enforce State index", this.id, nodeid, val, i)
396
+ this.#enforcedIndex = i;
397
+ //}
400
398
  break;
401
399
  }
402
400
  }
401
+ //console.info("Changed index", this.id, nodeid, val, this.#enforcedIndex)
402
+ this.#index = this.#enforcedIndex;
403
+ //console.info("enforce State index", this.id, nodeid, val, i)
404
+ //this.#enforcedIndex = this.#index;
403
405
  }
406
+
404
407
 
405
408
  if (attribute == "blink") {
406
409
  console.info("Changed blink", buttonID, nodeid, val)
File without changes
package/common/index.mjs CHANGED
File without changes
package/common/utils.mjs CHANGED
File without changes
package/index.mjs CHANGED
File without changes
File without changes
File without changes
File without changes
@@ -56,6 +56,7 @@ export class OPCUAIf extends BaseIf {
56
56
  this.#samplingInterval = 100;
57
57
  this.LogInfo(`OPCUAIf init using default samplingInterval: ${this.#samplingInterval}ms\n`);
58
58
  }
59
+ this.options = options
59
60
  this.monitoreditems = {}
60
61
  this.types = {}
61
62
  this.buttons = {}
@@ -78,18 +79,22 @@ export class OPCUAIf extends BaseIf {
78
79
  let attributes = ["nodeid", "blink"]
79
80
  for (let j = 0; j < attributes.length; j++) {
80
81
  const attribute = attributes[j]
82
+ let nodeID = super.formatString(elem.params[attribute], options)
81
83
  if (attribute in elem.params) {
82
- if (!this.IsNodeID(elem.params[attribute])) {
84
+ if (!this.IsNodeID(nodeID)) {
83
85
  continue
84
86
  }
85
87
 
86
- let monitoredItemId = await this.Subscribe(elem.params[attribute], options,attribute)
88
+ let monitoredItemId = await this.Subscribe(nodeID, options,attribute)
87
89
  if (monitoredItemId) {
88
- this.buttons[monitoredItemId] = {
90
+ console.log("Register nodeid",nodeID, monitoredItemId, buttonID, attribute,)
91
+ if (this.buttons[monitoredItemId] == undefined)
92
+ this.buttons[monitoredItemId] = []
93
+ this.buttons[monitoredItemId].push({
89
94
  buttonID: i,
90
95
  buttonName: buttonID,
91
96
  attribute: attribute
92
- }
97
+ })
93
98
  }
94
99
  }
95
100
  }
@@ -103,17 +108,21 @@ export class OPCUAIf extends BaseIf {
103
108
 
104
109
  for (let k = 0; k < attributes.length; k++) {
105
110
  const attribute = attributes[k]
111
+ let nodeID = super.formatString(state[attribute], options)
106
112
  if (attribute in state) {
107
- if (!this.IsNodeID(state[attribute])) {
113
+ if (!this.IsNodeID(nodeID)) {
108
114
  continue
109
115
  }
110
- let monitoredItemId = await this.Subscribe(state[attribute], options,attribute)
116
+ let monitoredItemId = await this.Subscribe(nodeID, options,attribute)
111
117
  if (monitoredItemId) {
112
- this.buttons[monitoredItemId] = {
118
+ console.log("Register state",monitoredItemId, buttonID, attribute,nodeID)
119
+ if (this.buttons[monitoredItemId] == undefined)
120
+ this.buttons[monitoredItemId] = []
121
+ this.buttons[monitoredItemId].push({
113
122
  buttonID: i,
114
123
  buttonName: buttonID,
115
124
  attribute: attribute
116
- }
125
+ })
117
126
  }
118
127
  }
119
128
  }
@@ -188,6 +197,12 @@ export class OPCUAIf extends BaseIf {
188
197
  var nodeId = super.call(opcuaNode, options)
189
198
 
190
199
  var type = this.types[nodeId]
200
+
201
+ if (type === undefined){
202
+ let dataValue = await this.Read(nodeId)
203
+ this.types[nodeId] = dataValue.value.dataType
204
+ type = this.types[nodeId]
205
+ }
191
206
  var value = options.value
192
207
  if (typeof value == "string")
193
208
  value = super.formatString(options.value, options)
@@ -311,10 +326,10 @@ export class OPCUAIf extends BaseIf {
311
326
  this.#session = await this.#client.createSession();
312
327
 
313
328
  this.#session.on("session_closed", (statusCode) => {
314
- self.LogInfo(`OPCUAIf: Session has been closed\n`);
329
+ //self.LogInfo(`OPCUAIf: Session has been closed\n`);
315
330
  })
316
331
  this.#session.on("session_restored", () => {
317
- self.LogInfo(`OPCUAIf: Session has been restored\n`);
332
+ //self.LogInfo(`OPCUAIf: Session has been restored\n`);
318
333
  });
319
334
  this.#session.on("keepalive", (lastKnownServerState) => {
320
335
  self.LogInfo(`OPCUAIf: KeepAlive lastKnownServerState ${lastKnownServerState}\n`);
@@ -367,11 +382,12 @@ export class OPCUAIf extends BaseIf {
367
382
  let nodeID = this.formatString(unformattedNodeID, options)
368
383
 
369
384
  // install monitored item
370
- const monitoredNodeIdList = Object.values(this.monitoreditems)
385
+ const monitoredNodeIdList = Object.keys(this.monitoreditems)
386
+ let monitorItemId = -1
371
387
  for (let i = 0; i < monitoredNodeIdList.length; i++) {
372
- if (monitoredNodeIdList[i] == nodeID) {
373
- // already registered => return itemid
374
- return this.monitoreditems[i]
388
+ let monitorItemId = monitoredNodeIdList[i]
389
+ if (this.monitoreditems[monitorItemId] == nodeID) {
390
+ return monitorItemId // already registered => return itemid
375
391
  }
376
392
  }
377
393
 
@@ -391,23 +407,27 @@ export class OPCUAIf extends BaseIf {
391
407
  }
392
408
  const monitoredItem = await this.#sub.monitor(itemToMonitor, monitoringParameters, TimestampsToReturn.Both);
393
409
  this.monitoreditems[monitoredItem.monitoredItemId] = nodeID
410
+ if (monitoredItem.monitoredItemId === undefined) {
411
+ this.LogError(`OPCUAIf: Error subscribing to node ${nodeID} (attribute ${attribute})\n`)
412
+ } else {
413
+ this.LogDebug(`OPCUAIf: Subscribe to ${monitoredItem.monitoredItemId},${nodeID},(attribute ${attribute})\n`);
414
+ }
415
+
394
416
  var self = this
395
417
  monitoredItem.on("changed", function (dataValue) {
396
418
  var nodeId = self.monitoreditems[this.monitoredItemId]
397
- var buttonInfo = self.buttons[this.monitoredItemId]
419
+
398
420
  // store the type of a nodeid in local dictionary
399
421
  self.types[nodeId] = dataValue.value.dataType
400
422
  // publish the value to subscribers:
401
- self.LogInfo(`OPCUAIf: monitored item changed: ${buttonInfo.buttonID} ${buttonInfo.attribute} ${nodeId} => ${dataValue.value.value}\n`);
402
- self.emit('monitored item changed', buttonInfo.buttonID, buttonInfo.attribute, nodeId, dataValue.value.value)
423
+ let buttons = self.buttons[this.monitoredItemId]
424
+ for (var i=0;i<buttons.length;i++){
425
+ var buttonInfo = buttons[i]
426
+ self.LogInfo(`OPCUAIf: monitored item changed: ${buttonInfo.buttonID} ${buttonInfo.attribute} ${nodeId} => ${dataValue.value.value}\n`);
427
+ self.emit('monitored item changed', buttonInfo.buttonID, buttonInfo.attribute, nodeId, dataValue.value.value)
428
+ }
403
429
  });
404
430
 
405
- if (monitoredItem.monitoredItemId === undefined) {
406
- this.LogError(`OPCUAIf: Error subscribing to node ${nodeID} (attribute ${attribute})\n`)
407
- } else {
408
- this.LogDebug(`OPCUAIf: Subscribe to ${monitoredItem.monitoredItemId},${nodeID},(attribute ${attribute})\n`);
409
- }
410
-
411
431
  return monitoredItem.monitoredItemId;
412
432
  }
413
433
 
@@ -451,11 +471,11 @@ export class OPCUAIf extends BaseIf {
451
471
  self.LogInfo(`OPCUAIf: wrote ${nodeID} => ${value}\n`);
452
472
  }
453
473
  } else {
454
- self.LogError("OPCUAIf: write NOT ok", nodeID, value, "\n");
474
+ self.LogError(`OPCUAIf: writing not OK ${nodeID} => ${value}, ${err}\n`);
455
475
  }
456
476
  });
457
477
  } catch (err) {
458
- self.LogError("OPCUAIf: write NOT ok", nodeID, value, "\n");
478
+ self.LogError(`OPCUAIf: writing not OK ${nodeID} => ${value}, ${err}\n`);
459
479
  }
460
480
  }
461
481
  }
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loupedeck-commander",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
4
4
  "description": "A system to ease working with LoupeDeck devices using CMD-line, OPC/UA or HTTP-client interfaces",
5
5
  "main": "index.mjs",
6
6
  "scripts": {
@@ -10,12 +10,12 @@
10
10
  "start": "node index.mjs"
11
11
  },
12
12
  "dependencies": {
13
- "canvas": "^3.1.0",
13
+ "canvas": "^3.2.0",
14
14
  "loupedeck": "^7.0.0",
15
15
  "mkdirp": "^3.0.1",
16
- "node-opcua": "^2.153.0",
16
+ "node-opcua": "^2.156.0",
17
17
  "string-template": "^1.0.0",
18
- "yaml": "^2.8.0"
18
+ "yaml": "^2.8.1"
19
19
  },
20
20
  "author": "Thomas Schneider",
21
21
  "license": "Apache-2.0",