| | |
| | | <script setup> |
| | | |
| | | import {ref} from "vue"; |
| | | import {ipc} from '@/utils/ipcRenderer' |
| | | import {onBeforeUnmount, ref} from "vue"; |
| | | import {useStore} from "@/stores/icrfStore"; |
| | | const store = useStore(); |
| | | // 连接模式 |
| | | const mode = ref(2); |
| | | const mode = ref(store.mode); |
| | | // 设备编号 |
| | | const deviceId = ref(1); |
| | | const com = ref(); |
| | | const deviceId = ref(store.deviceId); |
| | | // 串口地址 |
| | | const com = ref(store.com); |
| | | // 波特率 |
| | | const serialBaud = ref(store.serialBaud); |
| | | const serialBaudList = ref([ |
| | | 9600,19200,38400,57600,115200 |
| | | ]) |
| | | const data = ref( [ |
| | | ]); |
| | | //com列表 |
| | | const comList = ref([]); |
| | | const isLJ = ref(store.isLJ) |
| | | const icdev = ref(); |
| | | |
| | | const initListPort = () =>{ |
| | | ipc.invoke('controller.port.initPort',1).then(res=>{ |
| | | console.log(res) |
| | | comList.value = res; |
| | | |
| | | if (comList.value.length > 0){ |
| | | com.value = 0; |
| | | } |
| | | }) |
| | | } |
| | | /** |
| | | * 连接设备 |
| | | */ |
| | | const setLocalICRF = () => { |
| | | if(mode.value === 1){ |
| | | ipc.invoke('controller.icrf.connectUsb',{number:deviceId.value}); |
| | | }else{ |
| | | let port = comList.value[com.value]; |
| | | let portNum = port.path.slice(3); |
| | | ipc.invoke('controller.icrf.connectSerialPort',{port:(Number(portNum) -1),baud:serialBaud.value}); |
| | | } |
| | | |
| | | } |
| | | /** |
| | | * 断开设备 |
| | | */ |
| | | const disconnectLocalICRF =()=>{ |
| | | ipc.invoke('controller.icrf.connectExit').then(res=>{ |
| | | if (res.code === 0){ |
| | | isLJ.value = false; |
| | | store.$reset(); |
| | | } |
| | | data.value.unshift(res.msg); |
| | | }); |
| | | |
| | | } |
| | | |
| | | const resetLocal = ()=>{ |
| | | ipc.invoke('controller.icrf.connectExit').then(res=>{ |
| | | isLJ.value = false; |
| | | store.$reset(); |
| | | data.value.unshift("重置连接成功"); |
| | | }); |
| | | |
| | | } |
| | | |
| | | ipc.on('controller.icrf.communication',(event,ret)=>{ |
| | | if (Number(ret.handle) > 0){ |
| | | icdev.value = Number(ret.handle) |
| | | isLJ.value = true; |
| | | store.$patch({ |
| | | mode: mode.value, |
| | | deviceId: deviceId.value, |
| | | com: com.value, |
| | | serialBaud: serialBaud.value, |
| | | icdev: icdev.value, |
| | | isLJ: true, |
| | | }) |
| | | } |
| | | data.value.unshift(ret.msg); |
| | | }) |
| | | onBeforeUnmount(()=>{ |
| | | ipc.removeAllListeners('controller.icrf.communication') |
| | | }) |
| | | |
| | | |
| | | initListPort(); |
| | | </script> |
| | | |
| | | <template> |
| | |
| | | <div class="card-box"> |
| | | <div class="flex-1 " style="margin-right: 10px"> |
| | | <Section title="连接模式"> |
| | | <a-radio-group v-model:value="mode"> |
| | | <a-radio-group v-model:value="mode" :disabled="isLJ"> |
| | | <a-radio :value="1">USB</a-radio> |
| | | <a-radio :value="2">Serial Port</a-radio> |
| | | </a-radio-group> |
| | | </Section> |
| | | |
| | | <Section title="设备编号"> |
| | | <a-input v-model:value="deviceId" placeholder="请输入" /> |
| | | <a-input :disabled="mode !== 1 || isLJ" v-model:value="deviceId" placeholder="请输入" /> |
| | | </Section> |
| | | |
| | | <Section title="串口号"> |
| | | <a-select |
| | | <a-select :disabled="mode !== 2 || isLJ" |
| | | ref="select" |
| | | v-model:value="com" |
| | | style="width: 100%;" |
| | | @change="handleChange" |
| | | > |
| | | <a-select-option value="jack">COM1</a-select-option> |
| | | <a-select-option value="lucy">COM2</a-select-option> |
| | | <a-select-option :value="index" v-for="(item,index) in comList">{{ item.path }}</a-select-option> |
| | | </a-select> |
| | | </Section> |
| | | |
| | | <Section title="波特率"> |
| | | <a-select |
| | | <a-select :disabled="mode !== 2 || isLJ" |
| | | ref="select" |
| | | v-model:value="com" |
| | | v-model:value="serialBaud" |
| | | style="width: 100%;" |
| | | @change="handleChange" |
| | | > |
| | | <a-select-option value="jack">COM1</a-select-option> |
| | | <a-select-option value="lucy">COM2</a-select-option> |
| | | <a-select-option :value="item" v-for="(item,index) in serialBaudList" :key="index">{{ item }}</a-select-option> |
| | | </a-select> |
| | | </Section> |
| | | <div style="margin-top: 20px;text-align: right;"> |
| | | <a-button style="margin-right: 20px;width: 150px">连接设备</a-button> |
| | | <a-button style="width: 150px">断开连接</a-button> |
| | | <a-button style="margin-right: 20px;width: 150px" :disabled="isLJ" @click="setLocalICRF">连接设备</a-button> |
| | | <a-button style="width: 150px" :disabled="!isLJ" @click="disconnectLocalICRF">断开连接</a-button> |
| | | <a-button style="margin-left: 20px;width: 150px;margin-top: 10px" @click="resetLocal">重置</a-button> |
| | | </div> |
| | | </div> |
| | | <div class="flex-1 box-right"> |
| | |
| | | .aList{ |
| | | overflow: auto; |
| | | height: 330px; |
| | | max-height: 100%; |
| | | min-height: 100%; |
| | | } |
| | | } |
| | | } |