Skip to content

Commit

Permalink
Merge pull request #148 from biancode/major_update_serialport
Browse files Browse the repository at this point in the history
Major update serialport
  • Loading branch information
yaacov committed Sep 26, 2017
2 parents 66976ad + 79a8697 commit 363b98b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ build/Release
node_modules
modbus-serial
docs

package-lock\.json
11 changes: 6 additions & 5 deletions examples/buffered_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ var unitId = 1;
var minAddress = 0;
var maxInputAddress = 10001;
var maxAddress = 20001;
var bufferFactor = 8;

// 1...10000* address - 1 Coils (outputs) 0 Read/Write
// 10001...20000* address - 10001 Discrete Inputs 01 Read
// 30001...40000* address - 30001 Input Registers 04 Read
// 40001...50000* address - 40001 Holding Registers 03 Read/Write

var vector = {
getCoil: function(addr, unitID) { if (unitID === unitId && addr >= minAddress && addr < maxAddress) { return coils.readUInt8(addr); } },
getInputRegister: function(addr, unitID) { if (unitID === unitId && addr >= minAddress && addr < maxInputAddress) { return regsiters.readUInt16BE(addr); } },
getHoldingRegister: function(addr, unitID) { if (unitID === unitId && addr >= minAddress && addr < maxAddress) { return regsiters.readUInt16BE(addr); } },
getCoil: function(addr, unitID) { if (unitID === unitId && addr >= minAddress && addr < maxAddress) { return coils.readUInt8(addr * bufferFactor); } },
getInputRegister: function(addr, unitID) { if (unitID === unitId && addr >= minAddress && addr < maxInputAddress) { return regsiters.readUInt16BE(addr * bufferFactor); } },
getHoldingRegister: function(addr, unitID) { if (unitID === unitId && addr >= maxInputAddress && addr < maxAddress) { return regsiters.readUInt16BE(addr * bufferFactor); } },

setCoil: function(addr, value, unitID) { if (unitID === unitId && addr >= minAddress && addr < maxAddress) { coils.writeUInt8(value, addr); } },
setRegister: function(addr, value, unitID) { if (unitID === unitId && addr >= minAddress && addr < maxAddress) { regsiters.writeUInt16BE(value, addr); } }
setCoil: function(addr, value, unitID) { if (unitID === unitId && addr >= minAddress && addr < maxAddress) { coils.writeUInt8(value, addr * bufferFactor); } },
setRegister: function(addr, value, unitID) { if (unitID === unitId && addr >= minAddress && addr < maxAddress) { regsiters.writeUInt16BE(value, addr * bufferFactor); } }
};

// set the server to answer for modbus requests
Expand Down
2 changes: 1 addition & 1 deletion examples/write_complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function writeRegisters() {
// write 5 registers statrting at input registers
client.writeRegisters(1, [100, 90, 80, -200 + 65535, -100 + 65535])
.then(function(d) {
console.log("Write 10, 9, 8, -20, -10 to input registers", d); })
console.log("Write 100, 90, 80, -200, -100 to input registers", d); })
.catch(function(e) {
console.log(e.message); })
.then(writeHoldingRegsiters);
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "modbus-serial",
"version": "5.4.1",
"version": "6.0.0",
"description": "A pure JavaScript implemetation of MODBUS-RTU (Serial and TCP) for NodeJS.",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -36,8 +36,11 @@
"pump": "^1.0.2",
"sinon": "^1.17.7"
},
"engines": {
"node": "4.x || 6.x"
},
"dependencies": {
"debug": "^2.6.1",
"serialport": "^4.0.7"
"debug": "^3.0.1",
"serialport": "^5.0.0"
}
}

0 comments on commit 363b98b

Please sign in to comment.