Socket
Socket
Sign inDemoInstall

modbus-serial

Package Overview
Dependencies
2
Maintainers
1
Versions
123
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 8.0.4 to 8.0.5-no-serial-port

2

apis/connection.js

@@ -118,3 +118,3 @@ "use strict";

* @param {string} socket the instance of the net.Socket - required.
* @param {Object} options - the serial port options - optional.
* @param {Object} options - the TCP port options - optional.
* @param {Function} next the function to call next.

@@ -121,0 +121,0 @@ */

@@ -34,2 +34,6 @@ export class ModbusRTU {

connectAsciiSerial(path: string, options: SerialPortOptions): Promise<void>;
linkTCP(socket: string, options: TcpPortOptions, next: Function): void;
linkTcpRTUBuffered(socket: string, options: TcpRTUPortOptions, next: Function): void;
linkTelnet(socket: string, options: TelnetPortOptions, next: Function): void;
connectRTUSocket(socket: string, next: Function): void;

@@ -50,3 +54,3 @@ // Promise API

writeRegisters(dataAddress: number, values: Array<number> | Buffer): Promise<WriteMultipleResult>; // 16
isOpen: boolean;

@@ -108,2 +112,3 @@ }

family?: number;
ip?: string;
}

@@ -110,0 +115,0 @@

{
"name": "modbus-serial",
"version": "8.0.4",
"version": "8.0.5-no-serial-port",
"description": "A pure JavaScript implemetation of MODBUS-RTU (Serial and TCP) for NodeJS.",

@@ -40,5 +40,4 @@ "main": "index.js",

"dependencies": {
"debug": "^4.1.1",
"serialport": "^9.0.0"
"debug": "^4.1.1"
}
}
"use strict";
/* eslint-disable no-ternary */
var util = require("util");

@@ -111,2 +113,8 @@ var events = require("events");

// select char for start of slave frame (usually :)
this._startOfSlaveFrameChar =
(options.startOfSlaveFrameChar === undefined)
? 0x3A
: options.startOfSlaveFrameChar;
// disable auto open, as we handle the open

@@ -134,3 +142,3 @@ options.autoOpen = false;

// check buffer for start delimiter
var sdIndex = modbus._buffer.indexOf(0x3E); // ascii for '>', as this indicates slave replies
var sdIndex = modbus._buffer.indexOf(modbus._startOfSlaveFrameChar);
if(sdIndex === -1) {

@@ -137,0 +145,0 @@ // if not there, reset the buffer and return

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

| FC5 "Force Single Coil" | `writeCoil(coil, binary) //NOT setCoil` |
| FC6 "Preset Single Register"
| FC15 "Force Multiple Coil" | `writeRegister(addr, value)` |
| FC6 "Preset Single Register" | `writeRegister(addr, value)` |
| FC15 "Force Multiple Coil" | `writeCoils(addr, valueAry)` |
| FC16 "Preset Multiple Registers" | `writeRegisters(addr, valueAry)` |

@@ -286,3 +286,37 @@ | FC43/14 "Read Device Identification" (supported ports: TCP, RTU) | `readDeviceIdentification(id, obj)` |

```
----
###### Read and Write Modbus ASCII
``` javascript
// create an empty modbus client
var Modbus = require("modbus-serial");
var client = new Modbus();
// open connection to a serial port
client.connectAsciiSerial(
"/dev/ttyUSB0",
{
baudRate: 9600,
startOfSlaveFrameChar: 0x3A // optional: slave frame delimiter
},
write);
function write() {
client.setID(1);
// write the values 0, 0xffff to registers starting at address 5
// on device number 1.
client.writeRegisters(5, [0 , 0xffff])
.then(read);
}
function read() {
// read the 2 registers starting at address 5
// on device number 1.
client.readHoldingRegisters(5, 2)
.then(console.log);
}
```
----
to get more see [Examples](https://github.com/yaacov/node-modbus-serial/wiki)

@@ -289,0 +323,0 @@

@@ -21,3 +21,6 @@ "use strict";

var AsciiPort = require("./../../ports/asciiport");
port = new AsciiPort("/dev/null", {});
port = new AsciiPort(
"/dev/null",
{ startOfSlaveFrameChar: 0x3E } // optional slave frame char ('>')
);
});

@@ -64,3 +67,3 @@

setTimeout(function() {
port._client.receive(Buffer.from(">", "ascii"));
port._client.receive(Buffer.from(">", "ascii")); // changed slave frame char
port._client.receive(Buffer.from("11", "ascii"));

@@ -81,3 +84,3 @@ port._client.receive(Buffer.from("03", "ascii"));

it("should return a valid Modbus RTU exception", function(done) {
it("should return a valid Modbus ASCII exception", function(done) {
port.once("data", function(data) {

@@ -118,3 +121,3 @@ expect(data.toString("hex")).to.equal("1183044136");

it("Illegal start chars, should synchronize to valid Modbus RTU message", function(done) {
it("Illegal start chars, should synchronize to valid Modbus ASCII message", function(done) {
port.once("data", function(data) {

@@ -147,3 +150,3 @@ expect(data.toString("hex")).to.equal("110306ae415652434049ad");

it("Illegal end chars, should return a valid Modbus RTU message", function(done) {
it("Illegal end chars, should return a valid Modbus ASCII message", function(done) {
port.once("data", function(data) {

@@ -176,3 +179,3 @@ expect(data.toString("hex")).to.equal("110306ae415652434049ad");

it("should return a valid Modbus RTU message on illegal chars", function(done) {
it("should return a valid Modbus ASCII message on illegal chars", function(done) {
port.once("data", function(data) {

@@ -203,3 +206,3 @@ expect(data.toString("hex")).to.equal("110306ae415652434049ad");

describe("#write", function() {
it("should write a valid RTU message to the port", function() {
it("should write a valid Modbus ASCII message to the port", function() {
port.write(Buffer.from("1103006B00037687", "hex"));

@@ -206,0 +209,0 @@ expect(port._client._data.toString("ascii")).to.equal(":1103006B00037E\r\n");

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc