yaacov / node-modbus-serial

A pure JavaScript implemetation of MODBUS-RTU (and TCP) for NodeJS
ISC License
640 stars 241 forks source link

Modbus TCP #43

Closed yarosdev closed 7 years ago

yarosdev commented 7 years ago

How to implement Modbus TCP protocol using modbus-serial? Its has modbus over tcp, etc.

yaacov commented 7 years ago
var ModbusRTU = require("modbus-serial");
var client = new ModbusRTU();

// open connection to a tcp line
client.connectTCP("192.168.1.42", run);

// read the values of 10 registers starting at address 0
// on device number 1. and log the values to the console.
function run() {
    client.setID(1);

    client.readInputRegisters(0, 10)
        .then(console.log)
        .then(run);
}
yaacov commented 7 years ago

@Yarisrespect does that answer your question ?

yarosdev commented 7 years ago

I saw that, but it is modbus over tcp I am talking about Modbus TCP wich is without CRC

yarosdev commented 7 years ago

Modbus RTU over TCP

Simply put, this is a Modbus RTU message transmitted with a TCP/IP wrapper and sent over a network instead of serial lines. The Server does not have a SlaveID since it uses an IP Address instead.

Modbus TCP

A Modbus Messaging Implementation Guide provided by Schneider Automation outlines a modified protocol specifically for use over TCP/IP. The official Modbus specification can be found at www.modbus.org/specs.php . The main differences between Modbus RTU and Modbus TCP are outlined here.

from http://www.simplymodbus.ca/TCP.htm

yaacov commented 7 years ago

ok :-)

.connectTCP - Modbus TCP/IP or Modbus TCP — This is a Modbus variant used for communications over TCP/IP networks, connecting over port 502.

.connectTelnet - Wraps the Modbus RTU and send it over TCP using telnet. .connectC701 - Wraps the Modbus RTU and send it over UDP using the C701 proprietary protocol.

yaacov commented 7 years ago

@Yarisrespect do you need Modbus TCP or Modbus RTU/IP ?

Modbus TCP , we have using .connectTCP Modbus RTU/IP , we do not have. but the telnet variant sounds very similar.

yarosdev commented 7 years ago

I mean that this lib sends whole RTU. But in some cases you need send only PDU.

And one more question. Why do _transactionId in ModbusRTU object always equals 1?

yaacov commented 7 years ago

I meen that this lib sends whole RTU. But in some cases you need send only PDU.

no, the tcp variant , ascii variant and rtu variant send different frame formats, they will not work o/w :-)

Why do transaction Id in ModbusRTU object always equals 1?

a. only the tcp frame format has a transaction identifier ( see answer to question 1 ) b. it is not, transaction identifier is automatically set and is different for each transaction.

yarosdev commented 7 years ago

I am sorry. You have a point there.

yaacov commented 7 years ago

@Yarisrespect you can look at the tests: this transaction has an id of 1 ( see the second byte of frame ): https://github.com/yaacov/node-modbus-serial/blob/master/test/ports/tcpport.test.js#L73 and the next transaction has an id of 2 https://github.com/yaacov/node-modbus-serial/blob/master/test/ports/tcpport.test.js#L82

yarosdev commented 7 years ago

Thank you a lot) If I want to send CRC with PDU togeher over TCP I should just implement new port that would send it. Right?

yaacov commented 7 years ago

i think the telnet port is doing exactly what you want :-)

yaacov commented 7 years ago

Thank you a lot) If I want to send CRC with PDU togeher over TCP I should just implement new port that would send it. Right?

@Yarisrespect a. yes b. I think that the telnet port is doing just that, see comment above ^^