fast(串口调试): 添加串口通用调试(地址读写指令)、打包1.0.7
This commit is contained in:
parent
1c024beeb8
commit
9364ef8412
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "gateway-app",
|
"name": "gateway-app",
|
||||||
"version": "1.0.6",
|
"version": "1.0.7",
|
||||||
"description": "An Electron application with Vue",
|
"description": "An Electron application with Vue",
|
||||||
"main": "./out/main/index.js",
|
"main": "./out/main/index.js",
|
||||||
"author": "example.com",
|
"author": "example.com",
|
||||||
|
|
|
@ -60,13 +60,13 @@
|
||||||
</el-collapse>
|
</el-collapse>
|
||||||
</div>
|
</div>
|
||||||
<div class="calibrate-footer">
|
<div class="calibrate-footer">
|
||||||
<el-button :type="item.type" :loading="item.loading" :icon="item.icon" @click="sendBtnParameter(item)" v-for="(item,index) in btnParameterList" :key="index">{{item.name}}</el-button>
|
<el-button v-for="(item, index) in btnParameterList" :key="index" :type="item.type" :loading="item.loading" :icon="item.icon" @click="sendBtnParameter(item)">{{ item.name }}</el-button>
|
||||||
<!-- <el-button type="primary" @click="sendData">启动标定</el-button>-->
|
<!-- <el-button type="primary" @click="sendData">启动标定</el-button>-->
|
||||||
<!-- <el-button type="primary" @click="sendData">步骤1</el-button>-->
|
<!-- <el-button type="primary" @click="sendData">步骤1</el-button>-->
|
||||||
<!-- <el-button type="primary" @click="sendData">步骤2</el-button>-->
|
<!-- <el-button type="primary" @click="sendData">步骤2</el-button>-->
|
||||||
<!-- <el-button type="primary" @click="sendData">步骤3</el-button>-->
|
<!-- <el-button type="primary" @click="sendData">步骤3</el-button>-->
|
||||||
<!-- <el-button type="primary" @click="sendData">步骤4</el-button>-->
|
<!-- <el-button type="primary" @click="sendData">步骤4</el-button>-->
|
||||||
<!-- <el-button type="primary" @click="sendData">步骤5</el-button>-->
|
<!-- <el-button type="primary" @click="sendData">步骤5</el-button>-->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -776,68 +776,68 @@ const calibrateWriteLoading = ref(false);
|
||||||
|
|
||||||
const getElectricalParametersCalibrateList = () => {
|
const getElectricalParametersCalibrateList = () => {
|
||||||
if (!serialportForm.value.port) {
|
if (!serialportForm.value.port) {
|
||||||
ElMessage.error('请先打开串口');
|
ElMessage.error('请先打开串口');
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
calibrateReadLoading.value = true;
|
calibrateReadLoading.value = true;
|
||||||
|
|
||||||
let head = buildHead(
|
let head = buildHead(
|
||||||
deviceAttrCommonList.value['output'].datalentype,
|
deviceAttrCommonList.value['output'].datalentype,
|
||||||
deviceAttrCommonList.value['output'].remote_id,
|
deviceAttrCommonList.value['output'].remote_id,
|
||||||
deviceAttrCommonList.value['output'].local_id,
|
deviceAttrCommonList.value['output'].local_id,
|
||||||
deviceAttrCommonList.value['output'].cmd,
|
deviceAttrCommonList.value['output'].cmd,
|
||||||
deviceAttrCommonList.value['output'].devtype,
|
deviceAttrCommonList.value['output'].devtype,
|
||||||
deviceAttrCommonList.value['output'].datatype,
|
deviceAttrCommonList.value['output'].datatype,
|
||||||
30018,
|
30018,
|
||||||
4,
|
4,
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.post(
|
.post(
|
||||||
config.serialPortUrl + '/serial/response',
|
config.serialPortUrl + '/serial/response',
|
||||||
{
|
{
|
||||||
port: serialportForm.value.port,
|
port: serialportForm.value.port,
|
||||||
data: head,
|
data: head,
|
||||||
hex: 1,
|
hex: 1,
|
||||||
crc: 1,
|
crc: 1,
|
||||||
flush:1
|
flush: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
calibrateReadLoading.value = false;
|
calibrateReadLoading.value = false;
|
||||||
// 成功响应后的处理
|
// 成功响应后的处理
|
||||||
if (response.data.code === 0) {
|
if (response.data.code === 0) {
|
||||||
ElMessage.success('电参数校准获取成功');
|
ElMessage.success('电参数校准获取成功');
|
||||||
let hexValue = response.data.data.hex.substring(24, 72);
|
let hexValue = response.data.data.hex.substring(24, 72);
|
||||||
electricalParametersCalibrateList.value.forEach((item, index) => {
|
electricalParametersCalibrateList.value.forEach((item, index) => {
|
||||||
let value = hexValue.substring(item.startValue, item.endValue);
|
let value = hexValue.substring(item.startValue, item.endValue);
|
||||||
if (item.dataType === 'uint16_t') {
|
if (item.dataType === 'uint16_t') {
|
||||||
electricalParametersCalibrateList.value[index].value = hexToDec(rearrangeHexStr4(value));
|
electricalParametersCalibrateList.value[index].value = hexToDec(rearrangeHexStr4(value));
|
||||||
}else{
|
} else {
|
||||||
let formatValue = hexToDec(value)
|
let formatValue = hexToDec(value);
|
||||||
electricalParametersCalibrateList.value[index].value = formatValue;
|
electricalParametersCalibrateList.value[index].value = formatValue;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
} else {
|
} else {
|
||||||
ElMessage.error(response.data.message);
|
ElMessage.error(response.data.message);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
calibrateReadLoading.value = false;
|
calibrateReadLoading.value = false;
|
||||||
console.log('error', error);
|
console.log('error', error);
|
||||||
// 错误处理
|
// 错误处理
|
||||||
if (error.response.data.message) {
|
if (error.response.data.message) {
|
||||||
ElMessage.error(error.response.data.message);
|
ElMessage.error(error.response.data.message);
|
||||||
} else {
|
} else {
|
||||||
ElMessage.error(error);
|
ElMessage.error(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// let hexValue = '082030064275000005000000800cdc000a00bd07d007640000000000cdcc8c400d5e00103005427500000500000000000000000000000000000000000000000000008f5d'.substring(24, 72);
|
// let hexValue = '082030064275000005000000800cdc000a00bd07d007640000000000cdcc8c400d5e00103005427500000500000000000000000000000000000000000000000000008f5d'.substring(24, 72);
|
||||||
// electricalParametersCalibrateList.value.forEach((item, index) => {
|
// electricalParametersCalibrateList.value.forEach((item, index) => {
|
||||||
|
@ -854,8 +854,8 @@ const getElectricalParametersCalibrateList = () => {
|
||||||
|
|
||||||
const sendElectricalParametersCalibrateList = () => {
|
const sendElectricalParametersCalibrateList = () => {
|
||||||
if (!serialportForm.value.port) {
|
if (!serialportForm.value.port) {
|
||||||
ElMessage.error('请先打开串口');
|
ElMessage.error('请先打开串口');
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
calibrateWriteLoading.value = true;
|
calibrateWriteLoading.value = true;
|
||||||
let data = '00000000000000000000000000000000';
|
let data = '00000000000000000000000000000000';
|
||||||
|
@ -906,7 +906,6 @@ const sendElectricalParametersCalibrateList = () => {
|
||||||
// 成功响应后的处理
|
// 成功响应后的处理
|
||||||
if (response.data.code === 0) {
|
if (response.data.code === 0) {
|
||||||
ElMessage.success('电参数校准写入成功');
|
ElMessage.success('电参数校准写入成功');
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ElMessage.error(response.data.message);
|
ElMessage.error(response.data.message);
|
||||||
}
|
}
|
||||||
|
@ -924,118 +923,117 @@ const sendElectricalParametersCalibrateList = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const btnParameterList = ref([
|
const btnParameterList = ref([
|
||||||
{
|
{
|
||||||
name: '启动标定',
|
name: '启动标定',
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
loading:false,
|
loading: false,
|
||||||
icon: 'SwitchButton',
|
icon: 'SwitchButton',
|
||||||
startValue: 61000,
|
startValue: 61000,
|
||||||
lengthValue: 1,
|
lengthValue: 1,
|
||||||
value: '04000000'
|
value: '04000000'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '步骤1',
|
name: '步骤1',
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
loading:false,
|
loading: false,
|
||||||
icon: '',
|
icon: '',
|
||||||
startValue: 61000,
|
startValue: 61000,
|
||||||
lengthValue: 1,
|
lengthValue: 1,
|
||||||
value: '04000100'
|
value: '04000100'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '步骤2',
|
name: '步骤2',
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
loading:false,
|
loading: false,
|
||||||
icon: '',
|
icon: '',
|
||||||
startValue: 61000,
|
startValue: 61000,
|
||||||
lengthValue: 1,
|
lengthValue: 1,
|
||||||
value: '04000200'
|
value: '04000200'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '步骤3',
|
name: '步骤3',
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
loading:false,
|
loading: false,
|
||||||
icon: '',
|
icon: '',
|
||||||
startValue: 61000,
|
startValue: 61000,
|
||||||
lengthValue: 1,
|
lengthValue: 1,
|
||||||
value: '04000300'
|
value: '04000300'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '步骤4',
|
name: '步骤4',
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
loading:false,
|
loading: false,
|
||||||
icon: '',
|
icon: '',
|
||||||
startValue: 61000,
|
startValue: 61000,
|
||||||
lengthValue: 1,
|
lengthValue: 1,
|
||||||
value: '04000400'
|
value: '04000400'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '步骤5',
|
name: '步骤5',
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
loading:false,
|
loading: false,
|
||||||
icon: '',
|
icon: '',
|
||||||
startValue: 61000,
|
startValue: 61000,
|
||||||
lengthValue: 1,
|
lengthValue: 1,
|
||||||
value: '04000500'
|
value: '04000500'
|
||||||
},
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const sendBtnParameter = item => {
|
||||||
|
console.log('当前点击按钮', item);
|
||||||
|
if (!serialportForm.value.port) {
|
||||||
|
ElMessage.error('请先打开串口');
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
item.loading = true;
|
||||||
|
let head = buildHead(
|
||||||
|
deviceAttrCommonList.value['input'].datalentype,
|
||||||
|
deviceAttrCommonList.value['input'].remote_id,
|
||||||
|
deviceAttrCommonList.value['input'].local_id,
|
||||||
|
deviceAttrCommonList.value['input'].cmd,
|
||||||
|
deviceAttrCommonList.value['input'].devtype,
|
||||||
|
deviceAttrCommonList.value['input'].datatype,
|
||||||
|
item.startValue,
|
||||||
|
item.lengthValue,
|
||||||
|
item.value,
|
||||||
|
{ dataType: 'hexString' }
|
||||||
|
);
|
||||||
|
|
||||||
const sendBtnParameter = (item) => {
|
axios
|
||||||
console.log('当前点击按钮',item)
|
.post(
|
||||||
if (!serialportForm.value.port) {
|
config.serialPortUrl + '/serial/response',
|
||||||
ElMessage.error('请先打开串口');
|
{
|
||||||
return '';
|
port: serialportForm.value.port,
|
||||||
}
|
data: head,
|
||||||
item.loading = true;
|
hex: 1,
|
||||||
let head = buildHead(
|
crc: 1,
|
||||||
deviceAttrCommonList.value['input'].datalentype,
|
flush: 1
|
||||||
deviceAttrCommonList.value['input'].remote_id,
|
},
|
||||||
deviceAttrCommonList.value['input'].local_id,
|
{
|
||||||
deviceAttrCommonList.value['input'].cmd,
|
headers: {
|
||||||
deviceAttrCommonList.value['input'].devtype,
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
deviceAttrCommonList.value['input'].datatype,
|
}
|
||||||
item.startValue,
|
}
|
||||||
item.lengthValue,
|
)
|
||||||
item.value,
|
.then(response => {
|
||||||
{ dataType: 'hexString' }
|
item.loading = false;
|
||||||
);
|
// 成功响应后的处理
|
||||||
|
if (response.data.code === 0) {
|
||||||
axios
|
ElMessage.success(`执行${item.name}成功`);
|
||||||
.post(
|
} else {
|
||||||
config.serialPortUrl + '/serial/response',
|
ElMessage.error(response.data.message);
|
||||||
{
|
}
|
||||||
port: serialportForm.value.port,
|
})
|
||||||
data: head,
|
.catch(error => {
|
||||||
hex: 1,
|
item.loading = false;
|
||||||
crc: 1,
|
console.log('error', error);
|
||||||
flush: 1
|
// 错误处理
|
||||||
},
|
if (error.response.data.message) {
|
||||||
{
|
ElMessage.error(error.response.data.message);
|
||||||
headers: {
|
} else {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
ElMessage.error(error);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
)
|
|
||||||
.then(response => {
|
|
||||||
item.loading = false;
|
|
||||||
// 成功响应后的处理
|
|
||||||
if (response.data.code === 0) {
|
|
||||||
ElMessage.success(`执行${item.name}成功`);
|
|
||||||
} else {
|
|
||||||
ElMessage.error(response.data.message);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
item.loading = false;
|
|
||||||
console.log('error', error);
|
|
||||||
// 错误处理
|
|
||||||
if (error.response.data.message) {
|
|
||||||
ElMessage.error(error.response.data.message);
|
|
||||||
} else {
|
|
||||||
ElMessage.error(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 生命周期钩子
|
// 生命周期钩子
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
<div id="serialport-main" class="serialport-main">
|
<div id="serialport-main" class="serialport-main">
|
||||||
<el-collapse v-model="activeFold" @change="foldChange">
|
<el-collapse v-model="activeFold" @change="foldChange">
|
||||||
<el-collapse-item name="1" title="串口设置">
|
<el-collapse-item name="1" title="串口设置">
|
||||||
<el-form ref="serialportFormRef" :model="serialportForm" :rules="serialportRules" class="demo-serialportForm" label-width="auto" status-icon>
|
<el-form ref="serialportFormRef" :model="serialportForm" :rules="serialportRules" class="demo-serialportForm" label-width="auto" status-icon>
|
||||||
<el-form-item label="端口" prop="port" required >
|
<el-form-item label="端口" prop="port" required>
|
||||||
<el-select v-model="serialportForm.port" :disabled="connectionState" placeholder="选择端口" style="flex: 1">
|
<el-select v-model="serialportForm.port" :disabled="connectionState" placeholder="选择端口" style="flex: 1">
|
||||||
<el-option v-for="(item, index) in serialportList" :key="index" :label="item" :value="item" />
|
<el-option v-for="(item, index) in serialportList" :key="index" :label="item" :value="item" />
|
||||||
</el-select>
|
</el-select>
|
||||||
<el-button style="margin-left: 10px" type="primary" @click="getSerialPortList">获取端口列表</el-button>
|
<el-button style="margin-left: 10px" type="primary" @click="getSerialPortList">获取端口列表</el-button>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="波特率" prop="baudrate" required>
|
<el-form-item label="波特率" prop="baudrate" required>
|
||||||
<el-select v-model="serialportForm.baudrate" :disabled="connectionState" placeholder="选择波特率">
|
<el-select v-model="serialportForm.baudrate" :disabled="connectionState" placeholder="选择波特率">
|
||||||
|
@ -50,57 +50,78 @@
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
</el-collapse-item>
|
</el-collapse-item>
|
||||||
<!-- <el-collapse-item name="2" title="通用调试">-->
|
<el-collapse-item name="2" title="通用调试">
|
||||||
<!-- <el-form ref="commonDebuggerFormRef" :model="commonDebuggerForm" :rules="commonDebuggerRules" class="demo-serialportForm" label-width="auto" status-icon>-->
|
<el-form ref="commonDebuggerFormRef" :model="commonDebuggerForm" :rules="commonDebuggerRules" class="demo-serialportForm" label-width="auto" status-icon>
|
||||||
<!-- <el-form-item label="数据类型" prop="dataType">-->
|
<el-row>
|
||||||
<!-- <el-input-->
|
<el-col :span="12">
|
||||||
<!-- </el-form-item>-->
|
<el-form-item label="本地ID" prop="localId">
|
||||||
<!-- <el-form-item label="端口" prop="port" required >-->
|
<el-input v-model="commonDebuggerForm.localId" placeholder="请输入本地ID" />
|
||||||
<!-- <el-select v-model="commonDebuggerForm.port" :disabled="connectionState" placeholder="选择端口" style="flex: 1">-->
|
</el-form-item>
|
||||||
<!-- <el-option v-for="(item, index) in serialportList" :key="index" :label="item" :value="item" />-->
|
</el-col>
|
||||||
<!-- </el-select>-->
|
<el-col :span="12">
|
||||||
<!-- <el-button style="margin-left: 10px" type="primary" @click="getSerialPortList">获取端口列表</el-button>-->
|
<el-form-item label="目标ID" prop="remoteId">
|
||||||
<!-- </el-form-item>-->
|
<el-input v-model="commonDebuggerForm.remoteId" placeholder="请输入目标ID" />
|
||||||
<!-- <el-form-item label="波特率" prop="baudrate" required>-->
|
</el-form-item>
|
||||||
<!-- <el-select v-model="commonDebuggerForm.baudrate" :disabled="connectionState" placeholder="选择波特率">-->
|
</el-col>
|
||||||
<!-- <el-option label="4800" :value="4800" />-->
|
</el-row>
|
||||||
<!-- <el-option label="9600" :value="9600" />-->
|
<el-row>
|
||||||
<!-- <el-option label="19200" :value="19200" />-->
|
<el-col :span="12">
|
||||||
<!-- <el-option label="43000" :value="43000" />-->
|
<el-form-item label="设备类型" prop="devType" required>
|
||||||
<!-- <el-option label="56000" :value="56000" />-->
|
<el-select v-model="commonDebuggerForm.devType" placeholder="选择设备类型" style="flex: 1">
|
||||||
<!-- <el-option label="115200" :value="115200" />-->
|
<el-option v-for="(item, index) in devTypeList" :key="index" :label="item.label" :value="item.value" />
|
||||||
<!-- </el-select>-->
|
</el-select>
|
||||||
<!-- </el-form-item>-->
|
</el-form-item>
|
||||||
<!-- <el-form-item label="数据位" prop="databits" required>-->
|
</el-col>
|
||||||
<!-- <el-select v-model="commonDebuggerForm.databits" :disabled="connectionState" placeholder="选择数据位">-->
|
<el-col :span="12">
|
||||||
<!-- <el-option label="5" :value="5" />-->
|
<el-form-item label="数据类型" prop="dataType" required>
|
||||||
<!-- <el-option label="6" :value="6" />-->
|
<el-select v-model="commonDebuggerForm.dataType" placeholder="选择数据类型" style="flex: 1">
|
||||||
<!-- <el-option label="7" :value="7" />-->
|
<el-option v-for="(item, index) in dataTypeList" :key="index" :label="item.label" :value="item.value" />
|
||||||
<!-- <el-option label="8" :value="8" />-->
|
</el-select>
|
||||||
<!-- </el-select>-->
|
</el-form-item>
|
||||||
<!-- </el-form-item>-->
|
</el-col>
|
||||||
<!-- <el-form-item label="校验位" prop="parity" required>-->
|
</el-row>
|
||||||
<!-- <el-select v-model="commonDebuggerForm.parity" :disabled="connectionState" placeholder="选择校验位">-->
|
<el-row>
|
||||||
<!-- <el-option label="None" :value="0" />-->
|
<el-col :span="12">
|
||||||
<!-- <el-option label="Odd" :value="1" />-->
|
<el-form-item label="指令码" prop="cmd" required>
|
||||||
<!-- <el-option label="Even" :value="2" />-->
|
<el-select v-model="commonDebuggerForm.cmd" placeholder="选择指令码" style="flex: 1">
|
||||||
<!-- <el-option label="Mark" :value="3" />-->
|
<el-option v-for="(item, index) in cmdList" :key="index" :label="item.label" :value="item.value" />
|
||||||
<!-- <el-option label="Space" :value="4" />-->
|
</el-select>
|
||||||
<!-- </el-select>-->
|
</el-form-item>
|
||||||
<!-- </el-form-item>-->
|
</el-col>
|
||||||
<!-- <el-form-item label="停止位" prop="stopbits" required>-->
|
<el-col :span="12">
|
||||||
<!-- <el-select v-model="commonDebuggerForm.stopbits" :disabled="connectionState" placeholder="选择停止位">-->
|
<el-form-item label="数据长度类型" prop="dataLenType" required>
|
||||||
<!-- <el-option label="1" :value="0" />-->
|
<el-select v-model="commonDebuggerForm.dataLenType" placeholder="选择数据长度类型" style="flex: 1">
|
||||||
<!-- <el-option label="1.5" :value="1" />-->
|
<el-option v-for="(item, index) in dataLenTypeList" :key="index" :label="item.label" :value="item.value" />
|
||||||
<!-- <el-option label="2" :value="2" />-->
|
</el-select>
|
||||||
<!-- </el-select>-->
|
</el-form-item>
|
||||||
<!-- </el-form-item>-->
|
</el-col>
|
||||||
<!-- <el-form-item class="btn-box">-->
|
</el-row>
|
||||||
<!-- <el-button type="danger" @click="disconnSerialPort">关闭 </el-button>-->
|
<el-row v-if="commonDebuggerForm.cmd === '0100' || commonDebuggerForm.cmd === '0011'">
|
||||||
<!-- <el-button type="primary" @click="connectSerialPort(serialportFormRef)">{{ connectionState ? '已打开' : '打开' }}</el-button>-->
|
<el-col :span="12">
|
||||||
<!-- </el-form-item>-->
|
<el-form-item label="起始地址" prop="writeStart" required>
|
||||||
<!-- </el-form>-->
|
<el-input v-model="commonDebuggerForm.writeStart" type="number" placeholder="请输入起始地址" />
|
||||||
<!-- </el-collapse-item>-->
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="12">
|
||||||
|
<el-form-item label="长度" prop="writeLength" required>
|
||||||
|
<el-input v-model="commonDebuggerForm.writeLength" type="number" placeholder="请输入长度" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
<el-form-item v-if="commonDebuggerForm.cmd === '0100'" label="数据" prop="writeData">
|
||||||
|
<el-input v-model="commonDebuggerForm.writeData" type="textarea" :rows="2" placeholder="请输入数据" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="发送包" prop="dataStr">
|
||||||
|
<el-input v-model="commonDebuggerForm.dataStr" disabled />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="返回包" prop="hexStr">
|
||||||
|
<el-input v-model="commonDebuggerForm.hexStr" disabled />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item class="btn-box">
|
||||||
|
<el-button type="primary" :loading="sendCommonDebuggerState" @click="sendCommonDebugger(commonDebuggerFormRef)">发送</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</el-collapse-item>
|
||||||
<el-collapse-item name="3" title="设备基础参数">
|
<el-collapse-item name="3" title="设备基础参数">
|
||||||
<div class="device-attr-list">
|
<div class="device-attr-list">
|
||||||
<div v-for="(item, index) in deviceAttrList" :key="item.id" class="device-attr-item">
|
<div v-for="(item, index) in deviceAttrList" :key="item.id" class="device-attr-item">
|
||||||
|
@ -114,10 +135,10 @@
|
||||||
<el-button type="primary" :disabled="item.inputDisable" :loading="item.inputLoadingStatus" @click="sendDeviceAttr(item, 'input', index)">写入</el-button>
|
<el-button type="primary" :disabled="item.inputDisable" :loading="item.inputLoadingStatus" @click="sendDeviceAttr(item, 'input', index)">写入</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="btn-box">
|
<div class="btn-box">
|
||||||
<el-button type="primary" @click="allReadDeviceAttr">一键读取</el-button>
|
<el-button type="primary" @click="allReadDeviceAttr">一键读取</el-button>
|
||||||
<el-button type="primary" @click="allWriteDeviceAttr">一键写入</el-button>
|
<el-button type="primary" @click="allWriteDeviceAttr">一键写入</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</el-collapse-item>
|
</el-collapse-item>
|
||||||
</el-collapse>
|
</el-collapse>
|
||||||
|
@ -129,12 +150,11 @@
|
||||||
import axios from 'axios'; // 引入axios
|
import axios from 'axios'; // 引入axios
|
||||||
import config from '@renderer/util/config.js';
|
import config from '@renderer/util/config.js';
|
||||||
|
|
||||||
import { reactive, ref, onMounted, onUnmounted,watch } from 'vue';
|
import { reactive, ref, onMounted, onUnmounted, watch } from 'vue';
|
||||||
import { ElMessage } from 'element-plus';
|
import { ElMessage } from 'element-plus';
|
||||||
import { buildHead, hexToString, hexToVersion, rearrangeHexStr, versionToHex } from "./js/fun"
|
import { buildHead, hexToString, hexToVersion, rearrangeHexStr, versionToHex } from './js/fun';
|
||||||
import { useSerialPortStore } from '@renderer/stores/seralPort.js';
|
import { useSerialPortStore } from '@renderer/stores/seralPort.js';
|
||||||
|
|
||||||
|
|
||||||
const useseralPortStore = useSerialPortStore();
|
const useseralPortStore = useSerialPortStore();
|
||||||
const activeFold = ref(['1', '2', '3']);
|
const activeFold = ref(['1', '2', '3']);
|
||||||
|
|
||||||
|
@ -154,14 +174,16 @@ const serialportForm = reactive({
|
||||||
});
|
});
|
||||||
|
|
||||||
// 监听 serialportForm 的变化
|
// 监听 serialportForm 的变化
|
||||||
watch(() => ({ ...serialportForm }), (newVal) => {
|
watch(
|
||||||
// 将新的值存储到 localStorage 中
|
() => ({ ...serialportForm }),
|
||||||
newVal.port = newVal.port.toLowerCase();
|
newVal => {
|
||||||
useseralPortStore.setSerialport(newVal);
|
// 将新的值存储到 localStorage 中
|
||||||
// localStorage.setItem('serialportForm', newVal);
|
newVal.port = newVal.port.toLowerCase();
|
||||||
}, { deep: true });
|
useseralPortStore.setSerialport(newVal);
|
||||||
|
// localStorage.setItem('serialportForm', newVal);
|
||||||
|
},
|
||||||
|
{ deep: true }
|
||||||
|
);
|
||||||
|
|
||||||
const serialportRules = reactive({
|
const serialportRules = reactive({
|
||||||
port: [{ required: true, message: '请选择端口', trigger: 'change' }],
|
port: [{ required: true, message: '请选择端口', trigger: 'change' }],
|
||||||
|
@ -179,9 +201,9 @@ const getSerialPortList = (msgShow = true) => {
|
||||||
// 成功响应后的处理
|
// 成功响应后的处理
|
||||||
if (response.data.code === 0) {
|
if (response.data.code === 0) {
|
||||||
serialportList.value = response.data.data.List || [];
|
serialportList.value = response.data.data.List || [];
|
||||||
if(msgShow){
|
if (msgShow) {
|
||||||
ElMessage.success('获取端口列表成功');
|
ElMessage.success('获取端口列表成功');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ElMessage.error(response.data.message);
|
ElMessage.error(response.data.message);
|
||||||
}
|
}
|
||||||
|
@ -197,7 +219,7 @@ const connectSerialPort = formEl => {
|
||||||
if (!formEl) return;
|
if (!formEl) return;
|
||||||
formEl.validate(valid => {
|
formEl.validate(valid => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
serialportForm.port = serialportForm.port.toLowerCase();
|
serialportForm.port = serialportForm.port.toLowerCase();
|
||||||
axios
|
axios
|
||||||
.post(config.serialPortUrl + '/serial/open', serialportForm)
|
.post(config.serialPortUrl + '/serial/open', serialportForm)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
@ -227,7 +249,7 @@ const connectSerialPort = formEl => {
|
||||||
|
|
||||||
//关闭串口
|
//关闭串口
|
||||||
const disconnSerialPort = () => {
|
const disconnSerialPort = () => {
|
||||||
serialportForm.port = serialportForm.port.toLowerCase();
|
serialportForm.port = serialportForm.port.toLowerCase();
|
||||||
axios
|
axios
|
||||||
.get(config.serialPortUrl + '/serial/close', {
|
.get(config.serialPortUrl + '/serial/close', {
|
||||||
params: {
|
params: {
|
||||||
|
@ -290,7 +312,7 @@ const deviceAttrList = ref([
|
||||||
outputValue: '',
|
outputValue: '',
|
||||||
outputLoadingStatus: false,
|
outputLoadingStatus: false,
|
||||||
dataType: 'hex',
|
dataType: 'hex',
|
||||||
inputDisable: false
|
inputDisable: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 2,
|
id: 2,
|
||||||
|
@ -302,7 +324,7 @@ const deviceAttrList = ref([
|
||||||
outputValue: '',
|
outputValue: '',
|
||||||
outputLoadingStatus: false,
|
outputLoadingStatus: false,
|
||||||
dataType: 'str',
|
dataType: 'str',
|
||||||
inputDisable: false
|
inputDisable: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 3,
|
id: 3,
|
||||||
|
@ -314,7 +336,7 @@ const deviceAttrList = ref([
|
||||||
outputValue: '',
|
outputValue: '',
|
||||||
outputLoadingStatus: false,
|
outputLoadingStatus: false,
|
||||||
dataType: 'str',
|
dataType: 'str',
|
||||||
inputDisable: false
|
inputDisable: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 4,
|
id: 4,
|
||||||
|
@ -326,7 +348,7 @@ const deviceAttrList = ref([
|
||||||
outputValue: '',
|
outputValue: '',
|
||||||
outputLoadingStatus: false,
|
outputLoadingStatus: false,
|
||||||
dataType: 'str',
|
dataType: 'str',
|
||||||
inputDisable: false
|
inputDisable: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 5,
|
id: 5,
|
||||||
|
@ -338,7 +360,7 @@ const deviceAttrList = ref([
|
||||||
outputValue: '',
|
outputValue: '',
|
||||||
outputLoadingStatus: false,
|
outputLoadingStatus: false,
|
||||||
dataType: 'str',
|
dataType: 'str',
|
||||||
inputDisable: false
|
inputDisable: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 6,
|
id: 6,
|
||||||
|
@ -350,7 +372,7 @@ const deviceAttrList = ref([
|
||||||
outputValue: '',
|
outputValue: '',
|
||||||
outputLoadingStatus: false,
|
outputLoadingStatus: false,
|
||||||
dataType: 'str',
|
dataType: 'str',
|
||||||
inputDisable: false
|
inputDisable: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 7,
|
id: 7,
|
||||||
|
@ -362,7 +384,7 @@ const deviceAttrList = ref([
|
||||||
outputValue: '',
|
outputValue: '',
|
||||||
outputLoadingStatus: false,
|
outputLoadingStatus: false,
|
||||||
dataType: 'str',
|
dataType: 'str',
|
||||||
inputDisable: false
|
inputDisable: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 8,
|
id: 8,
|
||||||
|
@ -374,7 +396,7 @@ const deviceAttrList = ref([
|
||||||
outputValue: '',
|
outputValue: '',
|
||||||
outputLoadingStatus: false,
|
outputLoadingStatus: false,
|
||||||
dataType: 'firmware',
|
dataType: 'firmware',
|
||||||
inputDisable: true
|
inputDisable: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 9,
|
id: 9,
|
||||||
|
@ -386,7 +408,7 @@ const deviceAttrList = ref([
|
||||||
outputValue: '',
|
outputValue: '',
|
||||||
outputLoadingStatus: false,
|
outputLoadingStatus: false,
|
||||||
dataType: 'firmware',
|
dataType: 'firmware',
|
||||||
inputDisable: true
|
inputDisable: true
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -404,16 +426,15 @@ const analysisData = (hexData, data) => {
|
||||||
if (data.dataType === 'str') {
|
if (data.dataType === 'str') {
|
||||||
let str = hexToString(hexValue).trim();
|
let str = hexToString(hexValue).trim();
|
||||||
return str;
|
return str;
|
||||||
|
} else if (data.dataType === 'hex') {
|
||||||
|
let str = rearrangeHexStr(hexValue);
|
||||||
|
return str;
|
||||||
}
|
}
|
||||||
else if(data.dataType === 'hex'){
|
// else if(data.dataType === 'firmware'){
|
||||||
let str = rearrangeHexStr(hexValue);
|
// let str = hexToVersion(hexValue);
|
||||||
return str;
|
// return str;
|
||||||
}
|
// }
|
||||||
// else if(data.dataType === 'firmware'){
|
else {
|
||||||
// let str = hexToVersion(hexValue);
|
|
||||||
// return str;
|
|
||||||
// }
|
|
||||||
else {
|
|
||||||
return hexValue;
|
return hexValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -435,13 +456,13 @@ const sendDeviceAttr = (data, type, index) => {
|
||||||
deviceAttrCommonList.value[type].datatype,
|
deviceAttrCommonList.value[type].datatype,
|
||||||
data.startValue,
|
data.startValue,
|
||||||
data.lengthValue,
|
data.lengthValue,
|
||||||
data.inputValue,
|
data.inputValue,
|
||||||
data
|
data
|
||||||
);
|
);
|
||||||
|
|
||||||
if (type === 'input') {
|
if (type === 'input') {
|
||||||
deviceAttrList.value[index].inputLoadingStatus = true;
|
deviceAttrList.value[index].inputLoadingStatus = true;
|
||||||
// head = head + 'd240';
|
// head = head + 'd240';
|
||||||
} else {
|
} else {
|
||||||
deviceAttrList.value[index].outputLoadingStatus = true;
|
deviceAttrList.value[index].outputLoadingStatus = true;
|
||||||
}
|
}
|
||||||
|
@ -453,7 +474,7 @@ const sendDeviceAttr = (data, type, index) => {
|
||||||
data: head,
|
data: head,
|
||||||
hex: 1,
|
hex: 1,
|
||||||
crc: 1,
|
crc: 1,
|
||||||
flush:1
|
flush: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -495,177 +516,346 @@ const sendDeviceAttr = (data, type, index) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const allReadDeviceAttr = () => {
|
const allReadDeviceAttr = () => {
|
||||||
if (!serialportForm.port) {
|
if (!serialportForm.port) {
|
||||||
ElMessage.error('请先打开串口');
|
ElMessage.error('请先打开串口');
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
let head = buildHead(
|
let head = buildHead(
|
||||||
deviceAttrCommonList.value['output'].datalentype,
|
deviceAttrCommonList.value['output'].datalentype,
|
||||||
deviceAttrCommonList.value['output'].remote_id,
|
deviceAttrCommonList.value['output'].remote_id,
|
||||||
deviceAttrCommonList.value['output'].local_id,
|
deviceAttrCommonList.value['output'].local_id,
|
||||||
deviceAttrCommonList.value['output'].cmd,
|
deviceAttrCommonList.value['output'].cmd,
|
||||||
deviceAttrCommonList.value['output'].devtype,
|
deviceAttrCommonList.value['output'].devtype,
|
||||||
deviceAttrCommonList.value['output'].datatype,
|
deviceAttrCommonList.value['output'].datatype,
|
||||||
0,
|
0,
|
||||||
46,
|
46,
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.post(
|
.post(
|
||||||
config.serialPortUrl + '/serial/response',
|
config.serialPortUrl + '/serial/response',
|
||||||
{
|
{
|
||||||
port: serialportForm.port,
|
port: serialportForm.port,
|
||||||
data: head,
|
data: head,
|
||||||
hex: 1,
|
hex: 1,
|
||||||
crc: 1,
|
crc: 1,
|
||||||
flush:1
|
flush: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
// 成功响应后的处理
|
// 成功响应后的处理
|
||||||
console.log('串口请求', response); // 打印响应数据
|
console.log('串口请求', response); // 打印响应数据
|
||||||
if (response.data.code === 0) {
|
if (response.data.code === 0) {
|
||||||
ElMessage.success('操作成功');
|
ElMessage.success('操作成功');
|
||||||
let hexValue = response.data.data.hex.substring(24, 392);
|
let hexValue = response.data.data.hex.substring(24, 392);
|
||||||
let startValue = 0;
|
let startValue = 0;
|
||||||
deviceAttrList.value.forEach((item, index) => {
|
deviceAttrList.value.forEach((item, index) => {
|
||||||
if(startValue === 0){
|
if (startValue === 0) {
|
||||||
startValue = item.startValue;
|
startValue = item.startValue;
|
||||||
}
|
}
|
||||||
let value = hexValue.substring(startValue, item.lengthValue * 4 * 2 + startValue);
|
let value = hexValue.substring(startValue, item.lengthValue * 4 * 2 + startValue);
|
||||||
startValue = startValue + item.lengthValue * 4 * 2;
|
startValue = startValue + item.lengthValue * 4 * 2;
|
||||||
console.log("value",value)
|
console.log('value', value);
|
||||||
if (item.dataType === 'str') {
|
if (item.dataType === 'str') {
|
||||||
deviceAttrList.value[index].outputValue = hexToString(value).trim();
|
deviceAttrList.value[index].outputValue = hexToString(value).trim();
|
||||||
deviceAttrList.value[index].inputValue = hexToString(value).trim();
|
deviceAttrList.value[index].inputValue = hexToString(value).trim();
|
||||||
}else if (item.dataType === 'hex') {
|
} else if (item.dataType === 'hex') {
|
||||||
deviceAttrList.value[index].outputValue = rearrangeHexStr(value);
|
deviceAttrList.value[index].outputValue = rearrangeHexStr(value);
|
||||||
deviceAttrList.value[index].inputValue = rearrangeHexStr(value);
|
deviceAttrList.value[index].inputValue = rearrangeHexStr(value);
|
||||||
}else{
|
} else {
|
||||||
deviceAttrList.value[index].outputValue = value;
|
deviceAttrList.value[index].outputValue = value;
|
||||||
deviceAttrList.value[index].inputValue = value;
|
deviceAttrList.value[index].inputValue = value;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
// deviceAttrList.value[index].outputValue = analysisData(response.data.data.hex || '', data);
|
// deviceAttrList.value[index].outputValue = analysisData(response.data.data.hex || '', data);
|
||||||
} else {
|
} else {
|
||||||
ElMessage.error(response.data.message);
|
ElMessage.error(response.data.message);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log('error', error);
|
console.log('error', error);
|
||||||
// 错误处理
|
// 错误处理
|
||||||
if (error.response.data.message) {
|
if (error.response.data.message) {
|
||||||
ElMessage.error(error.response.data.message);
|
ElMessage.error(error.response.data.message);
|
||||||
} else {
|
} else {
|
||||||
ElMessage.error(error);
|
ElMessage.error(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
const allWriteDeviceAttr = () => {
|
const allWriteDeviceAttr = () => {
|
||||||
if (!serialportForm.port) {
|
if (!serialportForm.port) {
|
||||||
ElMessage.error('请先打开串口');
|
ElMessage.error('请先打开串口');
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
deviceAttrList.value.forEach((item, index)=>{
|
deviceAttrList.value.forEach((item, index) => {
|
||||||
setTimeout(()=>{
|
setTimeout(() => {
|
||||||
sendDeviceAttr(item, 'input', index)
|
sendDeviceAttr(item, 'input', index);
|
||||||
},50)
|
}, 50);
|
||||||
})
|
});
|
||||||
|
|
||||||
// let head = buildHead(
|
// let head = buildHead(
|
||||||
// deviceAttrCommonList.value['input'].datalentype,
|
// deviceAttrCommonList.value['input'].datalentype,
|
||||||
// deviceAttrCommonList.value['input'].remote_id,
|
// deviceAttrCommonList.value['input'].remote_id,
|
||||||
// deviceAttrCommonList.value['input'].local_id,
|
// deviceAttrCommonList.value['input'].local_id,
|
||||||
// deviceAttrCommonList.value['input'].cmd,
|
// deviceAttrCommonList.value['input'].cmd,
|
||||||
// deviceAttrCommonList.value['input'].devtype,
|
// deviceAttrCommonList.value['input'].devtype,
|
||||||
// deviceAttrCommonList.value['input'].datatype,
|
// deviceAttrCommonList.value['input'].datatype,
|
||||||
// 0,
|
// 0,
|
||||||
// 46,
|
// 46,
|
||||||
// ''
|
// ''
|
||||||
// );
|
// );
|
||||||
//
|
//
|
||||||
// axios
|
// axios
|
||||||
// .post(
|
// .post(
|
||||||
// config.serialPortUrl + '/serial/response',
|
// config.serialPortUrl + '/serial/response',
|
||||||
// {
|
// {
|
||||||
// port: serialportForm.port,
|
// port: serialportForm.port,
|
||||||
// data: head,
|
// data: head,
|
||||||
// hex: 1,
|
// hex: 1,
|
||||||
// crc: 1
|
// crc: 1
|
||||||
// },
|
// },
|
||||||
// {
|
// {
|
||||||
// headers: {
|
// headers: {
|
||||||
// 'Content-Type': 'application/x-www-form-urlencoded'
|
// 'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// )
|
// )
|
||||||
// .then(response => {
|
// .then(response => {
|
||||||
// // 成功响应后的处理
|
// // 成功响应后的处理
|
||||||
// console.log('串口请求', response); // 打印响应数据
|
// console.log('串口请求', response); // 打印响应数据
|
||||||
// if (response.data.code === 0) {
|
// if (response.data.code === 0) {
|
||||||
// ElMessage.success('操作成功');
|
// ElMessage.success('操作成功');
|
||||||
// let hexValue = response.data.data.hex.substring(24, 392);
|
// let hexValue = response.data.data.hex.substring(24, 392);
|
||||||
// let startValue = 0;
|
// let startValue = 0;
|
||||||
// deviceAttrList.value.forEach((item, index) => {
|
// deviceAttrList.value.forEach((item, index) => {
|
||||||
// if(startValue === 0){
|
// if(startValue === 0){
|
||||||
// startValue = item.startValue;
|
// startValue = item.startValue;
|
||||||
// }
|
// }
|
||||||
// let value = hexValue.substring(startValue, item.lengthValue * 4 * 2 + startValue);
|
// let value = hexValue.substring(startValue, item.lengthValue * 4 * 2 + startValue);
|
||||||
// startValue = startValue + item.lengthValue * 4 * 2;
|
// startValue = startValue + item.lengthValue * 4 * 2;
|
||||||
// console.log("value",value)
|
// console.log("value",value)
|
||||||
// if (item.dataType === 'str') {
|
// if (item.dataType === 'str') {
|
||||||
// deviceAttrList.value[index].outputValue = hexToString(value).trim();
|
// deviceAttrList.value[index].outputValue = hexToString(value).trim();
|
||||||
// deviceAttrList.value[index].inputValue = hexToString(value).trim();
|
// deviceAttrList.value[index].inputValue = hexToString(value).trim();
|
||||||
// }else{
|
// }else{
|
||||||
// deviceAttrList.value[index].outputValue = value;
|
// deviceAttrList.value[index].outputValue = value;
|
||||||
// deviceAttrList.value[index].inputValue = value;
|
// deviceAttrList.value[index].inputValue = value;
|
||||||
// }
|
// }
|
||||||
// })
|
// })
|
||||||
// // deviceAttrList.value[index].outputValue = analysisData(response.data.data.hex || '', data);
|
// // deviceAttrList.value[index].outputValue = analysisData(response.data.data.hex || '', data);
|
||||||
// } else {
|
// } else {
|
||||||
// ElMessage.error(response.data.message);
|
// ElMessage.error(response.data.message);
|
||||||
// }
|
// }
|
||||||
// })
|
// })
|
||||||
// .catch(error => {
|
// .catch(error => {
|
||||||
// console.log('error', error);
|
// console.log('error', error);
|
||||||
// // 错误处理
|
// // 错误处理
|
||||||
// if (error.response.data.message) {
|
// if (error.response.data.message) {
|
||||||
// ElMessage.error(error.response.data.message);
|
// ElMessage.error(error.response.data.message);
|
||||||
// } else {
|
// } else {
|
||||||
// ElMessage.error(error);
|
// ElMessage.error(error);
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const commonDebuggerFormRef = ref();
|
||||||
|
|
||||||
// const commonDebuggerFormRef = ref();
|
const sendCommonDebuggerState = ref(false);
|
||||||
//
|
|
||||||
// const commonDebuggerList = ref([]);
|
const commonDebuggerForm = ref({
|
||||||
//
|
localId: '',
|
||||||
// const commonDebuggerForm = reactive({
|
remoteId: '',
|
||||||
// localId:'',
|
devType: '00',
|
||||||
// port: '',
|
dataType: '00',
|
||||||
// baudrate: 115200,
|
cmd: '0011',
|
||||||
// databits: 8,
|
dataLenType: '00',
|
||||||
// parity: 0,
|
writeStart: 0,
|
||||||
// stopbits: 0
|
writeLength: 0,
|
||||||
// });
|
writeData: '',
|
||||||
//
|
dataStr: '',
|
||||||
// const commonDebuggerRules = reactive({
|
hexStr: ''
|
||||||
// port: [{ required: true, message: '请选择端口', trigger: 'change' }],
|
});
|
||||||
// baudrate: [{ required: true, message: '请选择波特率', trigger: 'change' }],
|
|
||||||
// databits: [{ required: true, message: '请选择port', trigger: 'change' }],
|
const devTypeList = ref([
|
||||||
// parity: [{ required: true, message: '请选择userName', trigger: 'change' }],
|
{
|
||||||
// stopbits: [{ required: true, message: '请选择passWord', trigger: 'change' }]
|
label: '配套通信工具',
|
||||||
// });
|
value: '00'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '网关',
|
||||||
|
value: '01'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '设备',
|
||||||
|
value: '10'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '其他',
|
||||||
|
value: '11'
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
const dataTypeList = ref([
|
||||||
|
{
|
||||||
|
label: '紧急',
|
||||||
|
value: '00'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '应答',
|
||||||
|
value: '01'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '发送',
|
||||||
|
value: '10'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '广播',
|
||||||
|
value: '11'
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
const cmdList = ref([
|
||||||
|
{
|
||||||
|
label: '特殊指令',
|
||||||
|
value: '0000'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '事件指令',
|
||||||
|
value: '0001'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '连接指令',
|
||||||
|
value: '0010'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '地址读指令',
|
||||||
|
value: '0011'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '地址写指令',
|
||||||
|
value: '0100'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '文件读指令',
|
||||||
|
value: '0101'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '文件写指令',
|
||||||
|
value: '0110'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '文件控制指令',
|
||||||
|
value: '0111'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'OTA升级指令',
|
||||||
|
value: '1000'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '控制台通道',
|
||||||
|
value: '1001'
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
const dataLenTypeList = ref([
|
||||||
|
{
|
||||||
|
label: '单帧数据',
|
||||||
|
value: '00'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '多帧数据起始帧',
|
||||||
|
value: '01'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '多帧数据中间帧',
|
||||||
|
value: '10'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '多帧数据结束帧',
|
||||||
|
value: '11'
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
const commonDebuggerRules = reactive({
|
||||||
|
devType: [{ required: true, message: '请选择设备类型', trigger: 'change' }],
|
||||||
|
dataType: [{ required: true, message: '请选择数据类型', trigger: 'change' }],
|
||||||
|
cmd: [{ required: true, message: '请选择指令码', trigger: 'change' }],
|
||||||
|
dataLenType: [{ required: true, message: '请选择数据长度类型', trigger: 'change' }],
|
||||||
|
writeStart: [{ required: true, message: '请输入起始地址', trigger: 'blur' }],
|
||||||
|
writeLength: [{ required: true, message: '请输入长度', trigger: 'blur' }]
|
||||||
|
});
|
||||||
|
|
||||||
|
//打开
|
||||||
|
const sendCommonDebugger = formEl => {
|
||||||
|
if (!formEl) return;
|
||||||
|
formEl.validate(valid => {
|
||||||
|
if (valid) {
|
||||||
|
if (!serialportForm.port) {
|
||||||
|
ElMessage.error('请先打开串口');
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
let head = buildHead(
|
||||||
|
commonDebuggerForm.value.dataLenType,
|
||||||
|
commonDebuggerForm.value.remoteId,
|
||||||
|
commonDebuggerForm.value.localId,
|
||||||
|
commonDebuggerForm.value.cmd,
|
||||||
|
commonDebuggerForm.value.devType,
|
||||||
|
commonDebuggerForm.value.dataType,
|
||||||
|
commonDebuggerForm.value.writeStart,
|
||||||
|
commonDebuggerForm.value.writeLength,
|
||||||
|
commonDebuggerForm.value.writeData,
|
||||||
|
commonDebuggerForm.value
|
||||||
|
);
|
||||||
|
sendCommonDebuggerState.value = true;
|
||||||
|
axios
|
||||||
|
.post(
|
||||||
|
config.serialPortUrl + '/serial/response',
|
||||||
|
{
|
||||||
|
port: serialportForm.port,
|
||||||
|
data: head,
|
||||||
|
hex: 1,
|
||||||
|
crc: 1,
|
||||||
|
flush: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.then(response => {
|
||||||
|
// 成功响应后的处理
|
||||||
|
console.log('串口请求', response); // 打印响应数据
|
||||||
|
sendCommonDebuggerState.value = false;
|
||||||
|
if (response.data.code === 0) {
|
||||||
|
ElMessage.success('请求成功');
|
||||||
|
commonDebuggerForm.value.dataStr = head;
|
||||||
|
commonDebuggerForm.value.hexStr = response.data.data.hex;
|
||||||
|
} else {
|
||||||
|
ElMessage.error(response.data.message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
sendCommonDebuggerState.value = false;
|
||||||
|
console.log('error', error);
|
||||||
|
// 错误处理
|
||||||
|
if (error.response.data.message) {
|
||||||
|
ElMessage.error(error.response.data.message);
|
||||||
|
} else {
|
||||||
|
ElMessage.error(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// 生命周期钩子
|
// 生命周期钩子
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
@ -708,11 +898,11 @@ onUnmounted(() => {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.btn-box{
|
.btn-box {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
:deep(.el-form) {
|
:deep(.el-form) {
|
||||||
|
|
Loading…
Reference in New Issue