add modbus cmd
This commit is contained in:
parent
762175f1f9
commit
c990935194
@ -54,6 +54,9 @@
|
||||
"ERR0052": "ScaleMin輸入錯誤",
|
||||
"ERR0053": "ScaleMax輸入錯誤",
|
||||
"ERR0054": "此位址設定已存在",
|
||||
"ERR0055": "Func Code 輸入錯誤",
|
||||
"ERR0056": "LeOne數量已達上限",
|
||||
"ERR0057": "連動資料輸入錯誤",
|
||||
|
||||
"ERR7000": "命令執行失敗",
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -270,6 +270,7 @@
|
||||
"iocmd": "IO CMD",
|
||||
"schedule": "排程控制",
|
||||
"modbus": "Modbus",
|
||||
"modbuscmd": "Modbus CMD",
|
||||
"link": "連動",
|
||||
"logout": "登出"
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ router
|
||||
let param = [config.db.db1, 'leonelist'];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if (err || row.length == 0) return n('ERR8000');
|
||||
if (row[0].num >= config.leone_limit) return n('ERR0048');
|
||||
if (row[0].num >= config.leone_limit) return n('ERR0056');
|
||||
|
||||
let query = "select count(*) from ??.?? where `leoneip` = ? ";
|
||||
let p = [...param, arr.data.ip];
|
||||
@ -246,7 +246,7 @@ router
|
||||
let param = [config.db.db1, 'leonelist', ids];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if (err || row.length == 0) return n('ERR8000');
|
||||
if (row[0].num >= config.leone_limit) return n('ERR0048');
|
||||
if (row[0].num >= config.leone_limit) return n('ERR0056');
|
||||
|
||||
let query = "update ??.?? set `temporary` = '0', `leone_modify_date` = unix_timestamp() where `leonelistuid` in (?)";
|
||||
res.db.query(query, param, (err, row) => {
|
||||
|
@ -119,7 +119,7 @@ router
|
||||
if (!tool.checkPermission(req)) return n('ERR9000');
|
||||
let arr = req.body;
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.link || Object.keys(arr.data.link).length == 0) return n('ERR0049');
|
||||
if (!arr.data.link || Object.keys(arr.data.link).length == 0) return n('ERR0057');
|
||||
if (!('active' in arr.data)) return n('ERR0032');
|
||||
if (!arr.data.action) return n('ERR0030');
|
||||
|
||||
|
@ -2,12 +2,10 @@ const express = require('express');
|
||||
const router = express.Router();
|
||||
const rt = require('../ResTool');
|
||||
const config = require('../../config.json');
|
||||
const fs = require('fs');
|
||||
const mysql = require('../../libs/mysql_cls');
|
||||
const tool = require('../../includes/apiTool');
|
||||
const exec = require('child_process').exec;
|
||||
const so = require('../../includes/storeObject');
|
||||
const crypt = require('../../libs/crypto');
|
||||
|
||||
router
|
||||
.get('/', (req, res) => {
|
||||
@ -583,6 +581,28 @@ router
|
||||
});
|
||||
});
|
||||
})
|
||||
.post('/modbuscmd', (req,res,n) => {
|
||||
if (!config.permission.modbus) return n('ERR9000');
|
||||
if (!tool.checkPermission(req)) return n('ERR9000');
|
||||
let arr = req.body;
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if(!arr.data.ip) return n('ERR0010');
|
||||
if(!('node' in arr.data) || arr.data.node.length == 0) return n('ERR0038');
|
||||
if(!('func' in arr.data) || arr.data.func.length == 0) return n('ERR0055');
|
||||
if(!('addr' in arr.data) || arr.data.addr.length == 0) return n('ERR0048');
|
||||
if(!('value' in arr.data) || arr.data.value.length == 0) return n('ERR0049');
|
||||
|
||||
let cmd = `mbtcpm ${arr.data.ip} ${arr.data.node} ${arr.data.func} ${arr.data.addr} ${arr.data.value}`;
|
||||
res.api_res = {
|
||||
record: []
|
||||
};
|
||||
exec(cmd, (err, stdout, stderr) => {
|
||||
let msg = err ? err.toString() : stdout;
|
||||
res.api_res.record.push({msg});
|
||||
|
||||
n();
|
||||
})
|
||||
})
|
||||
.all('*', rt.send);
|
||||
|
||||
module.exports = router;
|
@ -42,6 +42,7 @@ class PageRoot extends React.Component {
|
||||
return response.json();
|
||||
return {}
|
||||
}).then(json => {
|
||||
let lang = Object.keys(json)[0] || '';
|
||||
i18next.init({
|
||||
lng: lang,
|
||||
resources: json
|
||||
|
86
src/components/AdminPage/ModbusCmd/index.js
Normal file
86
src/components/AdminPage/ModbusCmd/index.js
Normal file
@ -0,0 +1,86 @@
|
||||
import React from 'react';
|
||||
import {Container, Segment, Input, Form, Button} from 'semantic-ui-react';
|
||||
import {getRequest} from '../../../actions';
|
||||
|
||||
class ModbusCmdPage extends React.Component {
|
||||
|
||||
state = {
|
||||
res: ''
|
||||
}
|
||||
|
||||
handleSubmit = (data) => {
|
||||
let {i18n} = this.props;
|
||||
if(data.ip == '' || data.node == '' || data.func == '' || data.addr == '' || data.value == '') return this.props.showDialog(i18n&&i18n.t?i18n.t('tip.input_empty'):'');
|
||||
this.props.toggleLoading(1);
|
||||
this.setState({res:''})
|
||||
fetch('/api/modbus/modbuscmd', getRequest(data))
|
||||
.then(response=>response.json())
|
||||
.then(json=>{
|
||||
this.props.toggleLoading(0);
|
||||
if(json.status != 1) return this.props.showDialog(json.message);
|
||||
this.setState({
|
||||
res: json.data.record[0].msg || ''
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Container>
|
||||
<Segment>
|
||||
<Form onSubmit={(e,d)=>{
|
||||
e.preventDefault();
|
||||
this.handleSubmit(d.formData);
|
||||
}} serializer={e=>{
|
||||
let json = {
|
||||
ip: '',
|
||||
node: '',
|
||||
func: '',
|
||||
addr: '',
|
||||
value: ''
|
||||
};
|
||||
|
||||
let ip = e.querySelector('input[name="ip"]');
|
||||
if(ip && 'value' in ip) json.ip = ip.value;
|
||||
let node = e.querySelector('input[name="node"]');
|
||||
if(node && 'value' in node) json.node = node.value;
|
||||
let func = e.querySelector('input[name="func"]');
|
||||
if(func && 'value' in func) json.func = func.value;
|
||||
let addr = e.querySelector('input[name="addr"]');
|
||||
if(addr && 'value' in addr) json.addr = addr.value;
|
||||
let val = e.querySelector('input[name="val"]');
|
||||
if(val && 'value' in val) json.value = val.value;
|
||||
|
||||
return json;
|
||||
}}>
|
||||
<Form.Field>
|
||||
<Input name="ip" label="請輸入IP" defaultValue="127.0.0.1" />
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Input name="node" label="請輸入節點" />
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Input name="func" label="請輸入FunctionCode" />
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Input name="addr" label="請輸入位址" />
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Input name="val" label="請輸入數值" />
|
||||
</Form.Field>
|
||||
<Button type="submit" content="送出" fluid />
|
||||
</Form>
|
||||
</Segment>
|
||||
<Segment>
|
||||
{
|
||||
this.state.res.split(/\n/).map((t,idx) => (
|
||||
<div key={idx}>{t}</div>
|
||||
))
|
||||
}
|
||||
</Segment>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default ModbusCmdPage;
|
@ -67,6 +67,7 @@ class Root extends React.Component {
|
||||
return response.json();
|
||||
return {}
|
||||
}).then(json => {
|
||||
let lang = Object.keys(json)[0] || '';
|
||||
i18next.init({
|
||||
lng: lang,
|
||||
resources: json
|
||||
|
@ -16,6 +16,7 @@ const MainMenu = ({i18n, show, toggleMenu, children, permissions, showDashboard,
|
||||
<MItem toLink="/admin/iocmd" txt={i18n && 't' in i18n ? i18n.t('menu.item.iocmd') : ''} permission={permissions.iocmd} onClick={()=>toggleMenu()} />
|
||||
<MItem toLink="/admin/schedule" txt={i18n && 't' in i18n ? i18n.t('menu.item.schedule') : ''} permission={permissions.schedule} onClick={()=>toggleMenu()} />
|
||||
<MItem toLink="/admin/modbus" txt={i18n && 't' in i18n ? i18n.t('menu.item.modbus') : ''} permission={permissions.modbus} onClick={()=>toggleMenu()} />
|
||||
<MItem toLink="/admin/modbuscmd" txt={i18n && 't' in i18n ? i18n.t('menu.item.modbuscmd') : ''} permission={permissions.modbus} onClick={()=>toggleMenu()} />
|
||||
<MItem toLink="/admin/link" txt={i18n && 't' in i18n ? i18n.t('menu.item.link') : ''} permission={permissions.link} onClick={()=>toggleMenu()} />
|
||||
<MItem toLink="/admin" txt={i18n && 't' in i18n ? i18n.t('menu.item.logout') : ''} permission={true} onClick={()=>{
|
||||
sessionStorage.clear();
|
||||
|
18
src/containers/AdminPage/ModbusCmd.js
Normal file
18
src/containers/AdminPage/ModbusCmd.js
Normal file
@ -0,0 +1,18 @@
|
||||
import {connect} from 'react-redux';
|
||||
import {add_dialog_msg, toggle_loading} from '../../actions';
|
||||
import ModbusCmdPage from '../../components/AdminPage/ModbusCmd';
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
i18n: state.i18n
|
||||
});
|
||||
|
||||
const mapDispatchToProps = (dispatch, ownProps) => ({
|
||||
showDialog: (msg) => {
|
||||
dispatch(add_dialog_msg(msg));
|
||||
},
|
||||
toggleLoading: (flag = false) => {
|
||||
dispatch(toggle_loading(flag));
|
||||
}
|
||||
})
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(ModbusCmdPage);
|
@ -10,6 +10,7 @@ import IOGroup from './containers/AdminPage/IOGroup';
|
||||
import IOCmd from './containers/AdminPage/IOCmd';
|
||||
import Schedule from './containers/AdminPage/Schedule';
|
||||
import Modbus from './containers/AdminPage/Modbus';
|
||||
import ModbusCmd from './containers/AdminPage/ModbusCmd';
|
||||
import ActionLink from './containers/AdminPage/ActionLink';
|
||||
import ActionLinkAdd from './containers/AdminPage/ActionLinkAdd';
|
||||
|
||||
@ -26,6 +27,7 @@ const Routes = (
|
||||
<Route path="modbus" component={Modbus} />
|
||||
<Route path="link" component={ActionLink} />
|
||||
<Route path="addlink" component={ActionLinkAdd} />
|
||||
<Route path="modbuscmd" component={ModbusCmd} />
|
||||
</Route>
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user