node-red-contrib-iiot-opcua
Version:
An Industrial IoT OPC UA toolbox contribution package for Node-RED based on node-opcua.
77 lines (74 loc) • 3.19 kB
JavaScript
/*
The BSD 3-Clause License
Copyright 2022 - DATATRONiQ GmbH (https://datatroniq.com)
Copyright (c) 2018-2022 Klaus Landsdorf (http://node-red.plus/)
All rights reserved.
node-red-contrib-iiot-opcua
*/
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const opcua_iiot_core_connector_1 = __importDefault(require("./core/opcua-iiot-core-connector"));
const opcua_iiot_core_1 = require("./core/opcua-iiot-core");
/**
* Event Node-RED node.
*
* @param RED
*/
module.exports = function (RED) {
// SOURCE-MAP-REQUIRED
function OPCUAIIoTFlexConnector(config) {
RED.nodes.createNode(this, config);
this.name = config.name;
this.showStatusActivities = config.showStatusActivities;
this.showErrors = config.showErrors;
this.connector = RED.nodes.getNode(config.connector);
let self = this;
self.iiot = {};
this.status({ fill: 'blue', shape: 'ring', text: 'new' });
this.on('input', (msg) => {
opcua_iiot_core_connector_1.default.internalDebugLog('connector change request input');
const payload = msg.payload;
if (self.connector) {
if (payload.endpoint && payload.endpoint.includes('opc.tcp:')) {
opcua_iiot_core_connector_1.default.internalDebugLog('connector change possible');
opcua_iiot_core_connector_1.default.internalDebugLog(payload);
self.connector.functions.restartWithNewSettings(payload, () => {
opcua_iiot_core_connector_1.default.internalDebugLog('connector change injected');
this.send(msg);
});
}
else {
opcua_iiot_core_connector_1.default.internalDebugLog('Connector Change Not Possible - Wrong Endpoint');
this.error(new Error('Connector Change Not Possible - Wrong Endpoint'), msg);
}
}
else {
opcua_iiot_core_connector_1.default.internalDebugLog('Connector Change Not Possible - No Connector');
this.error(new Error('Connector Change Not Possible - No Connector'), msg);
}
});
const statusHandler = (status) => {
this.status(status);
};
const errorHandler = (err, msg) => {
this.error(err, msg);
};
const onAlias = (event, callback) => {
// @ts-ignore
this.on(event, callback);
};
(0, opcua_iiot_core_1.registerToConnector)(this, statusHandler, onAlias, errorHandler);
this.on('close', (done) => {
self.removeAllListeners();
(0, opcua_iiot_core_1.deregisterToConnector)(this, () => {
(0, opcua_iiot_core_1.resetIiotNode)(this);
done();
});
});
}
RED.nodes.registerType('OPCUA-IIoT-Flex-Connector', OPCUAIIoTFlexConnector);
};
//# sourceMappingURL=opcua-iiot-flex-connector.js.map