From e0301d12be2ba6c04613f23c24734c48a30caad8 Mon Sep 17 00:00:00 2001 From: zhaochongyi <11111> Date: 星期一, 26 八月 2024 19:07:18 +0800 Subject: [PATCH] 修改初始化 --- electron/utils/websocket.js | 5 + electron/config/config.default.js | 5 + electron/controller/port.js | 16 ++--- frontend/components.d.ts | 1 frontend/src/views/communication/index.vue | 60 +++++++++++++++---- electron/controller/icrf.js | 33 +++++++++++ frontend/src/App.vue | 4 - README.md | 5 + 8 files changed, 102 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index ab3f9e1..f971e03 100644 --- a/README.md +++ b/README.md @@ -1 +1,4 @@ -鏅鸿兘IC鍗¤鍐欐闈㈢▼搴� \ No newline at end of file +鏅鸿兘IC鍗¤鍐欐闈㈢▼搴� + + +npm config set registry https://registry.npmmirror.com diff --git a/electron/config/config.default.js b/electron/config/config.default.js index 5c090a3..4e4e256 100644 --- a/electron/config/config.default.js +++ b/electron/config/config.default.js @@ -113,9 +113,12 @@ * 涓昏繘绋� */ config.mainServer = { + protocol: 'file://', indexPath: '/public/dist/index.html', - }; + }; + + /** * 纭欢鍔犻�� diff --git a/electron/controller/icrf.js b/electron/controller/icrf.js new file mode 100644 index 0000000..9e79d44 --- /dev/null +++ b/electron/controller/icrf.js @@ -0,0 +1,33 @@ +const {Controller} = require("ee-core"); +const Ps = require("ee-core/ps"); +const koffi = require('koffi'); +const path = require("path"); +class IcrfController extends Controller{ + hcicrf =null; + constructor(ctx) { + super(ctx); + const dllPath = path.join(Ps.getExtraResourcesDir(),'dll','hc_icrf32.dll'); + this.hcicrf =koffi.load(dllPath); + } + async hc_init(params){ + const hc_init = this.hcicrf.func('int __stdcall hc_init(short port, uint32_t baud)'); + let hcInit = hc_init(2, 115200); + console.log(hcInit); + if (hcInit <=0){ + // let errMsg = this.getErrMsg(hcInit); + //console.log(errMsg) + } + return hcInit; + } + + getErrMsg(st){ + let getErrMsg = this.hcicrf.func("int getErrMsg(short st,short lg, char errMsg)"); + let errMsg = getErrMsg(st, 0, 1024); + console.log(errMsg) + return errMsg; + } + +} + +IcrfController.toString = ()=> '[class IcrfController]'; +module.exports =IcrfController; \ No newline at end of file diff --git a/electron/controller/port.js b/electron/controller/port.js index 0f815b4..5a18768 100644 --- a/electron/controller/port.js +++ b/electron/controller/port.js @@ -1,21 +1,19 @@ -import { Controller } from "ee-core"; -import { SerialPort } from "serialport"; +const { Controller } = require("ee-core"); +const { SerialPort } = require("serialport"); const Services = require('ee-core/services') -class Port extends Controller{ +class PortController extends Controller{ constructor(ctx){ super(ctx) } async initPort(bool){ - console.log(bool) if(bool){ - SerialPort.list().then((ports)=>{ - setTimeout(()=>{ - }) - }) + return SerialPort.list(); } } -} \ No newline at end of file +} +PortController.toString = () => '[class PortController]'; +module.exports = PortController; \ No newline at end of file diff --git a/electron/utils/websocket.js b/electron/utils/websocket.js new file mode 100644 index 0000000..072fb75 --- /dev/null +++ b/electron/utils/websocket.js @@ -0,0 +1,5 @@ +class WebsocketUtil { + constructor() { + } + +} \ No newline at end of file diff --git a/frontend/components.d.ts b/frontend/components.d.ts index d2472e8..e0d11cc 100644 --- a/frontend/components.d.ts +++ b/frontend/components.d.ts @@ -9,6 +9,7 @@ export interface GlobalComponents { AButton: typeof import('ant-design-vue/es')['Button'] ACard: typeof import('ant-design-vue/es')['Card'] + ACheckbox: typeof import('ant-design-vue/es')['Checkbox'] AInput: typeof import('ant-design-vue/es')['Input'] ALayout: typeof import('ant-design-vue/es')['Layout'] ALayoutContent: typeof import('ant-design-vue/es')['LayoutContent'] diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 996ba2d..c5552b3 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -3,14 +3,12 @@ </template> <script> -import {ipc} from '@/utils/ipcRenderer' + export default { name: 'App', setup() { document.getElementById('loadingPage').remove(); - ipc.invoke('controller.port.initPort',1).then(res=>{ - }) } } </script> diff --git a/frontend/src/views/communication/index.vue b/frontend/src/views/communication/index.vue index 73a39c8..1652a8c 100644 --- a/frontend/src/views/communication/index.vue +++ b/frontend/src/views/communication/index.vue @@ -1,13 +1,51 @@ <script setup> - + import {ipc} from '@/utils/ipcRenderer' import {ref} from "vue"; // 杩炴帴妯″紡 const mode = ref(2); // 璁惧缂栧彿 const deviceId = ref(1); + // 涓插彛鍦板潃 const com = ref(); + // 娉㈢壒鐜� + const serialBaud = ref(115200); + const serialBaudList = ref([ + 9600,19200,38400,57600,115200 + ]) const data = ref( [ ]); + //com鍒楄〃 + const comList = ref([]); + const isLJ = ref(false) + + + 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 = () => { + ipc.invoke('controller.icrf.hc_init',{port:com.value,baud:serialBaud.value}).then(res=>{ + console.log(res) + }); + } + /** + * 鏂紑璁惧 + */ + const disconnectLocalICRF =()=>{ + + } + + + initListPort(); </script> <template> @@ -23,35 +61,31 @@ </Section> <Section title="璁惧缂栧彿"> - <a-input v-model:value="deviceId" placeholder="璇疯緭鍏�" /> + <a-input :disabled="mode !== 1" v-model:value="deviceId" placeholder="璇疯緭鍏�" /> </Section> <Section title="涓插彛鍙�"> - <a-select + <a-select :disabled="mode !== 2" 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" 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> </div> </div> <div class="flex-1 box-right"> -- Gitblit v1.8.0