From 9364ef8412639a491963718650f2e776402654b5 Mon Sep 17 00:00:00 2001 From: fhysy <1149505133@qq.com> Date: Thu, 7 Nov 2024 11:01:20 +0800 Subject: [PATCH] =?UTF-8?q?fast(=E4=B8=B2=E5=8F=A3=E8=B0=83=E8=AF=95):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=B2=E5=8F=A3=E9=80=9A=E7=94=A8=E8=B0=83?= =?UTF-8?q?=E8=AF=95=EF=BC=88=E5=9C=B0=E5=9D=80=E8=AF=BB=E5=86=99=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=EF=BC=89=E3=80=81=E6=89=93=E5=8C=851.0.7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- .../system/serialport/devicestandard.vue | 350 +++++---- .../src/views/system/serialport/index.vue | 726 +++++++++++------- 3 files changed, 633 insertions(+), 445 deletions(-) diff --git a/package.json b/package.json index 815aaf3..9197af7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gateway-app", - "version": "1.0.6", + "version": "1.0.7", "description": "An Electron application with Vue", "main": "./out/main/index.js", "author": "example.com", diff --git a/src/renderer/src/views/system/serialport/devicestandard.vue b/src/renderer/src/views/system/serialport/devicestandard.vue index aadffe6..8156948 100644 --- a/src/renderer/src/views/system/serialport/devicestandard.vue +++ b/src/renderer/src/views/system/serialport/devicestandard.vue @@ -60,13 +60,13 @@ @@ -776,68 +776,68 @@ const calibrateWriteLoading = ref(false); const getElectricalParametersCalibrateList = () => { if (!serialportForm.value.port) { - ElMessage.error('请先打开串口'); - return ''; + ElMessage.error('请先打开串口'); + return ''; } - calibrateReadLoading.value = true; + calibrateReadLoading.value = true; - let head = buildHead( - deviceAttrCommonList.value['output'].datalentype, - deviceAttrCommonList.value['output'].remote_id, - deviceAttrCommonList.value['output'].local_id, - deviceAttrCommonList.value['output'].cmd, - deviceAttrCommonList.value['output'].devtype, - deviceAttrCommonList.value['output'].datatype, - 30018, - 4, - '' + let head = buildHead( + deviceAttrCommonList.value['output'].datalentype, + deviceAttrCommonList.value['output'].remote_id, + deviceAttrCommonList.value['output'].local_id, + deviceAttrCommonList.value['output'].cmd, + deviceAttrCommonList.value['output'].devtype, + deviceAttrCommonList.value['output'].datatype, + 30018, + 4, + '' ); axios - .post( - config.serialPortUrl + '/serial/response', - { - port: serialportForm.value.port, - data: head, - hex: 1, - crc: 1, - flush:1 - }, - { - headers: { - 'Content-Type': 'application/x-www-form-urlencoded' - } - } - ) - .then(response => { - calibrateReadLoading.value = false; - // 成功响应后的处理 - if (response.data.code === 0) { - ElMessage.success('电参数校准获取成功'); - let hexValue = response.data.data.hex.substring(24, 72); - electricalParametersCalibrateList.value.forEach((item, index) => { - let value = hexValue.substring(item.startValue, item.endValue); - if (item.dataType === 'uint16_t') { - electricalParametersCalibrateList.value[index].value = hexToDec(rearrangeHexStr4(value)); - }else{ - let formatValue = hexToDec(value) - electricalParametersCalibrateList.value[index].value = formatValue; - } - }) - } else { - ElMessage.error(response.data.message); - } - }) - .catch(error => { - calibrateReadLoading.value = false; - console.log('error', error); - // 错误处理 - if (error.response.data.message) { - ElMessage.error(error.response.data.message); - } else { - ElMessage.error(error); - } - }); + .post( + config.serialPortUrl + '/serial/response', + { + port: serialportForm.value.port, + data: head, + hex: 1, + crc: 1, + flush: 1 + }, + { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + } + } + ) + .then(response => { + calibrateReadLoading.value = false; + // 成功响应后的处理 + if (response.data.code === 0) { + ElMessage.success('电参数校准获取成功'); + let hexValue = response.data.data.hex.substring(24, 72); + electricalParametersCalibrateList.value.forEach((item, index) => { + let value = hexValue.substring(item.startValue, item.endValue); + if (item.dataType === 'uint16_t') { + electricalParametersCalibrateList.value[index].value = hexToDec(rearrangeHexStr4(value)); + } else { + let formatValue = hexToDec(value); + electricalParametersCalibrateList.value[index].value = formatValue; + } + }); + } else { + ElMessage.error(response.data.message); + } + }) + .catch(error => { + calibrateReadLoading.value = false; + console.log('error', error); + // 错误处理 + if (error.response.data.message) { + ElMessage.error(error.response.data.message); + } else { + ElMessage.error(error); + } + }); // let hexValue = '082030064275000005000000800cdc000a00bd07d007640000000000cdcc8c400d5e00103005427500000500000000000000000000000000000000000000000000008f5d'.substring(24, 72); // electricalParametersCalibrateList.value.forEach((item, index) => { @@ -854,8 +854,8 @@ const getElectricalParametersCalibrateList = () => { const sendElectricalParametersCalibrateList = () => { if (!serialportForm.value.port) { - ElMessage.error('请先打开串口'); - return ''; + ElMessage.error('请先打开串口'); + return ''; } calibrateWriteLoading.value = true; let data = '00000000000000000000000000000000'; @@ -906,7 +906,6 @@ const sendElectricalParametersCalibrateList = () => { // 成功响应后的处理 if (response.data.code === 0) { ElMessage.success('电参数校准写入成功'); - } else { ElMessage.error(response.data.message); } @@ -924,118 +923,117 @@ const sendElectricalParametersCalibrateList = () => { }; const btnParameterList = ref([ - { - name: '启动标定', - type: 'primary', - loading:false, - icon: 'SwitchButton', - startValue: 61000, - lengthValue: 1, - value: '04000000' - }, - { - name: '步骤1', - type: 'primary', - loading:false, - icon: '', - startValue: 61000, - lengthValue: 1, - value: '04000100' - }, - { - name: '步骤2', - type: 'primary', - loading:false, - icon: '', - startValue: 61000, - lengthValue: 1, - value: '04000200' - }, - { - name: '步骤3', - type: 'primary', - loading:false, - icon: '', - startValue: 61000, - lengthValue: 1, - value: '04000300' - }, - { - name: '步骤4', - type: 'primary', - loading:false, - icon: '', - startValue: 61000, - lengthValue: 1, - value: '04000400' - }, - { - name: '步骤5', - type: 'primary', - loading:false, - icon: '', - startValue: 61000, - lengthValue: 1, - value: '04000500' - }, + { + name: '启动标定', + type: 'primary', + loading: false, + icon: 'SwitchButton', + startValue: 61000, + lengthValue: 1, + value: '04000000' + }, + { + name: '步骤1', + type: 'primary', + loading: false, + icon: '', + startValue: 61000, + lengthValue: 1, + value: '04000100' + }, + { + name: '步骤2', + type: 'primary', + loading: false, + icon: '', + startValue: 61000, + lengthValue: 1, + value: '04000200' + }, + { + name: '步骤3', + type: 'primary', + loading: false, + icon: '', + startValue: 61000, + lengthValue: 1, + value: '04000300' + }, + { + name: '步骤4', + type: 'primary', + loading: false, + icon: '', + startValue: 61000, + lengthValue: 1, + value: '04000400' + }, + { + name: '步骤5', + type: 'primary', + loading: false, + icon: '', + startValue: 61000, + lengthValue: 1, + 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) => { - 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' } - ); - - axios - .post( - config.serialPortUrl + '/serial/response', - { - port: serialportForm.value.port, - data: head, - hex: 1, - crc: 1, - flush: 1 - }, - { - headers: { - 'Content-Type': 'application/x-www-form-urlencoded' - } - } - ) - .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); - } - }); + axios + .post( + config.serialPortUrl + '/serial/response', + { + port: serialportForm.value.port, + data: head, + hex: 1, + crc: 1, + flush: 1 + }, + { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + } + } + ) + .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); + } + }); }; // 生命周期钩子 diff --git a/src/renderer/src/views/system/serialport/index.vue b/src/renderer/src/views/system/serialport/index.vue index d3be698..82658ac 100644 --- a/src/renderer/src/views/system/serialport/index.vue +++ b/src/renderer/src/views/system/serialport/index.vue @@ -3,12 +3,12 @@
- - - - - - 获取端口列表 + + + + + + 获取端口列表 @@ -50,57 +50,78 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 发送 + + +
@@ -114,10 +135,10 @@ 写入
-
- 一键读取 - 一键写入 -
+
+ 一键读取 + 一键写入 +
@@ -129,12 +150,11 @@ import axios from 'axios'; // 引入axios 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 { buildHead, hexToString, hexToVersion, rearrangeHexStr, versionToHex } from "./js/fun" +import { buildHead, hexToString, hexToVersion, rearrangeHexStr, versionToHex } from './js/fun'; import { useSerialPortStore } from '@renderer/stores/seralPort.js'; - const useseralPortStore = useSerialPortStore(); const activeFold = ref(['1', '2', '3']); @@ -154,14 +174,16 @@ const serialportForm = reactive({ }); // 监听 serialportForm 的变化 -watch(() => ({ ...serialportForm }), (newVal) => { - // 将新的值存储到 localStorage 中 - newVal.port = newVal.port.toLowerCase(); - useseralPortStore.setSerialport(newVal); - // localStorage.setItem('serialportForm', newVal); -}, { deep: true }); - - +watch( + () => ({ ...serialportForm }), + newVal => { + // 将新的值存储到 localStorage 中 + newVal.port = newVal.port.toLowerCase(); + useseralPortStore.setSerialport(newVal); + // localStorage.setItem('serialportForm', newVal); + }, + { deep: true } +); const serialportRules = reactive({ port: [{ required: true, message: '请选择端口', trigger: 'change' }], @@ -179,9 +201,9 @@ const getSerialPortList = (msgShow = true) => { // 成功响应后的处理 if (response.data.code === 0) { serialportList.value = response.data.data.List || []; - if(msgShow){ - ElMessage.success('获取端口列表成功'); - } + if (msgShow) { + ElMessage.success('获取端口列表成功'); + } } else { ElMessage.error(response.data.message); } @@ -197,7 +219,7 @@ const connectSerialPort = formEl => { if (!formEl) return; formEl.validate(valid => { if (valid) { - serialportForm.port = serialportForm.port.toLowerCase(); + serialportForm.port = serialportForm.port.toLowerCase(); axios .post(config.serialPortUrl + '/serial/open', serialportForm) .then(response => { @@ -227,7 +249,7 @@ const connectSerialPort = formEl => { //关闭串口 const disconnSerialPort = () => { - serialportForm.port = serialportForm.port.toLowerCase(); + serialportForm.port = serialportForm.port.toLowerCase(); axios .get(config.serialPortUrl + '/serial/close', { params: { @@ -290,7 +312,7 @@ const deviceAttrList = ref([ outputValue: '', outputLoadingStatus: false, dataType: 'hex', - inputDisable: false + inputDisable: false }, { id: 2, @@ -302,7 +324,7 @@ const deviceAttrList = ref([ outputValue: '', outputLoadingStatus: false, dataType: 'str', - inputDisable: false + inputDisable: false }, { id: 3, @@ -314,7 +336,7 @@ const deviceAttrList = ref([ outputValue: '', outputLoadingStatus: false, dataType: 'str', - inputDisable: false + inputDisable: false }, { id: 4, @@ -326,7 +348,7 @@ const deviceAttrList = ref([ outputValue: '', outputLoadingStatus: false, dataType: 'str', - inputDisable: false + inputDisable: false }, { id: 5, @@ -338,7 +360,7 @@ const deviceAttrList = ref([ outputValue: '', outputLoadingStatus: false, dataType: 'str', - inputDisable: false + inputDisable: false }, { id: 6, @@ -350,7 +372,7 @@ const deviceAttrList = ref([ outputValue: '', outputLoadingStatus: false, dataType: 'str', - inputDisable: false + inputDisable: false }, { id: 7, @@ -362,7 +384,7 @@ const deviceAttrList = ref([ outputValue: '', outputLoadingStatus: false, dataType: 'str', - inputDisable: false + inputDisable: false }, { id: 8, @@ -374,7 +396,7 @@ const deviceAttrList = ref([ outputValue: '', outputLoadingStatus: false, dataType: 'firmware', - inputDisable: true + inputDisable: true }, { id: 9, @@ -386,7 +408,7 @@ const deviceAttrList = ref([ outputValue: '', outputLoadingStatus: false, dataType: 'firmware', - inputDisable: true + inputDisable: true } ]); @@ -404,16 +426,15 @@ const analysisData = (hexData, data) => { if (data.dataType === 'str') { let str = hexToString(hexValue).trim(); return str; + } else if (data.dataType === 'hex') { + let str = rearrangeHexStr(hexValue); + return str; } - else if(data.dataType === 'hex'){ - let str = rearrangeHexStr(hexValue); - return str; - } - // else if(data.dataType === 'firmware'){ - // let str = hexToVersion(hexValue); - // return str; - // } - else { + // else if(data.dataType === 'firmware'){ + // let str = hexToVersion(hexValue); + // return str; + // } + else { return hexValue; } } @@ -435,13 +456,13 @@ const sendDeviceAttr = (data, type, index) => { deviceAttrCommonList.value[type].datatype, data.startValue, data.lengthValue, - data.inputValue, - data + data.inputValue, + data ); if (type === 'input') { deviceAttrList.value[index].inputLoadingStatus = true; - // head = head + 'd240'; + // head = head + 'd240'; } else { deviceAttrList.value[index].outputLoadingStatus = true; } @@ -453,7 +474,7 @@ const sendDeviceAttr = (data, type, index) => { data: head, hex: 1, crc: 1, - flush:1 + flush: 1 }, { headers: { @@ -495,177 +516,346 @@ const sendDeviceAttr = (data, type, index) => { }; const allReadDeviceAttr = () => { - if (!serialportForm.port) { - ElMessage.error('请先打开串口'); - return ''; - } + if (!serialportForm.port) { + ElMessage.error('请先打开串口'); + return ''; + } - let head = buildHead( - deviceAttrCommonList.value['output'].datalentype, - deviceAttrCommonList.value['output'].remote_id, - deviceAttrCommonList.value['output'].local_id, - deviceAttrCommonList.value['output'].cmd, - deviceAttrCommonList.value['output'].devtype, - deviceAttrCommonList.value['output'].datatype, - 0, - 46, - '' - ); + let head = buildHead( + deviceAttrCommonList.value['output'].datalentype, + deviceAttrCommonList.value['output'].remote_id, + deviceAttrCommonList.value['output'].local_id, + deviceAttrCommonList.value['output'].cmd, + deviceAttrCommonList.value['output'].devtype, + deviceAttrCommonList.value['output'].datatype, + 0, + 46, + '' + ); - 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); // 打印响应数据 - if (response.data.code === 0) { - ElMessage.success('操作成功'); - let hexValue = response.data.data.hex.substring(24, 392); - let startValue = 0; - deviceAttrList.value.forEach((item, index) => { - if(startValue === 0){ - startValue = item.startValue; - } - let value = hexValue.substring(startValue, item.lengthValue * 4 * 2 + startValue); - startValue = startValue + item.lengthValue * 4 * 2; - console.log("value",value) - if (item.dataType === 'str') { - deviceAttrList.value[index].outputValue = hexToString(value).trim(); - deviceAttrList.value[index].inputValue = hexToString(value).trim(); - }else if (item.dataType === 'hex') { - deviceAttrList.value[index].outputValue = rearrangeHexStr(value); - deviceAttrList.value[index].inputValue = rearrangeHexStr(value); - }else{ - deviceAttrList.value[index].outputValue = value; - deviceAttrList.value[index].inputValue = value; - } - }) - // deviceAttrList.value[index].outputValue = analysisData(response.data.data.hex || '', data); - } else { - ElMessage.error(response.data.message); - } - }) - .catch(error => { - console.log('error', error); - // 错误处理 - if (error.response.data.message) { - ElMessage.error(error.response.data.message); - } else { - ElMessage.error(error); - } - }); -} + 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); // 打印响应数据 + if (response.data.code === 0) { + ElMessage.success('操作成功'); + let hexValue = response.data.data.hex.substring(24, 392); + let startValue = 0; + deviceAttrList.value.forEach((item, index) => { + if (startValue === 0) { + startValue = item.startValue; + } + let value = hexValue.substring(startValue, item.lengthValue * 4 * 2 + startValue); + startValue = startValue + item.lengthValue * 4 * 2; + console.log('value', value); + if (item.dataType === 'str') { + deviceAttrList.value[index].outputValue = hexToString(value).trim(); + deviceAttrList.value[index].inputValue = hexToString(value).trim(); + } else if (item.dataType === 'hex') { + deviceAttrList.value[index].outputValue = rearrangeHexStr(value); + deviceAttrList.value[index].inputValue = rearrangeHexStr(value); + } else { + deviceAttrList.value[index].outputValue = value; + deviceAttrList.value[index].inputValue = value; + } + }); + // deviceAttrList.value[index].outputValue = analysisData(response.data.data.hex || '', data); + } else { + ElMessage.error(response.data.message); + } + }) + .catch(error => { + console.log('error', error); + // 错误处理 + if (error.response.data.message) { + ElMessage.error(error.response.data.message); + } else { + ElMessage.error(error); + } + }); +}; const allWriteDeviceAttr = () => { - if (!serialportForm.port) { - ElMessage.error('请先打开串口'); - return ''; - } - deviceAttrList.value.forEach((item, index)=>{ - setTimeout(()=>{ - sendDeviceAttr(item, 'input', index) - },50) - }) + if (!serialportForm.port) { + ElMessage.error('请先打开串口'); + return ''; + } + deviceAttrList.value.forEach((item, index) => { + setTimeout(() => { + sendDeviceAttr(item, 'input', index); + }, 50); + }); - // 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, - // 0, - // 46, - // '' - // ); - // - // axios - // .post( - // config.serialPortUrl + '/serial/response', - // { - // port: serialportForm.port, - // data: head, - // hex: 1, - // crc: 1 - // }, - // { - // headers: { - // 'Content-Type': 'application/x-www-form-urlencoded' - // } - // } - // ) - // .then(response => { - // // 成功响应后的处理 - // console.log('串口请求', response); // 打印响应数据 - // if (response.data.code === 0) { - // ElMessage.success('操作成功'); - // let hexValue = response.data.data.hex.substring(24, 392); - // let startValue = 0; - // deviceAttrList.value.forEach((item, index) => { - // if(startValue === 0){ - // startValue = item.startValue; - // } - // let value = hexValue.substring(startValue, item.lengthValue * 4 * 2 + startValue); - // startValue = startValue + item.lengthValue * 4 * 2; - // console.log("value",value) - // if (item.dataType === 'str') { - // deviceAttrList.value[index].outputValue = hexToString(value).trim(); - // deviceAttrList.value[index].inputValue = hexToString(value).trim(); - // }else{ - // deviceAttrList.value[index].outputValue = value; - // deviceAttrList.value[index].inputValue = value; - // } - // }) - // // deviceAttrList.value[index].outputValue = analysisData(response.data.data.hex || '', data); - // } else { - // ElMessage.error(response.data.message); - // } - // }) - // .catch(error => { - // console.log('error', error); - // // 错误处理 - // if (error.response.data.message) { - // ElMessage.error(error.response.data.message); - // } else { - // ElMessage.error(error); - // } - // }); -} + // 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, + // 0, + // 46, + // '' + // ); + // + // axios + // .post( + // config.serialPortUrl + '/serial/response', + // { + // port: serialportForm.port, + // data: head, + // hex: 1, + // crc: 1 + // }, + // { + // headers: { + // 'Content-Type': 'application/x-www-form-urlencoded' + // } + // } + // ) + // .then(response => { + // // 成功响应后的处理 + // console.log('串口请求', response); // 打印响应数据 + // if (response.data.code === 0) { + // ElMessage.success('操作成功'); + // let hexValue = response.data.data.hex.substring(24, 392); + // let startValue = 0; + // deviceAttrList.value.forEach((item, index) => { + // if(startValue === 0){ + // startValue = item.startValue; + // } + // let value = hexValue.substring(startValue, item.lengthValue * 4 * 2 + startValue); + // startValue = startValue + item.lengthValue * 4 * 2; + // console.log("value",value) + // if (item.dataType === 'str') { + // deviceAttrList.value[index].outputValue = hexToString(value).trim(); + // deviceAttrList.value[index].inputValue = hexToString(value).trim(); + // }else{ + // deviceAttrList.value[index].outputValue = value; + // deviceAttrList.value[index].inputValue = value; + // } + // }) + // // deviceAttrList.value[index].outputValue = analysisData(response.data.data.hex || '', data); + // } else { + // ElMessage.error(response.data.message); + // } + // }) + // .catch(error => { + // console.log('error', error); + // // 错误处理 + // if (error.response.data.message) { + // ElMessage.error(error.response.data.message); + // } else { + // ElMessage.error(error); + // } + // }); +}; +const commonDebuggerFormRef = ref(); -// const commonDebuggerFormRef = ref(); -// -// const commonDebuggerList = ref([]); -// -// const commonDebuggerForm = reactive({ -// localId:'', -// port: '', -// baudrate: 115200, -// databits: 8, -// parity: 0, -// stopbits: 0 -// }); -// -// const commonDebuggerRules = reactive({ -// port: [{ required: true, message: '请选择端口', trigger: 'change' }], -// baudrate: [{ required: true, message: '请选择波特率', trigger: 'change' }], -// databits: [{ required: true, message: '请选择port', trigger: 'change' }], -// parity: [{ required: true, message: '请选择userName', trigger: 'change' }], -// stopbits: [{ required: true, message: '请选择passWord', trigger: 'change' }] -// }); +const sendCommonDebuggerState = ref(false); + +const commonDebuggerForm = ref({ + localId: '', + remoteId: '', + devType: '00', + dataType: '00', + cmd: '0011', + dataLenType: '00', + writeStart: 0, + writeLength: 0, + writeData: '', + dataStr: '', + hexStr: '' +}); + +const devTypeList = ref([ + { + 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(() => { @@ -708,11 +898,11 @@ onUnmounted(() => {}); } } } - .btn-box{ - display: flex; - justify-content: center; - padding: 20px; - } + .btn-box { + display: flex; + justify-content: center; + padding: 20px; + } } :deep(.el-form) {