yaacov / node-modbus-serial

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

Parallel ModbusTCP #39

Closed jovermier closed 8 years ago

jovermier commented 8 years ago

I created an expressjs route that when called does:

Simplified version: `app.get('/modbus', function(req, res){ let client = new ModbusRTU();

// open connection to a tcp line client.connectTCP("192.168.1.42", function() { client.readHoldingRegisters(1, 1, function(err, data) { if (err) { res.send(err); } else{ res.send(data); } }); }); }`

I have a frontend app that polls this service. Everything works perfectly until I open up two instances of the web page. When the service has multiple connections to it there seems to be an issue. The time to get the response goes up an order of magnitude.

Another way I noticed this issue is when using asyncjs and reading a bunch of modbus registers in parallel.

yaacov commented 8 years ago

Hi, thanks for noticing that !

In the real app, do you have one global connected client or you create and connect each time a page is called ?

If you create a client and connect each time you get a http request: a. try to close the connection after using it - client.close() b. try to create a global client connect it, and after connection is made, start listening to http requests and use this already connected client.

yaacov commented 8 years ago

Everything works perfectly until I open up two instances of the web page.

Can your IoT device handle two open tcp sockets ?

jovermier commented 8 years ago

I tried client.close() which solved the issue. Thanks!

yaacov commented 8 years ago

:-)