Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functions return SID value for matching the reply #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/fins_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ FinsClient.prototype.read = function(address,regsToRead,callback) {
var packet = _buildPacket([header,command,commandData]);
var buffer = Buffer.from(packet);
this.socket.send(buffer,0,buffer.length,self.port,self.host,callback);
return self.header.SID;
};

FinsClient.prototype.readMultiple = function() { // no callback not sure how to handle this with an unknown number of arguments
Expand All @@ -311,6 +312,7 @@ FinsClient.prototype.readMultiple = function() { // no callback not sure how to
var packet = _buildPacket([header,command,commandData]);
var buffer = Buffer.from(packet);
this.socket.send(buffer,0,buffer.length,self.port,self.host); // we do not return a callback
return self.header.SID;
};

FinsClient.prototype.transfer = function(sourceAddress,destAddress,regsToRead,callback) {
Expand All @@ -325,6 +327,7 @@ FinsClient.prototype.transfer = function(sourceAddress,destAddress,regsToRead,ca
var packet = _buildPacket([header,command,commandData]);
var buffer = Buffer.from(packet);
this.socket.send(buffer,0,buffer.length,self.port,self.host,callback);
return self.header.SID;
};

FinsClient.prototype.write = function(address,dataToBeWritten,callback) {
Expand All @@ -337,8 +340,7 @@ FinsClient.prototype.write = function(address,dataToBeWritten,callback) {
// if address matches a bit, has a 2 character memory address eg HB, we validate the data to be written
if(address.match( /([A-Z]){2}([0-9]*)/ )){
if(dataToBeWritten>1){
console.log("Exiting before attempting to write: Bits can only be 0=0FF or 1=ON");
process.exit(1);
throw new Error("Bits can only be 0 (Off) or 1 (On)");
}
}
else{
Expand All @@ -350,6 +352,7 @@ FinsClient.prototype.write = function(address,dataToBeWritten,callback) {
var packet = _buildPacket([header,command,commandData]);
var buffer = Buffer.from(packet);
this.socket.send(buffer,0,buffer.length,self.port,self.host,callback);
return self.header.SID;
};

FinsClient.prototype.fill = function(address,dataToBeWritten,regsToWrite,callback) {
Expand All @@ -364,6 +367,7 @@ FinsClient.prototype.fill = function(address,dataToBeWritten,regsToWrite,callbac
var packet = _buildPacket([header,command,commandData]);
var buffer = Buffer.from(packet);
this.socket.send(buffer,0,buffer.length,self.port,self.host,callback);
return self.header.SID;
};

FinsClient.prototype.run = function(callback) {
Expand All @@ -374,6 +378,7 @@ FinsClient.prototype.run = function(callback) {
var packet = _buildPacket([header,command]);
var buffer = Buffer.from(packet);
this.socket.send(buffer,0,buffer.length,self.port,self.host,callback);
return self.header.SID;
};

FinsClient.prototype.stop = function(callback) {
Expand All @@ -384,6 +389,7 @@ FinsClient.prototype.stop = function(callback) {
var packet = _buildPacket([header,command]);
var buffer = Buffer.from(packet);
this.socket.send(buffer,0,buffer.length,self.port,self.host,callback);
return self.header.SID;
};


Expand All @@ -395,6 +401,7 @@ FinsClient.prototype.status = function(callback) {
var packet = _buildPacket([header,command]);
var buffer = Buffer.from(packet);
this.socket.send(buffer,0,buffer.length,self.port,self.host,callback);
return self.header.SID;
};


Expand Down