Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

modbus-serial

Package Overview
Dependencies
Maintainers
1
Versions
123
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

modbus-serial - npm Package Compare versions

Comparing version 2.0.1 to 2.1.1

connection_api.js

3

index.js

@@ -426,2 +426,5 @@ 'use strict';

// add the connection shorthand API
require('./connection_api')(ModbusRTU);
// add the promise API

@@ -428,0 +431,0 @@ require('./promise_api')(ModbusRTU);

2

package.json
{
"name": "modbus-serial",
"version": "2.0.1",
"version": "2.1.1",
"description": "A pure JavaScript implemetation of MODBUS-RTU (and TCP) for NodeJS.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -19,7 +19,5 @@ 'use strict';

/**
* Take a modbus serial function and convert it
* to use promises
* Take a modbus serial function and convert it to use promises.
*
* @param {function} f the function to convert
*
* @return a function that calls function "f" and return a promise.

@@ -34,3 +32,3 @@ */

* if we have a callback, use it
* o/w build a promise
* o/w build a promise.
*/

@@ -44,4 +42,7 @@ if (next) {

function cb(err, data) {
if (err) reject(err);
else resolve(data);
if (err) {
reject(err);
} else {
resolve(data);
}
}

@@ -60,5 +61,5 @@

/**
* Adds promise API to a modbus-serial client
* Adds promise API to a Modbus objext
*
* @param {ModbusRTU} client the ModbusRTU object.
* @param {ModbusRTU} Modbus the ModbusRTU object.
*/

@@ -73,3 +74,3 @@ var addPromiseAPI = function(Modbus) {

// convert functions to promises
// convert functions to return promises
cl.readCoils = convert(cl.writeFC1);

@@ -76,0 +77,0 @@ cl.readDiscreteInputs = convert(cl.writeFC2);

@@ -20,4 +20,4 @@ # modbus-serial

- [API](#api)
- [Methods That return a promise](#methods-that-return-a-promise)
- [API Promises](#api-promises)
- [API connection shorthand](#api-connection-shorthand)

@@ -295,6 +295,6 @@ #### Install

----
###### API promises
----
#### Methods That return a promise
All the communication functions have an wrapper function that use
The communication functions have a wrapper function that use
a pre-set unit-id and return a promise.

@@ -307,3 +307,3 @@

// read 8 discrete inputs starting at input 10
// (we use the unit id 1, we set earlier)
// (function use the unit id 1, we set earlier)
client.readDiscreteInputs(10, 8)

@@ -315,3 +315,2 @@ .then(function(data) {

###### API promises
----

@@ -384,1 +383,72 @@ ##### .setID(id)

----
###### API connection shorthand
----
The shorthand connection functions creates a port and open it.
Long way, without shorthand:
``` javascript
// open a serial port
var SerialPort = require("serialport").SerialPort;
var serialPort = new SerialPort("/dev/ttyUSB0", {baudrate: 9600});
// create a modbus client using the serial port
var ModbusRTU = require("modbus-serial");
var client = new ModbusRTU(serialPort);
// open connection to a serial port
client.open();
// tell your coffee machine to do something ...
```
Using shorthand:
``` javascript
// create an empty modbus client
var ModbusRTU = require("modbus-serial");
var client = new ModbusRTU();
// open connection to a serial port
client.connectRTU("/dev/ttyUSB0", {baudrate: 9600});
// tell your robot to do something ...
```
Using shorthand (TCP):
``` 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");
// tell your robot to do something ...
```
----
##### .connectRTU (path, options, callback)
Connect using serial port.
###### path
The port path (e.g. "/dev/ttyS0")
###### options (optional)
The options for this connection.
###### callback (optional)
Called once the client is connected.
----
##### .connectTCP (ip, options, callback)
Connect using tcp/ip.
###### ip
The port ip (e.g. "24.230.1.42")
###### options (optional)
The options for this connection.
###### callback (optional)
Called once the client is connected.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc