Giter Site home page Giter Site logo

Comments (7)

dresende avatar dresende commented on May 27, 2024

Post your tcp master code to see if I can spot anything.

from stream.

IlhanSeven avatar IlhanSeven commented on May 27, 2024
function connectToSlave() {
	modbus.tcp.connect(modbusPort, modbusIp, { debug: null }, (err, connection) => {
    
		if(err) {
			//throw err;
			console.log("Will try to reconnect in 3 seconds");
			setTimeout(connectToSlave, 3000);
		} else {
			console.log("Connected to the slave");
			setInterval(function(){
				
				var valuesArray = new Array();
				for(var i = 42001; i <= 42017; i++) {
					
					valuesArray.push(gatewayMap[i]);
				}
				
				connection.writeMultipleRegisters({ address: 42001, values: valuesArray}, (err, info) => {
					
					if(err) throw err;
				});
				
				connection.readInputRegisters({ address: 42101, quantity: 7}, (err, res) => {
					
					if(err) throw err;
					for(var i = 0; i<7; i++) {
						gatewayMap[i+42101] = res.response.data[i];
					}
					io.emit('updateInputRegisters', { values: gatewayMap });
				})
				
				connection.readInputRegisters({ address: 49001, quantity: 6}, (err, res) => {
					
					if(err) throw err;
					for(var i = 0; i<6; i++) {
						gatewayMap[i+49001] = res.response.data[i];
					}
					io.emit('updateInputRegisters', { values: gatewayMap });
				})
				
			}, 1000);
		}
	});
}

from stream.

dresende avatar dresende commented on May 27, 2024

I was not thinking properly, missing my coffee. Your initial error is not related to docker, it's telling you your other end closed the socket. Perhaps because you have a setInterval the connection is ended in the meanwhile and you keep requesting information but the socket stream is closed.

from stream.

dresende avatar dresende commented on May 27, 2024

I'm also not sure if it's not a problem with io.

from stream.

IlhanSeven avatar IlhanSeven commented on May 27, 2024

you might be right about setInterval. Do you have any suggestions or alternatives to it?

from stream.

dresende avatar dresende commented on May 27, 2024

I would store the interval id. Something like this:

let timer = setInterval(...);

And after that I would listen for the error event in the connection object and would stop the interval and reconnect.

connection.on("error", (err) => {
    clearInterval(timer);
    console.log(err);

    // reconnect();
});

from stream.

dresende avatar dresende commented on May 27, 2024

Reopen if it didn't solve and you have any more information.

from stream.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.