|
|
var net = require('net'),
|
|
|
redis = require('redis'),
|
|
|
_ = require('lodash'),
|
|
|
index = require('../index.js'),
|
|
|
async = require('async'),
|
|
|
index = require('../src/index.js'),
|
|
|
readerConfig = require('./readerConfig.js');
|
|
|
|
|
|
var r = redis.createClient();
|
...
|
...
|
@@ -142,7 +143,15 @@ function connectAllReaders() |
|
|
freq: 10
|
|
|
}];
|
|
|
|
|
|
connectReader(ip, 9761, filter, frequencys, reader.inventory_time, reader.ants, reader.group);
|
|
|
// 初次连接最多连接5次
|
|
|
async.retry(5, function(cb, results){
|
|
|
connectReader(ip, 9761, filter, frequencys, reader.inventory_time, reader.ants, reader.group, cb);
|
|
|
|
|
|
}, function(err, results){
|
|
|
if(err){
|
|
|
console.error(err);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -156,8 +165,9 @@ function connectAllReaders() |
|
|
* @param inventoryTime 盘点时间
|
|
|
* @param power 各天线的功率
|
|
|
* @param group 读写器所在组
|
|
|
* @param callback 回调函数
|
|
|
*/
|
|
|
function connectReader(host, port, filter, frequencys, inventoryTime, power, group)
|
|
|
function connectReader(host, port, filter, frequencys, inventoryTime, power, group, callback)
|
|
|
{
|
|
|
index.start({
|
|
|
host: host,
|
...
|
...
|
@@ -167,7 +177,7 @@ function connectReader(host, port, filter, frequencys, inventoryTime, power, gro |
|
|
inventoryTime: inventoryTime,
|
|
|
power: power,
|
|
|
group: group
|
|
|
}, function (dat) {
|
|
|
}, function (connected, dat) {
|
|
|
var onEpcs = [],
|
|
|
offEpcs = [],
|
|
|
redisEpcs = [];
|
...
|
...
|
@@ -216,6 +226,12 @@ function connectReader(host, port, filter, frequencys, inventoryTime, power, gro |
|
|
r.hset(group, 'on', JSON.stringify(onEpcs.concat(redisEpcs)), function(){});
|
|
|
r.hset(group, 'off', JSON.stringify(offEpcs), function(){});
|
|
|
|
|
|
if(connected){
|
|
|
callback(null, connected);
|
|
|
}else{
|
|
|
callback(new Error('连接读写器'+host+'错误'), connected);
|
|
|
}
|
|
|
|
|
|
});
|
|
|
}
|
|
|
|
...
|
...
|
|