From e971a9cf298121d20e6b188e8f19adcb225a6ab9 Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期五, 29 十一月 2024 12:25:29 +0800
Subject: [PATCH] 更新通讯

---
 src/views/home/index.vue                |   15 +++-
 src/samples/deviceApi/zhiRongShantou.ts |  152 ++++++++++++++++++++++++++++++++++++++++++++++++++
 imgs/1732850057688.png                  |    0 
 imgs/1732850063439.png                  |    0 
 4 files changed, 162 insertions(+), 5 deletions(-)

diff --git a/imgs/1732850057688.png b/imgs/1732850057688.png
new file mode 100644
index 0000000..743d735
--- /dev/null
+++ b/imgs/1732850057688.png
Binary files differ
diff --git a/imgs/1732850063439.png b/imgs/1732850063439.png
new file mode 100644
index 0000000..6647f48
--- /dev/null
+++ b/imgs/1732850063439.png
Binary files differ
diff --git a/src/samples/deviceApi/zhiRongShantou.ts b/src/samples/deviceApi/zhiRongShantou.ts
new file mode 100644
index 0000000..a7db9f0
--- /dev/null
+++ b/src/samples/deviceApi/zhiRongShantou.ts
@@ -0,0 +1,152 @@
+// 汕头悦康  波特率2400 
+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'
+
+// 设置重连间隔和最大重试次数
+const RECONNECT_INTERVAL = 10000; // 重连间隔10秒
+const MAX_RECONNECT_ATTEMPTS = 10; // 最大重试次数10次
+ 
+let reconnectAttempts = 0; // 当前重试次数
+let serialPort:any; // 串口实例
+   
+const initPort=(path:String,baudRate:Number)=>{
+    console.log('初始化打开汕头粤康体重秤端口',reconnectAttempts)
+    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 {
+        let lisijieguo=''
+        let duibinum=0
+        serialPort  = new SerialPort({ path, baudRate }, (err: any) => {
+            reconnectAttempts++
+            if (err) {
+                console.log(err)
+                ipcRenderer.invoke('logger', '汕头粤康体重秤端口打开失败!')
+                ElMessage({
+                    message: '汕头粤康体重秤端口打开失败!',
+                    type: 'error',
+                })
+                setTimeout(()=>{
+                    initPort(path,baudRate)
+                }, RECONNECT_INTERVAL);
+            }else{
+                reconnectAttempts=0
+                ipcRenderer.invoke('logger', '汕头粤康体重秤端口打开成功')
+                ElMessage({
+                    message: '汕头粤康体重秤端口打开成功',
+                    type: 'success',
+                })
+            } 
+        })
+        serialPort.on("close",(err: any)=>{
+            ipcRenderer.invoke('logger', '汕头粤康体重秤端口异常端口链接关闭')
+            console.log('汕头粤康体重秤端口异常端口链接断开')
+            reconnectAttempts=0
+            setTimeout(()=>{
+                initPort(path,baudRate)
+            }, RECONNECT_INTERVAL);
+            console.log(err)
+        })
+        // 解析分割数据流
+        //
+        //  2400
+        //
+        //
+        //=0.0000  
+        // =6.9600
+        // 3D 30 2E 30 30 30 30 20    
+        // 3D 35 2E 39 36 30 30 20
+        const parser = serialPort.pipe(new DelimiterParser({ delimiter:Buffer.from([32]),includeDelimiter:true }))
+        parser.on('data', (value: string | any[])=>{
+            
+            const str=value.toString()
+            console.log(str)
+
+            const ss=str.split('').reverse().join('');
+            console.log(ss.substring(0,ss.length-1))
+            const list=ss.substring(0,ss.length-1)
+            const res=ss.substring(0,ss.length-1)
+            console.log(Number(res))
+            if(list!=='000000'){
+                if(list===lisijieguo){
+                    duibinum++
+                }else{
+                    lisijieguo=list
+                    duibinum=0
+                }
+                // 对比4次结果都一致
+                if(duibinum>=3){
+                    console.log(list,'获取到的体重')
+                    sockteStore().setweightSockte(
+                        {
+                            deviceName:'汕头粤康',
+                            type:"体重秤",
+                            result:Number(res).toString(),
+                            resultTime:new Date().toString(),
+                            state:2
+                        }
+                    )
+                    duibinum=0
+                    lisijieguo=''
+                }else{
+    
+                }
+                
+            }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,
+}
diff --git a/src/views/home/index.vue b/src/views/home/index.vue
index e6fd31a..f5da880 100644
--- a/src/views/home/index.vue
+++ b/src/views/home/index.vue
@@ -54,7 +54,7 @@
                         <div style="display: grid;grid-template-columns: minmax(250px, 40%) 1fr; height: 100%; padding-left: 20px;padding-top: 20px;">
                             <!-- 头像 -->
                             <div  :style="{backgroundImage:`url(${patientInfo.patientAvatarIcon})`}" style="background-size:100% 100%;height: 100%;" >
-                              <div style="width:140px; height: 50px; line-height: 50px; font-size: 25px; background: #D09200;color: #FFFFFF; font-weight: 500; text-align: center; border-radius: 0px 8px 0px 30px; float: right;">
+                              <div style="width:140px; height: 50px; line-height: 50px; font-size: 25px; background: #9F61DC;color: #FFFFFF; font-weight: 500; text-align: center; border-radius: 0px 8px 0px 30px; float: right;">
                                 {{patientInfo.name}}
                               </div>
                             </div>
@@ -75,7 +75,7 @@
                 <div style="height: 31%; margin-top: 20px;border-radius: 12px;" >
                     <el-row style="height: 100%;background:rgba(246, 244, 244, 0.3);border-radius: 12px;opacity: 0.9;">
                         <el-col :span="8">
-                            <div class="textwenben" style="height: 28%; font-size: 25px;background-color: #D09200; border-radius: 12px 0 0 0;">
+                            <div class="textwenben" style="height: 28%; font-size: 25px;background-color: #9F61DC; border-radius: 12px 0 0 0;">
                               <template v-if="configData.deviceType==='体重秤'">
                                 <template v-if="patientInfo.isAfterMed===0&&!configData.gantiziShow">
                                   机号/床位号
@@ -91,7 +91,7 @@
                                 
                               </template>
                             </div>
-                            <div class="textwenben" style="height: 70%; font-size: 80px; color: #D09200;font-weight: 800;">
+                            <div class="textwenben" style="height: 70%; font-size: 80px; color: #9F61DC;font-weight: 1000;">
                               <template v-if="configData.deviceType==='体重秤'">
                                   <template v-if="patientInfo.isAfterMed===0&&!configData.gantiziShow">
                                     {{ patientInfo.deviceNo }}
@@ -129,12 +129,11 @@
                                 
                               </template>
                             </div>
-                            <div class="textwenben" style="height: 70%; font-size: 80px; color: #41B593; font-weight: 800;
+                            <div class="textwenben" style="height: 70%; font-size: 80px; color: #41B593; font-weight: 1000;
                               border-left: #FFFFFF solid 2px;border-right: #FFFFFF solid 2px;">
                                 <template v-if="configData.deviceType==='体重秤'">
                                   <template v-if="patientInfo.isAfterMed===0">
                                     {{patientInfo.lastTimeAfterWeight}}
-                                    99
                                   </template>
                                   <template v-else>{{tzjs}}</template>
                                     <!-- 体重减少(kg) -->
@@ -281,6 +280,7 @@
 import{initPort as  TM2655VP} from '@/samples/deviceApi/TM2655VP'
 import{initPort as zhiRongT605 } from '@/samples/deviceApi/zhiRongT605'
 import{initPort as zhiRongHehui } from '@/samples/deviceApi/zhiRongHehui'
+import{initPort as zhiRongShantou } from '@/samples/deviceApi/zhiRongShantou'
 import{initPort as taiHengM523 } from '@/samples/deviceApi/taiHengM523'
 import{initPort as XK3190A12 } from '@/samples/deviceApi/XK3190A12'
 import {initPort as mbp7000} from '@/samples/deviceApi/mbp7000'
@@ -294,6 +294,7 @@
 import {initPort as seca101Banger} from '@/samples/deviceApi/seca101Banger'
 import {initPort as liangjiang} from '@/samples/deviceApi/liangjiang'
 import {initPort as xinanguojiTZC} from '@/samples/deviceApi/xinanguojiTZC'
+
 
 // 引入模块
 import config from '../../../package.json'
@@ -1025,6 +1026,10 @@
       }else if(configData.value.tzc_type==='xinanguojiTZC'){
         xinanguojiTZC(configData.value.tzcPortPath,9600)
       }
+      // 志荣粤康  2400 
+      else if(configData.value.tzc_type==='zhiRongShantou'){
+        zhiRongShantou(configData.value.tzcPortPath,configData.value.tzcBaudRate)
+      }
       else{
         zhiRongT605(configData.value.tzcPortPath,configData.value.tzcBaudRate)
       }

--
Gitblit v1.8.0