chenyc
2024-09-04 0f38c5e72493ee138a68ddc0bd838f1aa314f4b4
优化程序 更新邦尔的体重称签到通讯
4个文件已修改
1个文件已添加
254 ■■■■ 已修改文件
src/samples/deviceApi/M503.ts 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/samples/deviceApi/seca101Banger.ts 150 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/samples/node-api.ts 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/stores/sockteInfo.ts 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/home/index.vue 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/samples/deviceApi/M503.ts
@@ -4,6 +4,7 @@
const { ReadyParser } = require('@serialport/parser-ready')
import {sockteStore} from '@/stores/sockteInfo'
import { ipcRenderer  } from 'electron'
import console from 'console'
// 设置重连间隔和最大重试次数
@@ -88,22 +89,22 @@
        //ST,GS 70.4kg
        //
        //
        //53 54 2C 47 53 20 20 20 20 20 30 2E 30 6B 67 0D 0A
        //53 54 2C 47 53 20 20 20 20 20 30 2E 30 6B 67 0D 0A   0.0kg
        //
        // 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
        // 53 54 2C 47 53 20 20 20 31 33 39 2E 39 6B 67 0D 0A   ST,GS   139.9kg
        // 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[])=>{
            // console.log(value.toString())
            const str=value.toString()
            const list=str.split(' ')
            // console.log(list)
            console.log('解析体重数值',list)
            if(list.length>=4&&list[0].search('ST,GS')!==-1){
                const re=list[list.length-1].trim()
                const res=re.substring(0,re.length-2)
                // console.log(res,'获取到的体重')
                console.log('提前到有用的体重数值',res)
                if(Number(res)>=20){
                    console.log('更新体重',res)
                    sockteStore().setweightSockte(
                        {
                            deviceName:'台衡M503',
@@ -114,7 +115,13 @@
                        }
                    )
                }else{
                    console.log('体重小于30KG')
                    const retst=Number(res)
                    if(retst<1){
                        // 体重接收小于1 就算初始化了
                        sockteStore().setis测量准备(true)
                        console.log('体重小于1千克,体重归零状态打开',)
                    }
                }
                
            }else{
src/samples/deviceApi/seca101Banger.ts
New file
@@ -0,0 +1,150 @@
import { ElMessage, ElMessageBox } from 'element-plus'
const { SerialPort } = require('serialport')
const { DelimiterParser } = require('@serialport/parser-delimiter')
const { ReadyParser } = require('@serialport/parser-ready')
import {sockteStore} from '@/stores/sockteInfo'
import { ipcRenderer  } from 'electron'
import console from 'console'
import { confingInfoStore } from '@/stores/StoresConfing'
// 设置重连间隔和最大重试次数
const RECONNECT_INTERVAL = 10000; // 重连间隔10秒
const MAX_RECONNECT_ATTEMPTS = 10; // 最大重试次数10次
let reconnectAttempts = 0; // 当前重试次数
let serialPort:any; // 串口实例
const initPort=(path:String,baudRate:Number)=>{
    const yanjiancishu=confingInfoStore().confingInfo.jianyancishu===undefined?4:confingInfoStore().confingInfo.jianyancishu
    console.log('初始化打开邦尔赛康101体重秤端口')
    let lisijieguo=''
    let duibinum=0
    if(reconnectAttempts!==0){
        console.log('ssss',reconnectAttempts)
        ipcRenderer.invoke('logger', '串口重连第${reconnectAttempts}次')
        ElMessage({
            message: `串口重连第${reconnectAttempts}次启动`,
            type: 'success',
        })
    }
    if (reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) {
        console.error('重试次数达到上限,不再尝试重连。');
        ipcRenderer.invoke('logger', '串口已经重连了${reconnectAttempts}次了,点击确认关闭程序,重启电脑后再试')
        ElMessageBox.confirm(
            `串口已经重连了${reconnectAttempts}次了,点击确认关闭程序,重启电脑后再试`,
            'Warning',
            {
              confirmButtonText: '确认',
              cancelButtonText: '取消',
              type: 'warning',
            }
          )
            .then(() => {
                ipcRenderer.send('winClose')
                ipcRenderer.invoke('logger', '确认了关闭程序')
            })
            .catch(() => {
              ElMessage({
                type: 'info',
                message: '取消操作',
              })
            })
        return;
    }
    if (serialPort && serialPort.isOpen) {
        reconnectAttempts=0
        console.log('串口已打开,不再重复打开。');
        return;
    }
    try {
        const serialport  = new SerialPort({ path, baudRate }, (err: any) => {
            reconnectAttempts++
            if (err) {
                console.log(err)
                ipcRenderer.invoke('logger', '邦尔赛康101体重秤端口打开失败!')
                ElMessage({
                    message: '邦尔赛康101体重秤端口打开失败!',
                    type: 'error',
                })
                setTimeout(()=>{
                    initPort(path,baudRate)
                }, RECONNECT_INTERVAL);
            }else{
                reconnectAttempts=0
                ipcRenderer.invoke('logger', '邦尔赛康101体重秤端口打开成功')
                ElMessage({
                    message: '邦尔赛康101体重秤端口打开成功',
                    type: 'success',
                })
            }
        })
        serialport.on("close",(err: any)=>{
            ipcRenderer.invoke('logger', '邦尔赛康101体重秤端口异常端口链接关闭')
            console.log('邦尔赛康101体重秤端口异常端口链接断开')
            reconnectAttempts=0
            setTimeout(()=>{
                initPort(path,baudRate)
            }, RECONNECT_INTERVAL);
            console.log(err)
        })
        // 解析分割数据流
        // 02 41 30 30 30 30 30 30 31 30 31 30 30 41 39 0D 0A 03   A00000010100A9
        // 02 41 30 30 30 36 36 38 31 30 31 30 30 41 41 0D 0A 03
        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('A0')
            if(list.length===2&&list[1].length>5){
                const re=list[1].trim()
                const res=Number(re.substring(1,4)+'.'+re.substring(4,5)).toString()
                // 如果小于1 说明体重秤归零了
                if(Number(res)<1){
                    // 体重接收小于1 就算初始化了
                    sockteStore().setis测量准备(true)
                    console.log('体重小于1千克,体重归零状态打开',)
                }else{ // 大于1的才判断
                    // 判断是否相等 相等加一
                    if(res===lisijieguo){
                        duibinum++
                    }else{
                        lisijieguo=res
                        duibinum=0
                    }
                    // 对比3次结果都一致
                    if(duibinum>=yanjiancishu){
                        console.log(res,'获取到的体重')
                        sockteStore().setweightSockte(
                            {
                                deviceName:'seca102',
                                type:"体重秤",
                                result:res,
                                resultTime:new Date().toString(),
                                state:2
                            }
                        )
                        duibinum=0
                        lisijieguo=''
                    }
                }
            }else{
                console.log('数据格式不对')
            }
        }) // all data after READY is received
    }
    catch (error:any) {
        console.error('无法创建串口实例:', error.message);
        reconnectAttempts=0
        setTimeout(()=>{
            initPort(path,baudRate)
        }, RECONNECT_INTERVAL);
    }
}
export {
    initPort,
}
src/samples/node-api.ts
@@ -9,7 +9,7 @@
import os from 'os'
// import internetAvailable  from "internet-available"
var internetAvailable = require("internet-available")
import { ElMessage, ElMessageBox } from 'element-plus'
import { ElMessage, ElMessageBox, ElNotification } from 'element-plus'
import { on } from 'events'
interface ResultInfo{
@@ -70,9 +70,19 @@
    sockteStore().setnetLink(true)
  }).catch(()=>{
    sockteStore().setnetLink(false)
    ElNotification({
      title: 'Success',
      message: '网络连接成功',
      type: 'success',
    })
    console.log("网路链接失败")
    ElNotification({
      title: '异常',
      message: '网络已断开,等待重连',
      type: 'warning',
    })
  })
},10000)
},5000)
const writeResult=(res: ResultInfo)=>{
  // console.log(`收到设备回传结果:类型=${res.deviceType},结果=${res.result}`)
  ipcRenderer.invoke('logger', `收到设备回传结果:类型=${res.deviceType},结果=${res.result}`)
src/stores/sockteInfo.ts
@@ -42,6 +42,15 @@
    const isLink=ref(false) // sockte 链接状态
    const netLink=ref(true) // 网络链接状态
    const pcName=ref('')
     /**
      * 默认true,  判断是否有体重归零状态
      */
     const is测量准备=ref(true)
    // 温度
    const wendu=ref(0)
    const weightSockte=ref(weightInfo) // 体重秤sockte结果
@@ -117,8 +126,14 @@
    function setPcName(name:any){
        pcName.value=name
    }
    /**
     * 更新体重准备
     */
    function setis测量准备(value:boolean){
        is测量准备.value=value
    }
    return {isLink,netLink,weightSockte,xyjSockte,dkqSockte,wendu,faceInfoSockte,pcName,setsockteIsLink,setnetLink,setweightSockte,
    return {isLink,netLink,weightSockte,xyjSockte,dkqSockte,wendu,faceInfoSockte,pcName,is测量准备,setsockteIsLink,setnetLink,setweightSockte,
        setweightState,setPcName,setXtjState,setfaceSockte,setWendu,
        setxyjSockte,setdkqSockte}
        setxyjSockte,setdkqSockte,setis测量准备}
})
src/views/home/index.vue
@@ -290,6 +290,7 @@
import {initPort as M503} from '@/samples/deviceApi/M503'
import {initPort as seca102} from '@/samples/deviceApi/seca102'
import {initPort as seca101Banger} from '@/samples/deviceApi/seca101Banger'
import {initPort as liangjiang} from '@/samples/deviceApi/liangjiang'
// 引入模块
import config from '../../../package.json'
@@ -298,7 +299,7 @@
// 读取体重文件
import{todatatzs } from '@/samples/deviceApi/seca101'
import {ElMessage, UploadFile, UploadInstance, UploadProps } from 'element-plus'
import {ElMessage, ElNotification, UploadFile, UploadInstance, UploadProps } from 'element-plus'
const { proxy } = getCurrentInstance() as any;
// 人脸检测对象
const options = new SsdMobilenetv1Options({
@@ -312,7 +313,6 @@
const stream = ref(null) // 当前流
const getUserMediaFail = ref(false) // 获取用户媒体失败
let lsDateTime:any=new Date()
let imgSrc:'';
const msg = ref<string>("没识别到人脸...");
const datetext=computed(()=>{
  return  formatDate(new Date(),'YYYY-mm-dd  WWW')
@@ -341,12 +341,7 @@
const gao_ya=ref("")//高压
const di_ya=ref("")//低压
const  mai_bu=ref("")//脉搏,
const tupianpath=ref('') //验证图片地址
const centerDialogVisible=ref(false)
const uploadRef = ref<UploadInstance>()
const fileList=ref([])
const imageUrl = ref('')
const dialogImageUrl = ref('')
// 打开图片验证
const yanzhengTUpian=()=>{
  
@@ -386,7 +381,13 @@
  if(!netLink.value){
    ElMessage.success('网络已经连接')
  }else{
    ElMessage.warning('网络已断开,等待重连')
    // ElNotification({
    //   title: '异常',
    //   message: '网络已断开,等待重连',
    //   type: 'warning',
    //   duration:10000
    // })
    // ElMessage.warning('网络已断开,等待重连')
  }
})
@@ -467,10 +468,11 @@
  }
  if (isUseFaceRecogService.value) {
    console.log('开启人脸识别')
    lsDateTime=new Date()
    dialogVisible.value = true
  }else{
    console.log('关闭人脸识别')
    dialogVisible.value = true
    dialogVisible.value = false
  }
}
@@ -745,7 +747,7 @@
  () => weightInfo.value.resultTime,
  async () => {
    const X= jgTime(timer,new Date())
    console.log(X,'收到体重',configData.value.BobaoJg)
    // console.log(X,'收到体重',configData.value.BobaoJg)
    // 体重不能0
    if (weightInfo.value.result !== "0"&&patientInfo.value.code!=='') {
        ipcRenderer.invoke('logger', `体重变化了:${weightInfo.value.result}`)
@@ -844,6 +846,12 @@
  updatePatient(mode).then(re=>{
    ElMessage.success('结果发送成功')
    ipcRenderer.invoke('logger', '结果上传成功')
    // 测量结果发送成功后就一定要体重秤归零才行  关闭体重秤归零状态为false
    // 只增对M503
    if(configData.value.tzc_type==='M503'||configData.value.tzc_type==='seca101Banger'){
      console.log('发送清理体重归零')
      sockteStore().setis测量准备(false)
    }
    clockNum.value = Number(configData.value.timeJg/1000)
    return false
  }).catch(re=>{
@@ -876,16 +884,17 @@
    ipcRenderer.invoke('logger', '结果上传成功')
    // 倒计时结果显示
    clockNum.value = Number(configData.value.timeJg/1000)
    return false
  }).catch(re=>{
    ElMessage('结果发送失败')
    console.log('结果发送失败')
    ipcRenderer.invoke('logger', `结果发送失败:第${fasongNum.value}次,3秒后重新发送`)
    ipcRenderer.invoke('logger', `结果发送失败:第${fasongNum.value}次,2秒后重新发送`)
    if(fasongNum.value<3){
      setTimeout(sundModeXyj,5000);
      setTimeout(sundModeXyj,2000);
    }
    else{
      ipcRenderer.invoke('logger', '3次结果上传都失败放弃本次请求')
      ipcRenderer.invoke('logger', '2次结果上传都失败放弃本次请求')
      return false
    }
  })
@@ -946,8 +955,8 @@
  }
}
const updateChengxu=()=>{
  console.log('检查更新')
  if(configData.value.isLanFace===true){
  console.log('检查更新',)
  if(configData.value.isLanFace===true||sockteStore().isLink){
    console.log('是内网不能检查更新')
  }else{
    ipcRenderer.invoke("check-update");
@@ -999,11 +1008,10 @@
        M503(configData.value.tzcPortPath,configData.value.tzcBaudRate)
      }else if(configData.value.tzc_type==='seca102'){
        seca102(configData.value.tzcPortPath,configData.value.tzcBaudRate)
      }
      // seca101读取文件
      else if(configData.value.tzc_type==='seca101'){
        console.log('体重是读取文件')
      else if(configData.value.tzc_type==='seca101Banger'){
        seca101Banger(configData.value.tzcPortPath,configData.value.tzcBaudRate)
      }// 耀华XK3190-A12 
      else if(configData.value.tzc_type==='XK3190-A12'){
        XK3190A12(configData.value.tzcPortPath,configData.value.tzcBaudRate)
@@ -1078,7 +1086,7 @@
    speech.value = new Speech();
    speech.value?.setLanguage('zh-CN')
    speech.value?.init().then(() => {
      console.log('语音初始化成功')
      console.log('加载人脸采集模型成功')
    })
  },8000)
})
@@ -1110,7 +1118,6 @@
  draw.drawDetections(canvas.value, resizedResult.box);
  drawBox(box, '')
  // video.value.pause()
  // //截取人脸图片
  const image = await cameraShoot(
    video.value,
@@ -1125,7 +1132,10 @@
    return detectFace()
  }
  const X= jgTime(lsDateTime,new Date())
  if(dialogVisible.value&&X>configData.value.face_push&&isworkTime(new Date())){
  //人脸上传到阿里云
  // 只有是结果归零状态才能进行识别
  console.log(`检查人脸是否要上传到阿里云识别:${sockteStore().is测量准备}`)
  if(dialogVisible.value&&X>configData.value.face_push&&isworkTime(new Date())&&sockteStore().is测量准备){
    lsDateTime=new Date()
    // console.log(X,'上传图片间隔')
    base64toFile(image)