更新 main.js
This commit is contained in:
20
main.js
20
main.js
@@ -4,13 +4,13 @@
|
||||
'use strict';
|
||||
|
||||
const utils = require(__dirname + '/lib/utils');
|
||||
let modbus = null;
|
||||
let rsonoff = null;
|
||||
let fs;
|
||||
|
||||
let serialport = null;
|
||||
|
||||
let adapter = utils.Adapter({
|
||||
name: 'modbus',
|
||||
name: 'rsonoff',
|
||||
unload: stop
|
||||
});
|
||||
|
||||
@@ -50,9 +50,9 @@ adapter.on('message', function (obj) {
|
||||
});
|
||||
|
||||
function stop(callback) {
|
||||
if (modbus) {
|
||||
modbus.close();
|
||||
modbus = null;
|
||||
if (rsonoff) {
|
||||
rsonoff.close();
|
||||
rsonoff = null;
|
||||
}
|
||||
|
||||
if (adapter && adapter.setState && adapter.config && adapter.config.params) {
|
||||
@@ -72,16 +72,16 @@ let infoRegExp = new RegExp(adapter.namespace.replace('.', '\\.') + '\\.info\\.'
|
||||
|
||||
adapter.on('stateChange', (id, state) => {
|
||||
if (state && !state.ack && id && !infoRegExp.test(id)) {
|
||||
if (!modbus) {
|
||||
if (!rsonoff) {
|
||||
adapter.log.warn('No connection')
|
||||
} else {
|
||||
if (objects[id]) {
|
||||
modbus.write(id, state);
|
||||
rsonoff.write(id, state);
|
||||
} else {
|
||||
adapter.getObject(id, (err, data) => {
|
||||
if (!err) {
|
||||
objects[id] = data;
|
||||
modbus.write(id, state);
|
||||
rsonoff.write(id, state);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -809,8 +809,8 @@ function main() {
|
||||
parseConfig(options => {
|
||||
let Modbus;
|
||||
Modbus = require(__dirname + '/lib/master');
|
||||
modbus = new Modbus(options, adapter);
|
||||
modbus.start();
|
||||
rsonoff = new Modbus(options, adapter);
|
||||
rsonoff.start();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user