forked from yaacov/node-modbus-serial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- tested tcp buffered with PLC Simulator
- new example for tcp buffered
- Loading branch information
Showing
8 changed files
with
142 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// create an empty modbus client | ||
//var ModbusRTU = require("modbus-serial"); | ||
var ModbusRTU = require("../index"); | ||
var client = new ModbusRTU(); | ||
|
||
// NPort Gateway 801D NetPort | ||
// client.connectTcpRTUBuffered("192.168.1.73", {port: 502, removeCrc: true}) | ||
// client.connectTcpRTUBuffered("192.168.1.73", {port: 502, removeCrc: false | ||
client.connectTcpRTUBuffered("192.168.1.20", {port: 502, removeCrc: false}) | ||
.then(setClient) | ||
.then(function () { | ||
console.log("Connected"); | ||
}) | ||
.catch(function (e) { | ||
console.log(e.message); | ||
}); | ||
|
||
function setClient() { | ||
// set the client's unit id | ||
// set a timout for requests default is null (no timeout) | ||
client.setID(1); | ||
client.setTimeout(2000); | ||
|
||
// run program | ||
run(); | ||
} | ||
|
||
function run() { | ||
// read the 4 registers starting at address 5 | ||
client.readHoldingRegisters(5, 4) | ||
.then(function (d) { | ||
console.log("Receive:", d.data); | ||
}) | ||
.catch(function (e) { | ||
console.log(e.message); | ||
}) | ||
.then(close); | ||
} | ||
|
||
function close() { | ||
client.close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.