@things-factory/integration-opc 6.1.129 → 6.1.138

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.
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  require("./opc-ua-read");
4
4
  require("./opc-ua-write");
5
5
  require("./opc-ua-start-monitor");
6
- require("./opc-ua-stop-monitor");
6
+ //import './opc-ua-stop-monitor'
7
7
  require("./utils");
8
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/engine/task/index.ts"],"names":[],"mappings":";;AAAA,yBAAsB;AACtB,0BAAuB;AACvB,kCAA+B;AAC/B,iCAA8B;AAC9B,mBAAgB","sourcesContent":["import './opc-ua-read'\nimport './opc-ua-write'\nimport './opc-ua-start-monitor'\nimport './opc-ua-stop-monitor'\nimport './utils'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/engine/task/index.ts"],"names":[],"mappings":";;AAAA,yBAAsB;AACtB,0BAAuB;AACvB,kCAA+B;AAC/B,gCAAgC;AAChC,mBAAgB","sourcesContent":["import './opc-ua-read'\nimport './opc-ua-write'\nimport './opc-ua-start-monitor'\n//import './opc-ua-stop-monitor'\nimport './utils'\n"]}
@@ -1,22 +1,46 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const integration_base_1 = require("@things-factory/integration-base");
4
- async function OPCUAStartMonitor(step, { logger, domain, data }) {
4
+ const utils_1 = require("@things-factory/utils");
5
+ async function OPCUAStartMonitor(step, context) {
5
6
  var { connection, params: { node, samplingInterval, discardOldest, queueSize } } = step;
7
+ const { logger, domain, closures, __opcua_moinitor } = context;
8
+ if (!__opcua_moinitor) {
9
+ context.__opcua_moinitor = {};
10
+ }
6
11
  var client = integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, connection);
7
12
  if (!client) {
8
13
  throw new Error(`no connection : ${connection}`);
9
14
  }
10
- const callback = (dataValue) => {
11
- logger.log('monitored value: %s', dataValue === null || dataValue === void 0 ? void 0 : dataValue.value.value);
12
- };
13
- var { startMonitor } = client;
14
- var monitoredItem = await startMonitor(node, callback, {
15
- samplingInterval,
16
- discardOldest,
17
- queueSize
18
- }, { logger });
19
- return { data: monitoredItem };
15
+ if (!context.__opcua_moinitor[node]) {
16
+ var MONINTORED_VALUE;
17
+ context.__opcua_moinitor[node] = async () => {
18
+ while (!MONINTORED_VALUE) {
19
+ await (0, utils_1.sleep)(100);
20
+ }
21
+ var monitoringValue = MONINTORED_VALUE;
22
+ MONINTORED_VALUE = null;
23
+ return monitoringValue;
24
+ };
25
+ var { startMonitor, stopMonitor } = client;
26
+ var monitoredItem = await startMonitor(node, (dataValue) => {
27
+ MONINTORED_VALUE = dataValue === null || dataValue === void 0 ? void 0 : dataValue.value.value;
28
+ }, {
29
+ samplingInterval,
30
+ discardOldest,
31
+ queueSize
32
+ }, { logger });
33
+ closures.push(async () => {
34
+ try {
35
+ monitoredItem && (await stopMonitor(monitoredItem, { logger }));
36
+ }
37
+ catch (e) {
38
+ logger.error(e);
39
+ }
40
+ });
41
+ }
42
+ var monitoringValue = await context.__opcua_moinitor[node]();
43
+ return { data: monitoringValue };
20
44
  }
