Skip to content

Commit

Permalink
modbus worker (#399)
Browse files Browse the repository at this point in the history
* link TCP port with existing socket

* add linkTelnet

* add linkTcpRTUBuffered

* worker api
  • Loading branch information
yarosdev authored Mar 22, 2021
1 parent 9e8a060 commit 9d42e84
Show file tree
Hide file tree
Showing 3 changed files with 426 additions and 0 deletions.
31 changes: 31 additions & 0 deletions apis/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const Worker = require("../worker/index");

module.exports = function(Modbus) {
const cl = Modbus.prototype;


cl.setWorkerOptions = function(options) {
if (this._worker) {
this._worker.setOptions(options);
} else {
this._worker = new Worker(this, options);
}
};

cl.send = function(request) {
if(!this._worker) {
this._worker = new Worker(this);
}

return this._worker.send(request);
};

cl.poll = function(options) {
if(!this._worker) {
this._worker = new Worker(this);
}

return this._worker.poll(options);
};

};
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,9 @@ require("./apis/connection")(ModbusRTU);
// add the promise API
require("./apis/promise")(ModbusRTU);

// add worker API
require("./apis/worker")(ModbusRTU);

// exports
module.exports = ModbusRTU;
module.exports.TestPort = require("./ports/testport");
Expand Down
Loading

0 comments on commit 9d42e84

Please sign in to comment.