modbus-serial
Advanced tools
Comparing version 2.1.1 to 2.1.3
{ | ||
"name": "modbus-serial", | ||
"version": "2.1.1", | ||
"version": "2.1.3", | ||
"description": "A pure JavaScript implemetation of MODBUS-RTU (and TCP) for NodeJS.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -70,29 +70,47 @@ # modbus-serial | ||
---- | ||
###### Logger | ||
``` javascript | ||
// create an empty modbus client | ||
var ModbusRTU = require("modbus-serial"); | ||
var client = new ModbusRTU(); | ||
// open connection to a tcp line | ||
client.connectTCP("192.168.1.42", run); | ||
// read the values of 10 registers starting at address 0 | ||
// on device number 1. and log the values to the console. | ||
function run() { | ||
client.setID(1); | ||
client.readInputRegisters(0, 10) | ||
.then(console.log) | ||
.then(run); | ||
} | ||
``` | ||
---- | ||
###### Read and Write | ||
``` javascript | ||
var SerialPort = require("serialport").SerialPort; | ||
var serialPort = new SerialPort("/dev/ttyUSB0", {baudrate: 9600}); | ||
// create an empty modbus client | ||
var ModbusRTU = require("modbus-serial"); | ||
var modbusRTU = new ModbusRTU(serialPort); | ||
var client = new ModbusRTU(); | ||
modbusRTU.open(); | ||
// open connection to a serial port | ||
client.connectRTU("/dev/ttyUSB0", {baudrate: 9600}, write); | ||
// write the values 0, 0xffff to registers starting at address 5 | ||
// on device number 1. | ||
setTimeout(function() { | ||
modbusRTU.writeFC16(1, 5, [0 , 0xffff]); | ||
}, 1000); | ||
function write() { | ||
client.setID(1); | ||
// read the values of 2 registers starting at address 5 | ||
// on device number 1. and log the values to the console. | ||
setTimeout(function() { | ||
modbusRTU.writeFC4(1, 5, 2, function(err, data) { | ||
console.log(data); | ||
}); | ||
}, 2000); | ||
// write the values 0, 0xffff to registers starting at address 5 | ||
// on device number 1. | ||
client.writeRegisters(5, [0 , 0xffff]) | ||
.then(read); | ||
} | ||
// close communication | ||
setTimeout(function() { | ||
serialPort.close(); | ||
}, 3000); | ||
function read() { | ||
// read the 2 registers starting at address 5 | ||
// on device number 1. | ||
client.readHoldingRegisters(5, 2) | ||
.then(console.log); | ||
} | ||
``` | ||
@@ -102,8 +120,9 @@ ---- | ||
``` javascript | ||
var SerialPort = require("serialport").SerialPort; | ||
var serialPort = new SerialPort("/dev/ttyUSB0", {baudrate: 9600}); | ||
// create an empty modbus client | ||
var ModbusRTU = require("modbus-serial"); | ||
var modbusRTU = new ModbusRTU(serialPort); | ||
var client = new ModbusRTU(); | ||
modbusRTU.open(); | ||
// open connection to a serial port | ||
client.connectRTU("/dev/ttyUSB0", {baudrate: 9600}); | ||
client.setID(1); | ||
@@ -113,3 +132,3 @@ // read the values of 10 registers starting at address 0 | ||
setInterval(function() { | ||
modbusRTU.writeFC4(1, 0, 10, function(err, data) { | ||
client.readHoldingRegisters(0, 10, function(err, data) { | ||
console.log(data.data); | ||
@@ -122,8 +141,9 @@ }); | ||
``` javascript | ||
var TcpPort = require("modbus-serial").TcpPort; | ||
var tcpPort = new TcpPort("192.168.1.42"); | ||
// create an empty modbus client | ||
var ModbusRTU = require("modbus-serial"); | ||
var modbusRTU = new ModbusRTU(tcpPort); | ||
var client = new ModbusRTU(); | ||
modbusRTU.open(); | ||
// open connection to a tcp line | ||
client.connectTCP("192.168.1.42"); | ||
client.setID(1); | ||
@@ -133,3 +153,3 @@ // read the values of 10 registers starting at address 0 | ||
setInterval(function() { | ||
modbusRTU.writeFC4(1, 0, 10, function(err, data) { | ||
client.readHoldingRegisters(0, 10, function(err, data) { | ||
console.log(data.data); | ||
@@ -142,20 +162,16 @@ }); | ||
``` javascript | ||
var SerialPort = require("serialport").SerialPort; | ||
var serialPort = new SerialPort("/dev/ttyUSB0", {baudrate: 9600}); | ||
// create an empty modbus client | ||
var ModbusRTU = require("modbus-serial"); | ||
var modbusRTU = new ModbusRTU(serialPort); | ||
var client = new ModbusRTU(); | ||
modbusRTU.open(); | ||
// open connection to a serial port | ||
client.connectRTU("/dev/ttyUSB0", {baudrate: 9600}); | ||
client.setID(1); | ||
// read 2 16bit-registers to get one 32bit number | ||
setTimeout(function() { | ||
modbusRTU.writeFC4(1, 5, 2, function(err, data) { | ||
client.readInputRegisters(5, 2, function(err, data) { | ||
console.log(data.buffer.readUInt32BE()); | ||
}); | ||
}, 2000); | ||
// close communication | ||
setTimeout(function() { | ||
serialPort.close(); | ||
}, 3000); | ||
}, 1000); | ||
``` | ||
@@ -162,0 +178,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50557
17
1106
466