Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Asynchronous handling supported also here
console.log("set register", addr, value, unitID);
holdingValue = value;
return;
},
setCoil: function(addr, value, unitID) {
// Asynchronous handling supported also here
console.log("set coil", addr, value, unitID);
coilValue = Boolean(value);
return;
},
};
// set the server to answer for modbus requests
console.log("ModbusTCP listening on modbus://127.0.0.1:5028");
var serverTCP = new ModbusRTU.ServerTCP(vector, { host: "0.0.0.0", port: 5028, debug: true, unitID: 1 });
serverTCP.on("socketError", function(err){
// Handle socket error if needed, can be ignored
console.error(err);
});
node.startServer = function () {
try {
if (node.modbusServer === null) {
try {
node.modbusServer = new ModbusRTU.ServerTCP(node.vector, {
host: node.serverAddress,
port: node.serverPort,
debug: node.logEnabled,
unitID: node.unitId
})
} catch (err) {
node.error(err, { payload: 'server net error -> for port 502 on unix, you have to be a super user' })
}
node.modbusServer.on('socketError', function (err) {
internalDebugLog(err.message)
if (node.showErrors) {
node.warn(err)
}
mbBasics.setNodeStatusTo('error', node)