| | |
| | | import { ElMessage, ElMessageBox } from 'element-plus' |
| | | import { ElMessage, ElMessageBox, ElNotification } from 'element-plus' |
| | | const { SerialPort } = require('serialport') |
| | | const { DelimiterParser } = require('@serialport/parser-delimiter') |
| | | const { ReadyParser } = require('@serialport/parser-ready') |
| | |
| | | if(reconnectAttempts!==0){ |
| | | console.log('ssss',reconnectAttempts) |
| | | ipcRenderer.invoke('logger', '串口重连第${reconnectAttempts}次') |
| | | ElMessage({ |
| | | ElMessage.warning({ |
| | | message: `串口重连第${reconnectAttempts}次启动`, |
| | | type: 'success', |
| | | }) |
| | |
| | | if (err) { |
| | | console.log(err) |
| | | ipcRenderer.invoke('logger', 'M503体重秤端口打开失败!') |
| | | ElMessage({ |
| | | ElNotification.warning({ |
| | | title: '警告', |
| | | message: 'M503体重秤端口打开失败!', |
| | | type: 'error', |
| | | }) |
| | | showClose: false, |
| | | duration:10000 |
| | | }) |
| | | setTimeout(()=>{ |
| | | initPort(path,baudRate) |
| | | }, RECONNECT_INTERVAL); |
| | | }else{ |
| | | reconnectAttempts=0 |
| | | ipcRenderer.invoke('logger', 'M503体重秤端口打开成功') |
| | | ipcRenderer.invoke('logger', 'M503体重秤端口打开成功'+path) |
| | | ElMessage({ |
| | | message: 'M503体重秤端口打开成功', |
| | | type: 'success', |
| | |
| | | // |
| | | // 55 53 2C 47 53 20 20 20 20 31 33 30 2E 35 6B 67 0D 0A 135 |
| | | // 53 54 2C 47 53 20 20 20 31 33 39 2E 39 6B 67 0D 0A ST,GS 139.9kg |
| | | //53 54 2C 4E 54 20 20 20 20 20 30 2E 30 6B 67 |
| | | // 55 53 2C 47 53 20 20 20 20 36 30 2E 35 6B 67 0D 0A HEX |
| | | const parser = serialport.pipe(new DelimiterParser({ delimiter:Buffer.from([13,10]),includeDelimiter:true })) |
| | | parser.on('data', (value: string | any[])=>{ |
| | | const str=value.toString() |
| | | const list=str.split(' ') |
| | | ipcRenderer.invoke('logger', 'M503体重秤数据接收!'+str) |
| | | console.log('解析体重数值',list) |
| | | if(list.length>=4&&list[0].search('ST,GS')!==-1){ |
| | | const re=list[list.length-1].trim() |