admin管理员组

文章数量:1419234

I am trying to connect to a PLC using modbus TCP/IP (modbus-serial node on node.js)

This is crucial part of the code

const modbusClient = new ModbusRTU();

modbusClient.connectTCP("192.168.0.10", { port: 502 });
modbusClient.setTimeout(5000);
modbusClient.setID(1);

modbusClient.readHoldingRegisters(2, 1)
    .then(function(data) {
        console.log(data);
    });

All I get is this error

PortNotOpenError {
  name: 'PortNotOpenError',
  message: 'Port Not Open',
  errno: 'ECONNREFUSED'
}

The port is actually open. I can poll the data using modbus-tcp node in node-red on the same computer and it works. Am I missing anything?

本文标签: nodejsNo connection to a PLC using modbusserialStack Overflow