fast(串口调试): 添加串口通用调试(地址读写指令)、打包1.0.7
This commit is contained in:
parent
1c024beeb8
commit
9364ef8412
|
@ -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",
|
||||
|
|
|
@ -60,13 +60,13 @@
|
|||
</el-collapse>
|
||||
</div>
|
||||
<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 type="primary" @click="sendData">启动标定</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">步骤3</el-button>-->
|
||||
<!-- <el-button type="primary" @click="sendData">步骤4</el-button>-->
|
||||
<!-- <el-button type="primary" @click="sendData">步骤5</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">步骤1</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">步骤4</el-button>-->
|
||||
<!-- <el-button type="primary" @click="sendData">步骤5</el-button>-->
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 生命周期钩子
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
<div id="serialport-main" class="serialport-main">
|
||||
<el-collapse v-model="activeFold" @change="foldChange">
|
||||
<el-collapse-item name="1" title="串口设置">
|
||||
<el-form ref="serialportFormRef" :model="serialportForm" :rules="serialportRules" class="demo-serialportForm" label-width="auto" status-icon>
|
||||
<el-form-item label="端口" prop="port" required >
|
||||
<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-select>
|
||||
<el-button style="margin-left: 10px" type="primary" @click="getSerialPortList">获取端口列表</el-button>
|
||||
<el-form ref="serialportFormRef" :model="serialportForm" :rules="serialportRules" class="demo-serialportForm" label-width="auto" status-icon>
|
||||
<el-form-item label="端口" prop="port" required>
|
||||
<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-select>
|
||||
<el-button style="margin-left: 10px" type="primary" @click="getSerialPortList">获取端口列表</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item label="波特率" prop="baudrate" required>
|
||||
<el-select v-model="serialportForm.baudrate" :disabled="connectionState" placeholder="选择波特率">
|
||||
|
@ -50,57 +50,78 @@
|
|||
</el-form-item>
|
||||
</el-form>
|
||||
</el-collapse-item>
|
||||
<!-- <el-collapse-item name="2" title="通用调试">-->
|
||||
<!-- <el-form ref="commonDebuggerFormRef" :model="commonDebuggerForm" :rules="commonDebuggerRules" class="demo-serialportForm" label-width="auto" status-icon>-->
|
||||
<!-- <el-form-item label="数据类型" prop="dataType">-->
|
||||
<!-- <el-input-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- <el-form-item label="端口" prop="port" required >-->
|
||||
<!-- <el-select v-model="commonDebuggerForm.port" :disabled="connectionState" placeholder="选择端口" style="flex: 1">-->
|
||||
<!-- <el-option v-for="(item, index) in serialportList" :key="index" :label="item" :value="item" />-->
|
||||
<!-- </el-select>-->
|
||||
<!-- <el-button style="margin-left: 10px" type="primary" @click="getSerialPortList">获取端口列表</el-button>-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- <el-form-item label="波特率" prop="baudrate" required>-->
|
||||
<!-- <el-select v-model="commonDebuggerForm.baudrate" :disabled="connectionState" placeholder="选择波特率">-->
|
||||
<!-- <el-option label="4800" :value="4800" />-->
|
||||
<!-- <el-option label="9600" :value="9600" />-->
|
||||
<!-- <el-option label="19200" :value="19200" />-->
|
||||
<!-- <el-option label="43000" :value="43000" />-->
|
||||
<!-- <el-option label="56000" :value="56000" />-->
|
||||
<!-- <el-option label="115200" :value="115200" />-->
|
||||
<!-- </el-select>-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- <el-form-item label="数据位" prop="databits" required>-->
|
||||
<!-- <el-select v-model="commonDebuggerForm.databits" :disabled="connectionState" placeholder="选择数据位">-->
|
||||
<!-- <el-option label="5" :value="5" />-->
|
||||
<!-- <el-option label="6" :value="6" />-->
|
||||
<!-- <el-option label="7" :value="7" />-->
|
||||
<!-- <el-option label="8" :value="8" />-->
|
||||
<!-- </el-select>-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- <el-form-item label="校验位" prop="parity" required>-->
|
||||
<!-- <el-select v-model="commonDebuggerForm.parity" :disabled="connectionState" placeholder="选择校验位">-->
|
||||
<!-- <el-option label="None" :value="0" />-->
|
||||
<!-- <el-option label="Odd" :value="1" />-->
|
||||
<!-- <el-option label="Even" :value="2" />-->
|
||||
<!-- <el-option label="Mark" :value="3" />-->
|
||||
<!-- <el-option label="Space" :value="4" />-->
|
||||
<!-- </el-select>-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- <el-form-item label="停止位" prop="stopbits" required>-->
|
||||
<!-- <el-select v-model="commonDebuggerForm.stopbits" :disabled="connectionState" placeholder="选择停止位">-->
|
||||
<!-- <el-option label="1" :value="0" />-->
|
||||
<!-- <el-option label="1.5" :value="1" />-->
|
||||
<!-- <el-option label="2" :value="2" />-->
|
||||
<!-- </el-select>-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- <el-form-item class="btn-box">-->
|
||||
<!-- <el-button type="danger" @click="disconnSerialPort">关闭 </el-button>-->
|
||||
<!-- <el-button type="primary" @click="connectSerialPort(serialportFormRef)">{{ connectionState ? '已打开' : '打开' }}</el-button>-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- </el-form>-->
|
||||
<!-- </el-collapse-item>-->
|
||||
<el-collapse-item name="2" title="通用调试">
|
||||
<el-form ref="commonDebuggerFormRef" :model="commonDebuggerForm" :rules="commonDebuggerRules" class="demo-serialportForm" label-width="auto" status-icon>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="本地ID" prop="localId">
|
||||
<el-input v-model="commonDebuggerForm.localId" placeholder="请输入本地ID" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="目标ID" prop="remoteId">
|
||||
<el-input v-model="commonDebuggerForm.remoteId" placeholder="请输入目标ID" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="设备类型" prop="devType" required>
|
||||
<el-select v-model="commonDebuggerForm.devType" placeholder="选择设备类型" style="flex: 1">
|
||||
<el-option v-for="(item, index) in devTypeList" :key="index" :label="item.label" :value="item.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="数据类型" prop="dataType" required>
|
||||
<el-select v-model="commonDebuggerForm.dataType" placeholder="选择数据类型" style="flex: 1">
|
||||
<el-option v-for="(item, index) in dataTypeList" :key="index" :label="item.label" :value="item.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="指令码" prop="cmd" required>
|
||||
<el-select v-model="commonDebuggerForm.cmd" placeholder="选择指令码" style="flex: 1">
|
||||
<el-option v-for="(item, index) in cmdList" :key="index" :label="item.label" :value="item.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="数据长度类型" prop="dataLenType" required>
|
||||
<el-select v-model="commonDebuggerForm.dataLenType" placeholder="选择数据长度类型" style="flex: 1">
|
||||
<el-option v-for="(item, index) in dataLenTypeList" :key="index" :label="item.label" :value="item.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row v-if="commonDebuggerForm.cmd === '0100' || commonDebuggerForm.cmd === '0011'">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="起始地址" prop="writeStart" required>
|
||||
<el-input v-model="commonDebuggerForm.writeStart" type="number" placeholder="请输入起始地址" />
|
||||
</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="设备基础参数">
|
||||
<div class="device-attr-list">
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-box">
|
||||
<el-button type="primary" @click="allReadDeviceAttr">一键读取</el-button>
|
||||
<el-button type="primary" @click="allWriteDeviceAttr">一键写入</el-button>
|
||||
</div>
|
||||
<div class="btn-box">
|
||||
<el-button type="primary" @click="allReadDeviceAttr">一键读取</el-button>
|
||||
<el-button type="primary" @click="allWriteDeviceAttr">一键写入</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-collapse-item>
|
||||
</el-collapse>
|
||||
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue