node-omron-fins
node-omron-fins copied to clipboard
Patch to read and write to return the sid
To be able to track multiple parallel requests, I simply added: return self.header.SID; to FinsClient.prototype.read and FinsClient.prototype.write.
It is possible to have this patch in the code?
Thank you. GT
client.read('D00000', 5, function (err, bytes) { console.log("Bytes: ", bytes); console.log("SID: ", client.header.SID); }); Please try this.
Mhhh..... This way I can see two different problems: I need to use a callback that otherwise I don't need, and because I'm using a single client to run multiple different read & write, and I need the SID to be able to identify the correct answer, so the "client" object in the meantime could have changed.
The way I handle SIDs without the need for callbacks or for adding a return is in the client.on('reply'). Here I am expecting 17 SIDs and on getting them all we close the connection. They often do not arrive in order therefore we need an if / else or switch statement.
client.on('reply',function(msg) {
if(msg.sid==1) {
// code to handle SID 1
}
else if(msg.sid==2) {
// code to handle SID 2
}
else if(msg.sid==3) {
// code to handle SID 3
}
// etc
else if(msg.sid > 17){
console.log("ERROR invalid SID: " + msg.sid);
client.close();
console.log("Return 10");
return process.exit(10);
}
if(++replyCounter==17){
client.close();
}
}