addlink new func (modbus)
This commit is contained in:
@@ -590,6 +590,98 @@ router
|
||||
n();
|
||||
})
|
||||
})
|
||||
.post('/getmodbustype', (req, res, n) => {
|
||||
if (!config.permission.modbus) return n('ERR9000');
|
||||
let arr = req.body;
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
|
||||
let query = "select io.`type` \
|
||||
from ??.?? io \
|
||||
left join ??.?? dev \
|
||||
on dev.`uid` = io.`devuid` \
|
||||
where \
|
||||
dev.`uid` = ? \
|
||||
group by io.`type` \
|
||||
order by io.`type` ";
|
||||
let param = [config.db.db5, 'iolist', config.db.db5, 'device', arr.data.id];
|
||||
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if (err) return rt.err(res, err, n, 'ERR8000');
|
||||
|
||||
res.api_res = {
|
||||
record: tool.checkArray(row)
|
||||
}
|
||||
|
||||
n();
|
||||
})
|
||||
})
|
||||
.post('/getmodbusport', (req, res, n) => {
|
||||
if (!config.permission.modbus) return n('ERR9000')
|
||||
let arr = req.body;
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
if (!arr.data.type) return n('ERR0009');
|
||||
|
||||
let type = arr.data.type;
|
||||
if (type == 5) type = 1;
|
||||
if (type == 6) type = 3;
|
||||
|
||||
if (type == 3 || type == 4) {
|
||||
let query = "select a.`name`, a.`portnum` \
|
||||
from ??.?? a \
|
||||
left join ??.?? io \
|
||||
on io.`uid` = a.`iouid` \
|
||||
left join ??.?? dev \
|
||||
on dev.`uid` = io.`devuid` \
|
||||
where \
|
||||
io.`type` = ? \
|
||||
and dev.`uid` = ? ";
|
||||
let param = [config.db.db5, 'aioset', config.db.db5, 'iolist', config.db.db5, 'device', type, arr.data.id];
|
||||
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if (err) return rt.err(res, err, n, 'ERR8000');
|
||||
|
||||
res.api_res = {
|
||||
record: tool.checkArray(row)
|
||||
}
|
||||
|
||||
n();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == 1 || type == 2) {
|
||||
let query = "select * \
|
||||
from ??.?? io \
|
||||
left join ??.?? dev \
|
||||
on dev.`uid` = io.`devuid` \
|
||||
where \
|
||||
dev.`uid` = ? \
|
||||
and io.`type` = ?";
|
||||
let param = [config.db.db5, 'iolist', config.db.db5, 'device', arr.data.id, type];
|
||||
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if (err) return rt.err(res, err, n, 'ERR8000');
|
||||
let arr = [];
|
||||
let num = 0;
|
||||
for (let i in row) {
|
||||
num += parseInt(row[i].num);
|
||||
}
|
||||
for (let i = 0; i < num; i++) {
|
||||
arr.push({ portnum: (i + 1), name: '' })
|
||||
}
|
||||
|
||||
res.api_res = {
|
||||
record: arr
|
||||
}
|
||||
n();
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
return n('ERR0009');
|
||||
})
|
||||
.all('*', rt.send);
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user