21
45
  OPCUAStartMonitor.parameterSpec = [
22
46
  {
@@ -1 +1 @@
1
- {"version":3,"file":"opc-ua-start-monitor.js","sourceRoot":"","sources":["../../../server/engine/task/opc-ua-start-monitor.ts"],"names":[],"mappings":";;AAAA,uEAAkF;AAGlF,KAAK,UAAU,iBAAiB,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE;IAC7D,IAAI,EACF,UAAU,EACV,MAAM,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,aAAa,EAAE,SAAS,EAAE,EAC7D,GAAG,IAAI,CAAA;IAER,IAAI,MAAM,GAAG,oCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAC9E,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CAAC,mBAAmB,UAAU,EAAE,CAAC,CAAA;KACjD;IAED,MAAM,QAAQ,GAAG,CAAC,SAAoB,EAAE,EAAE;QACxC,MAAM,CAAC,GAAG,CAAC,qBAAqB,EAAE,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,KAAK,CAAC,KAAK,CAAC,CAAA;IAC3D,CAAC,CAAA;IAED,IAAI,EAAE,YAAY,EAAE,GAAG,MAAM,CAAA;IAC7B,IAAI,aAAa,GAAG,MAAM,YAAY,CACpC,IAAI,EACJ,QAAQ,EACR;QACE,gBAAgB;QAChB,aAAa;QACb,SAAS;KACV,EACD,EAAE,MAAM,EAAE,CACX,CAAA;IAED,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,CAAA;AAChC,CAAC;AAED,iBAAiB,CAAC,aAAa,GAAG;IAChC;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,MAAM;KACd;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,kBAAkB;QACxB,KAAK,EAAE,mBAAmB;KAC3B;IACD;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,eAAe;QACrB,KAAK,EAAE,gBAAgB;KACxB;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,YAAY;KACpB;CACF,CAAA;AAED,iBAAiB,CAAC,IAAI,GAAG,uCAAuC,CAAA;AAEhE,+BAAY,CAAC,mBAAmB,CAAC,sBAAsB,EAAE,iBAAiB,CAAC,CAAA","sourcesContent":["import { ConnectionManager, TaskRegistry } from '@things-factory/integration-base'\nimport { DataValue } from 'node-opcua'\n\nasync function OPCUAStartMonitor(step, { logger, domain, data }) {\n var {\n connection,\n params: { node, samplingInterval, discardOldest, queueSize }\n } = step\n\n var client = ConnectionManager.getConnectionInstanceByName(domain, connection)\n if (!client) {\n throw new Error(`no connection : ${connection}`)\n }\n\n const callback = (dataValue: DataValue) => {\n logger.log('monitored value: %s', dataValue?.value.value)\n }\n\n var { startMonitor } = client\n var monitoredItem = await startMonitor(\n node,\n callback,\n {\n samplingInterval,\n discardOldest,\n queueSize\n },\n { logger }\n )\n\n return { data: monitoredItem }\n}\n\nOPCUAStartMonitor.parameterSpec = [\n {\n type: 'string',\n name: 'node',\n label: 'node'\n },\n {\n type: 'number',\n name: 'samplingInterval',\n label: 'sampling-interval'\n },\n {\n type: 'boolean',\n name: 'discardOldest',\n label: 'discard-oldest'\n },\n {\n type: 'number',\n name: 'queueSize',\n label: 'queue-size'\n }\n]\n\nOPCUAStartMonitor.help = 'integration/task/opc-ua-start-monitor'\n\nTaskRegistry.registerTaskHandler('opc-ua-start-monitor', OPCUAStartMonitor)\n"]}
1
+ {"version":3,"file":"opc-ua-start-monitor.js","sourceRoot":"","sources":["../../../server/engine/task/opc-ua-start-monitor.ts"],"names":[],"mappings":";;AAAA,uEAAkF;AAElF,iDAA6C;AAE7C,KAAK,UAAU,iBAAiB,CAAC,IAAI,EAAE,OAAO;IAC5C,IAAI,EACF,UAAU,EACV,MAAM,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,aAAa,EAAE,SAAS,EAAE,EAC7D,GAAG,IAAI,CAAA;IAER,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAA;IAC9D,IAAI,CAAC,gBAAgB,EAAE;QACrB,OAAO,CAAC,gBAAgB,GAAG,EAAE,CAAA;KAC9B;IAED,IAAI,MAAM,GAAG,oCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAC9E,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CAAC,mBAAmB,UAAU,EAAE,CAAC,CAAA;KACjD;IAED,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,EA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AI,EAAE,SAAS;QACf,IAAI,EAAE,eAAe;QACrB,KAAK,EAAE,gBAAgB;KACxB;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,YAAY;KACpB;CACF,CAAA;AAED,iBAAiB,CAAC,IAAI,GAAG,uCAAuC,CAAA;AAEhE,+BAAY,CAAC,mBAAmB,CAAC,sBAAsB,EAAE,iBAAiB,CAAC,CAAA","sourcesContent":["import { ConnectionManager, TaskRegistry } from '@things-factory/integration-base'\nimport { DataValue } from 'node-opcua'\nimport { sleep } from '@things-factory/utils'\n\nasync function OPCUAStartMonitor(step, context) {\n var {\n connection,\n params: { node, samplingInterval, discardOldest, queueSize }\n } = step\n\n const { logger, domain, closures, __opcua_moinitor } = context\n if (!__opcua_moinitor) {\n context.__opcua_moinitor = {}\n }\n\n var client = ConnectionManager.getConnectionInstanceByName(domain, connection)\n if (!client) {\n throw new Error(`no connection : ${connection}`)\n }\n\n if (!context.__opcua_moinitor[node]) {\n var MONINTORED_VALUE\n context.__opcua_moinitor[node] = async () => {\n while (!MONINTORED_VALUE) {\n await sleep(100)\n }\n\n var monitoringValue = MONINTORED_VALUE\n\n MONINTORED_VALUE = null\n\n return monitoringValue\n }\n\n var { startMonitor, stopMonitor } = client\n var monitoredItem = await startMonitor(\n node,\n (dataValue: DataValue) => {\n MONINTORED_VALUE = dataValue?.value.value\n },\n {\n samplingInterval,\n discardOldest,\n queueSize\n },\n { logger }\n )\n\n closures.push(async () => {\n try {\n monitoredItem && (await stopMonitor(monitoredItem, { logger }))\n } catch (e) {\n logger.error(e)\n }\n })\n }\n\n var monitoringValue = await context.__opcua_moinitor[node]()\n\n return { data: monitoringValue }\n}\n\nOPCUAStartMonitor.parameterSpec = [\n {\n type: 'string',\n name: 'node',\n label: 'node'\n },\n {\n type: 'number',\n name: 'samplingInterval',\n label: 'sampling-interval'\n },\n {\n type: 'boolean',\n name: 'discardOldest',\n label: 'discard-oldest'\n },\n {\n type: 'number',\n name: 'queueSize',\n label: 'queue-size'\n }\n]\n\nOPCUAStartMonitor.help = 'integration/task/opc-ua-start-monitor'\n\nTaskRegistry.registerTaskHandler('opc-ua-start-monitor', OPCUAStartMonitor)\n"]}