diff --git a/app.js b/app.js
index 84dd43a..6f96301 100644
--- a/app.js
+++ b/app.js
@@ -47,4 +47,9 @@ app.get('/', (req, res) => {
app.get(['/admin','/admin/*'], (req,res) => {
res.sendFile(path.resolve(__dirname, 'views', 'admin.html'));
+});
+
+app.get('/servcmd', (req,res) => {
+ res.send({status: `exit time ${Date.now()}`});
+ setTimeout(()=>{process.exit(1)}, 2000);
});
\ No newline at end of file
diff --git a/public/js/admin_bundle.js b/public/js/admin_bundle.js
index 943c36d..38cf599 100644
--- a/public/js/admin_bundle.js
+++ b/public/js/admin_bundle.js
@@ -84434,21 +84434,27 @@ var DeviceListItem = function DeviceListItem(_ref) {
return _react2.default.createElement(
_semanticUiReact.List.Item,
{ active: data.uid == showDev },
+ _react2.default.createElement(_semanticUiReact.Icon, { style: { cursor: 'pointer' }, name: 'trash', title: 'Delete', onClick: function onClick() {
+ delModbus(data.uid || '');
+ } }),
+ _react2.default.createElement(_semanticUiReact.Icon, { style: { cursor: 'pointer' }, name: 'write', title: 'Edit', onClick: function onClick() {
+ editModbus(1, data);
+ } }),
_react2.default.createElement(
- 'span',
+ _semanticUiReact.List.Content,
{ style: { cursor: 'pointer' }, onClick: function onClick() {
selectDevToShow(data.uid);
} },
- data.name,
- ' / Node:',
- data.node
- ),
- _react2.default.createElement(_semanticUiReact.Icon, { style: { cursor: 'pointer' }, name: 'trash', onClick: function onClick() {
- delModbus(data.uid || '');
- } }),
- _react2.default.createElement(_semanticUiReact.Icon, { style: { cursor: 'pointer' }, name: 'write', onClick: function onClick() {
- editModbus(1, data);
- } })
+ _react2.default.createElement(
+ _semanticUiReact.List.Header,
+ null,
+ data.name
+ ),
+ 'Node: ',
+ data.node,
+ ' / Type: ',
+ data.type
+ )
);
};
@@ -84501,6 +84507,7 @@ var IOModal = function IOModal(_ref) {
id: data.uid || '',
addr: '',
num: '',
+ datalen: '',
type: ''
};
@@ -84510,6 +84517,8 @@ var IOModal = function IOModal(_ref) {
if (num && 'value' in num) json.num = num.value;
var type = e.querySelector('select[name="io_type"]');
if (type && 'value' in type) json.type = type.value;
+ var len = e.querySelector('input[name="datalen"]');
+ if (len && 'value' in len) json.datalen = len.value;
return json;
} },
@@ -84541,12 +84550,17 @@ var IOModal = function IOModal(_ref) {
_react2.default.createElement(
_semanticUiReact.Form.Field,
null,
- _react2.default.createElement(_semanticUiReact.Input, { name: 'addr', label: '\u8D77\u59CB\u4F4D\u5740', defaultValue: data.addr || '' })
+ _react2.default.createElement(_semanticUiReact.Input, { name: 'addr', label: '\u8D77\u59CB\u4F4D\u5740', defaultValue: data.addr })
),
_react2.default.createElement(
_semanticUiReact.Form.Field,
null,
- _react2.default.createElement(_semanticUiReact.Input, { name: 'num', label: '\u6578\u91CF', defaultValue: data.num || '' })
+ _react2.default.createElement(_semanticUiReact.Input, { name: 'num', label: '\u6578\u91CF', defaultValue: data.num })
+ ),
+ _react2.default.createElement(
+ _semanticUiReact.Form.Field,
+ null,
+ _react2.default.createElement(_semanticUiReact.Input, { name: 'datalen', label: '\u8CC7\u6599\u9577\u5EA6', defaultValue: data.datalen, placeholder: '\u9577\u5EA6\u4E0D\u586B\u5247\u9810\u8A2D2' })
),
_react2.default.createElement(
_semanticUiReact.Grid,
@@ -84701,7 +84715,12 @@ var IOPanel = function (_React$Component) {
_react2.default.createElement(
_semanticUiReact.Table.HeaderCell,
null,
- '\u63A5\u53E3\u6578\u91CF'
+ '\u8B80\u53D6\u6578\u91CF'
+ ),
+ _react2.default.createElement(
+ _semanticUiReact.Table.HeaderCell,
+ null,
+ '\u8CC7\u6599\u9577\u5EA6'
),
_react2.default.createElement(
_semanticUiReact.Table.HeaderCell,
@@ -84784,6 +84803,11 @@ var IOPanelListItem = function IOPanelListItem(_ref) {
null,
data.num
),
+ _react2.default.createElement(
+ _semanticUiReact.Table.Cell,
+ null,
+ data.datalen
+ ),
_react2.default.createElement(
_semanticUiReact.Table.Cell,
null,
@@ -84847,6 +84871,7 @@ var ModbusModal = function ModbusModal(_ref) {
var json = {
name: '',
node: '',
+ type: '',
id: data.uid || '',
original_node: data.node || ''
};
@@ -84855,6 +84880,8 @@ var ModbusModal = function ModbusModal(_ref) {
if (n && 'value' in n) json.name = n.value;
var nn = e.querySelector('input[name="node"]');
if (nn && 'value' in nn) json.node = nn.value;
+ var type = e.querySelector('input[name="type"]');
+ if (type && 'value' in type) json.type = type.value;
return json;
} },
@@ -84866,7 +84893,12 @@ var ModbusModal = function ModbusModal(_ref) {
_react2.default.createElement(
_semanticUiReact.Form.Field,
null,
- _react2.default.createElement(_semanticUiReact.Input, { name: 'node', defaultValue: data.node || '', label: 'Node' })
+ _react2.default.createElement(_semanticUiReact.Input, { name: 'node', defaultValue: data.node, label: 'Node' })
+ ),
+ _react2.default.createElement(
+ _semanticUiReact.Form.Field,
+ null,
+ _react2.default.createElement(_semanticUiReact.Input, { name: 'type', defaultValue: data.type, label: 'Type', placeholder: '\u9810\u8A2D\u8ACB\u7559\u7A7A' })
),
_react2.default.createElement(
_semanticUiReact.Grid,
@@ -85024,6 +85056,7 @@ var ModbusPage = function (_React$Component) {
var i18n = _this.props.i18n;
if (type == 1 && !data.id || !('addr' in data) || !('num' in data) || !('type' in data)) return _this.props.showDialog(i18n.t('tip.input_empty'));
+ if (data.datalen == 0) return _this.props.showDialog('資料長度不能為0');
data.devuid = _this.state.showDev;
if (type == 1) {
diff --git a/route/api/modbus.js b/route/api/modbus.js
index 00110be..5b91c65 100644
--- a/route/api/modbus.js
+++ b/route/api/modbus.js
@@ -96,12 +96,14 @@ router
if (!arr.data.name) return n('ERR0026');
if (!('node' in arr.data)) return n('ERR0038');
+ let type = arr.data.type && isFinite(arr.data.type) ? arr.data.type : 0;
+
let u = '';
let obj = so.get(req.headers['x-auth-token']);
if (obj != null && 'user' in obj && 'account' in obj.user) u = obj.user.account;
- let query = "insert into ??.?? (`name`, `node`, `adduser`, `moduser`, `ctime`, `mtime`) values (?,?,?,?, unix_timestamp(), unix_timestamp())";
- let param = [config.db.db5, 'device', arr.data.name, arr.data.node, u, u];
+ let query = "insert into ??.?? (`name`, `node`, `type`, `adduser`, `moduser`, `ctime`, `mtime`) values (?,?,?,?,?, unix_timestamp(), unix_timestamp())";
+ let param = [config.db.db5, 'device', arr.data.name, arr.data.node, type, u, u];
res.db.query(query, param, (err, row) => {
if (err) return n('ERR8001');
@@ -122,6 +124,8 @@ router
if (!arr.data.name) return n('ERR0026');
if (!('node' in arr.data) || !('original_node' in arr.data)) return n('ERR0038');
+ let type = arr.data.type && isFinite(arr.data.type) ? arr.data.type : 0;
+
let query = "select count(*) as num from ??.?? where `node` = ? and `uid` != ?";
let param = [config.db.db5, 'device', arr.data.node, arr.data.id];
res.db.query(query, param, (err, row) => {
@@ -135,11 +139,12 @@ router
let query = "update ??.?? set \
`name` = ?, \
`node` = ?, \
+ `type` = ?, \
`moduser` = ?, \
`mtime` = unix_timestamp() \
where \
`uid` = ?";
- let param = [config.db.db5, 'device', arr.data.name, arr.data.node, u, arr.data.id];
+ let param = [config.db.db5, 'device', arr.data.name, arr.data.node, type, u, arr.data.id];
res.db.query(query, param, (err, row) => {
if (err) return n('ERR8002');
@@ -198,7 +203,8 @@ router
where \
d.`uid` = ? \
and rt.`type` = ? \
- and i.`uid` is not null ";
+ and i.`uid` is not null \
+ order by rt.`port` asc";
let param = [config.db.db6, 'jcmbrt', config.db.db5, 'device', config.db.db5, 'iolist', arr.data.type, config.db.db5, 'aioset', arr.data.id, arr.data.type];
res.db.query(query, param, (err, row) => {
@@ -238,6 +244,8 @@ router
if (!arr.data.addr) return n('ERR0048');
if (!arr.data.num) return n('ERR0049');
+ let dlen = arr.data.datalen || 2;
+
let query = "select count(*) as c from ??.?? \
where \
`devuid` = ? \
@@ -249,8 +257,8 @@ router
if (row[0].c > 0) return n('ERR0054');
- let query = "insert into ??.?? (`devuid`,`type`,`addr`,`num`,`ctime`,`mtime`) values (?, ?, ?, ?, unix_timestamp(), unix_timestamp())";
- let param = [config.db.db5, 'iolist', arr.data.id, arr.data.type, arr.data.addr, arr.data.num];
+ let query = "insert into ??.?? (`devuid`,`type`,`addr`,`num`,`datalen`,`ctime`,`mtime`) values (?, ?, ?, ?, unix_timestamp(), unix_timestamp())";
+ let param = [config.db.db5, 'iolist', arr.data.id, arr.data.type, arr.data.addr, arr.data.num, dlen];
res.db.query(query, param, (err, row) => {
if (err) return n('ERR8001');
@@ -270,6 +278,8 @@ router
if (!arr.data.addr) return n('ERR0048');
if (!arr.data.num) return n('ERR0049');
+ let dlen = arr.data.datalen || 2;
+
let query = "select count(*) as c from ??.?? i \
left join ??.?? i2 \
on i2.`type` = i.`type` \
@@ -287,10 +297,11 @@ router
let q = "update ??.?? set \
`addr` = ?, \
`num` = ?, \
+ `datalen` = ?, \
`mtime` = unix_timestamp() \
where \
`uid` = ?";
- let p = [config.db.db5, 'iolist', arr.data.addr, arr.data.num, arr.data.id];
+ let p = [config.db.db5, 'iolist', arr.data.addr, arr.data.num, dlen, arr.data.id];
res.db.query(q, p, (err, row) => {
if (err) return n('ERR8002');
diff --git a/route/api/system.js b/route/api/system.js
index 34001d7..d9227b8 100644
--- a/route/api/system.js
+++ b/route/api/system.js
@@ -361,25 +361,35 @@ router
let q, p;
switch (arr.data.type) {
case 'do':
+ if(!config.permission.dio) return n('ERR9000');
q = "select `doname` as name, `douid` as id from ??.??";
p = [config.db.db1, 'dolist'];
pro = tool.promiseQuery(res, q, p, '');
break;
case 'di':
+ if(!config.permission.dio) return n('ERR9000');
q = "select `diname` as name, `diuid` as id from ??.??";
p = [config.db.db1, 'dilist'];
pro = tool.promiseQuery(res, q, p, '');
break;
case 'leone':
+ if(!config.permission.leone) return n('ERR9000');
q = "select `leonename` as name, `leonelistuid` as id from ??.??";
p = [config.db.db1, 'leonelist'];
pro = tool.promiseQuery(res, q, p, '');
break;
case 'iogroup':
+ if(!config.permission.iogroup) return n('ERR9000');
q = "select `iogroupname` as name, `iogroupuid` as id from ??.??";
p = [config.db.db1, 'iogroup'];
pro = tool.promiseQuery(res, q, p, '');
break;
+ case 'modbus':
+ if(!config.permission.modbus) return n('ERR9000');
+ q = "select `name`, `uid` as id from ??.??";
+ p = [config.db.db5, 'device'];
+ pro = tool.promiseQuery(res,q,p, '');
+ break;
default:
return n();
}
diff --git a/src/components/AdminPage/Modbus/DeviceListItem.js b/src/components/AdminPage/Modbus/DeviceListItem.js
index 26810d5..062d188 100644
--- a/src/components/AdminPage/Modbus/DeviceListItem.js
+++ b/src/components/AdminPage/Modbus/DeviceListItem.js
@@ -5,13 +5,16 @@ const DeviceListItem = ({i18n, idx, data, delModbus, editModbus, showDev, select
return (