modbus-serial
Advanced tools
Comparing version 8.0.4 to 8.0.5-no-serial-port
@@ -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"); |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
308313
1
8104
331
1
- Removedserialport@^9.0.0
- Removed@serialport/binding-abstract@9.2.3(transitive)
- Removed@serialport/binding-mock@9.2.4(transitive)
- Removed@serialport/bindings@9.2.8(transitive)
- Removed@serialport/parser-byte-length@9.2.4(transitive)
- Removed@serialport/parser-cctalk@9.2.4(transitive)
- Removed@serialport/parser-delimiter@9.2.4(transitive)
- Removed@serialport/parser-inter-byte-timeout@9.2.4(transitive)
- Removed@serialport/parser-readline@9.2.4(transitive)
- Removed@serialport/parser-ready@9.2.4(transitive)
- Removed@serialport/parser-regex@9.2.4(transitive)
- Removed@serialport/stream@9.2.4(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbindings@1.5.0(transitive)
- Removedbl@4.1.0(transitive)
- Removedbuffer@5.7.1(transitive)
- Removedchownr@1.1.4(transitive)
- Removeddecompress-response@6.0.0(transitive)
- Removeddeep-extend@0.6.0(transitive)
- Removeddetect-libc@2.0.3(transitive)
- Removedend-of-stream@1.4.4(transitive)
- Removedexpand-template@2.0.3(transitive)
- Removedfile-uri-to-path@1.0.0(transitive)
- Removedfs-constants@1.0.0(transitive)
- Removedgithub-from-package@0.0.0(transitive)
- Removedieee754@1.2.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedini@1.3.8(transitive)
- Removedmimic-response@3.1.0(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp-classic@0.5.3(transitive)
- Removednan@2.19.0(transitive)
- Removednapi-build-utils@1.0.2(transitive)
- Removednode-abi@3.63.0(transitive)
- Removedonce@1.4.0(transitive)
- Removedprebuild-install@7.1.2(transitive)
- Removedpump@3.0.0(transitive)
- Removedrc@1.2.8(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsemver@7.6.2(transitive)
- Removedserialport@9.2.8(transitive)
- Removedsimple-concat@1.0.1(transitive)
- Removedsimple-get@4.0.1(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedstrip-json-comments@2.0.1(transitive)
- Removedtar-fs@2.1.1(transitive)
- Removedtar-stream@2.2.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwrappy@1.0.2(transitive)