From c4315986bc6ff814b0d8975699d9e89ab75961a2 Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期五, 13 十月 2023 10:19:35 +0800
Subject: [PATCH] 更新体重秤通讯
---
imgs/1697008903330.png | 0
src/samples/deviceApi/taiHengM523.ts | 64 ++++++++++++++++
src/views/home/index.vue | 52 ++++++++++--
src/samples/sockteStomp.ts | 2
src/stores/StoresConfing.ts | 5 +
package.json | 2
electron/main/index.ts | 2
src/samples/deviceApi/seca101.ts | 100 +++++++++++++++++++++++++
8 files changed, 214 insertions(+), 13 deletions(-)
diff --git a/electron/main/index.ts b/electron/main/index.ts
index 771a6e6..ba603bc 100644
--- a/electron/main/index.ts
+++ b/electron/main/index.ts
@@ -65,7 +65,7 @@
win = new BrowserWindow({
title: 'Main window',
transparent: true,
- frame:store.get('debug'),//关闭菜单栏
+ frame:store.get('debug')===undefined?true:store.get('debug'),//关闭菜单栏
fullscreen: true,// 开启默认全屏
kiosk: true,
// autoHideMenuBar:store.get('debug'),
diff --git a/imgs/1697008903330.png b/imgs/1697008903330.png
new file mode 100644
index 0000000..616bc83
--- /dev/null
+++ b/imgs/1697008903330.png
Binary files differ
diff --git a/package.json b/package.json
index 064dbab..92e76f9 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "sign-tool",
- "version": "2.7.0",
+ "version": "2.7.1",
"icon": "public/favicon.ico",
"main": "dist/electron/main/index.js",
"author": "",
diff --git a/src/samples/deviceApi/seca101.ts b/src/samples/deviceApi/seca101.ts
new file mode 100644
index 0000000..21aa385
--- /dev/null
+++ b/src/samples/deviceApi/seca101.ts
@@ -0,0 +1,100 @@
+// 体重秤读取文件夹模式通讯
+const fs = require('fs');
+const fspre = require('fs/promises');
+const path = require("path");
+import {sockteStore} from '@/stores/sockteInfo'
+import { confingInfoStore } from '@/stores/StoresConfing'
+async function toDataTz(filepath:string) {
+ try {
+ const data = await fspre.readFile(filepath, { encoding: 'utf8' });
+ // console.log('读取文件类容')
+ // console.log(data);
+ const list=data.split('kg')
+ if(list.length===2){
+ const tztext= list[0].substring(list[0].length-7,list[0].length-2)
+ // 替换,当.
+ const res= tztext.replace(",",".")
+ console.log(res)
+ sockteStore().setweightSockte(
+ {
+ deviceName:'seca101',
+ type:"体重秤",
+ result:res,
+ resultTime:new Date().toString(),
+ state:2
+ }
+ )
+ delImg(filepath)
+ }
+ } catch (err) {
+ console.log(err);
+ }
+ }
+const todatatzs= async (dateStr:string)=>{
+ try {
+ // const pathName='D:/seca101/data'
+ const pathName = confingInfoStore().confingInfo.seca101Path
+ fs.readdir(pathName, function(err: any, files: string | any[]){
+ var dirs: any[] = [];
+ (function iterator(i){
+ if(i == files.length) {
+ var maxtime = 0;
+ var maxfileName = '';
+ for(var j = 0;j<dirs.length;j++){
+ var stat = fs.statSync(path.join(pathName,dirs[j]));
+ console.log(stat)
+ console.log(stat.birthtime)
+ var fileCreateTimeStamp = (new Date(stat.birthtime)).getTime();
+ if(fileCreateTimeStamp>maxtime){
+ maxtime = fileCreateTimeStamp;
+ maxfileName=dirs[j];
+ }
+ }
+ // console.log('最终文件',maxfileName);
+ // 最新的文件路径
+ const param=path.join(pathName,maxfileName)
+
+ // console.log(dateStr,'人年识别时间')
+ var date1 = fs.statSync(param);
+ // const date2=date1.birthtime
+ // console.log('最终文件绝对路径',param);
+ //判断时间要大于人脸识别的时间
+ // console.log(date1.birthtime,'体重写入时间')
+ const times1 = (new Date(date1.birthtime)).getTime();
+ const times2=(new Date(dateStr)).getTime()
+ if(times1>times2){
+ toDataTz(param)
+ }else{
+ console.log(date1,dateStr)
+ delImg(param)
+ console.log('体重时间没有大于人脸识别时间')
+ }
+ return;
+ }
+ fs.stat(path.join(pathName, files[i]), function(err: any, data: { isFile: () => any; }){
+ if(data.isFile()){
+ dirs.push(files[i]);
+ }
+ iterator(i+1);
+ });
+ })(0);
+ })
+ }
+ catch(err){
+ console.log(err);
+ }
+}
+//验证后删除文件图片
+const delImg=(path:string)=>{
+ fs.unlink(path,(err:any)=>{
+ if(err){
+ console.log('删除失败')
+ }else{
+ console.log('删除成功')
+ }
+ })
+ }
+export {
+ toDataTz,
+ todatatzs
+}
diff --git a/src/samples/deviceApi/taiHengM523.ts b/src/samples/deviceApi/taiHengM523.ts
new file mode 100644
index 0000000..2d1d02f
--- /dev/null
+++ b/src/samples/deviceApi/taiHengM523.ts
@@ -0,0 +1,64 @@
+// 欧姆龙 HBP-9030 115200
+import { ElMessage } from 'element-plus'
+const { SerialPort } = require('serialport')
+const { DelimiterParser } = require('@serialport/parser-delimiter')
+const { ReadyParser } = require('@serialport/parser-ready')
+import {sockteStore} from '@/stores/sockteInfo'
+
+const initPort=(path:String,baudRate:Number)=>{
+ console.log('初始化打开台衡M523体重秤端口')
+ const serialport = new SerialPort({ path, baudRate }, (err: any) => {
+ if (err) {
+ console.log(err)
+ ElMessage({
+ message: '台衡M523体重秤端口打开失败!',
+ type: 'error',
+ })
+ console.log(err)
+ }else{
+ ElMessage({
+ message: '台衡M523体重秤端口打开成功',
+ type: 'success',
+ })
+ }
+ })
+ serialport.on("close",(err: any)=>{
+ console.log('台衡M523体重秤端口异常端口链接断开')
+ console.log(err)
+ })
+ // 解析分割数据流
+ //ST,GS 70.4kg
+ //
+ //
+ //
+ //
+ //
+ // 53 54 2C 47 53 20 37 30 2E 34 6B 67 0D 0A HEX
+ const parser = serialport.pipe(new DelimiterParser({ delimiter:Buffer.from([107,103,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)
+ if(list.length===2&&list[0].search('ST,GS')!==-1){
+ const re=list[1].trim()
+ const res=re.substring(0,re.length-2)
+ console.log(res,'获取到的体重')
+ sockteStore().setweightSockte(
+ {
+ deviceName:'台衡M523',
+ type:"体重秤",
+ result:res,
+ resultTime:new Date().toString(),
+ state:2
+ }
+ )
+ }else{
+ console.log('数据格式不对')
+ }
+ }) // all data after READY is received
+}
+
+export {
+ initPort,
+}
diff --git a/src/samples/sockteStomp.ts b/src/samples/sockteStomp.ts
index 63189f3..5f6a3f9 100644
--- a/src/samples/sockteStomp.ts
+++ b/src/samples/sockteStomp.ts
@@ -78,7 +78,7 @@
}
const writePatient=(resultInfo:any)=>{
// 给一个时间变化
- const da=new Date().toTimeString()
+ const da=new Date()
console.log(da)
const info={
id:resultInfo.patientInfo===null?0:resultInfo.patientInfo.id,
diff --git a/src/stores/StoresConfing.ts b/src/stores/StoresConfing.ts
index 09f71de..a0d2e8b 100644
--- a/src/stores/StoresConfing.ts
+++ b/src/stores/StoresConfing.ts
@@ -17,8 +17,11 @@
xueyanjiPortPath:"COM35",
xueyanjiBaudRate:115200,
Is_tzc:false,
+ // 志荣的[zhiRongT605];台衡的M523[taiHengM523] //[s]eca101]读文件夹
+ tzc_type:"seca101",
tzcPortPath:"COM34",
- tzcBaudRate:1200
+ tzcBaudRate:120,// zhiRongT605波特率1200;台衡523波特率9600
+ seca101Path:"D:/seca101/data/"// 文件获取目录
})
/**
diff --git a/src/views/home/index.vue b/src/views/home/index.vue
index 992881b..e102b5f 100644
--- a/src/views/home/index.vue
+++ b/src/views/home/index.vue
@@ -201,9 +201,9 @@
</div>
</div>
</div>
- <el-dialog title="提示" v-model="netLink" width="30%">
+ <!-- <el-dialog title="提示" v-model="netLink" width="30%">
<span>无法链接到网络!</span>
- </el-dialog>
+ </el-dialog> -->
</div>
</template>
<script setup lang="ts">
@@ -222,7 +222,9 @@
import{initPort} from '@/samples/portApi'
import{initPort as oumulongHbp9030 } from '@/samples/deviceApi/oumulong-HBP-9030'
import{initPort as zhiRongT605 } from '@/samples/deviceApi/zhiRongT605'
-
+import{initPort as taiHengM523 } from '@/samples/deviceApi/taiHengM523'
+// 读取体重文件
+import{toDataTz,todatatzs } from '@/samples/deviceApi/seca101'
import { ElLoading, ElMessage } from 'element-plus'
let trackerTask: any = null;
// 标识用的画布
@@ -315,8 +317,16 @@
ipcRenderer.invoke('logger', '网络已经断开')
}else{
ipcRenderer.invoke('logger', '网络已经恢复')
+
}
return !sockte.netLink
+})
+watch(netLink,()=>{
+ if(!netLink.value){
+ ElMessage.success('网络已经连接')
+ }else{
+ ElMessage.warning('网络已断开,等待重连')
+ }
})
// 体重
@@ -421,6 +431,7 @@
dialogVisible.value = false
speech.value?.speak({ text: str }).then(() => {
})
+
sockteStore().setweightSockte({
type: "体重秤",
state: 2,
@@ -435,6 +446,9 @@
result: "",
resultTime: ""
})
+
+
+
}
// 没有找到患者
@@ -492,7 +506,7 @@
settime()
// 定时数秒器
const tt = mode.weight.replace('.', '点')
- speech.value?.speak({ text: `称重完成,${tt}kg` }).then(() => {
+ speech.value?.speak({ text: `称重完成,${tt}千克` }).then(() => {
console.log("播报完成...")
})
patientCodeLs = mode.patientCode
@@ -650,7 +664,7 @@
sendPationCodeApi(inputCode.value)
setTimeout(function () {
inputCode.value = ''
- }, 1000)
+ }, 5000)
}
// 点击10下关闭程序
const guyanbi = () => {
@@ -660,9 +674,9 @@
}
}
onMounted(() => {
+ console.log(0%5)
console.log('页面初始化', os.hostname())
setTimeout(()=>{
-
console.log('8秒后执行')
console.log('打印设置文件')
console.log(configData.value)
@@ -676,7 +690,17 @@
}
// 是否开启志荣体重秤联机
if(configData.value.Is_tzc){
- zhiRongT605(configData.value.tzcPortPath,configData.value.tzcBaudRate)
+ //台衡M523
+ if(configData.value.tzc_type==='taiHengM523'){
+ taiHengM523(configData.value.tzcPortPath,configData.value.tzcBaudRate)
+ }
+ // seca101读取文件
+ else if(configData.value.tzc_type==='seca101'){
+ console.log('体重是读取文件')
+ }
+ else{
+ zhiRongT605(configData.value.tzcPortPath,configData.value.tzcBaudRate)
+ }
}
// 是否开启脸识别
isUseFaceRecogService.value = configData.value.isUseFaceRecogService
@@ -693,10 +717,9 @@
setInterval(function () {
clockNum.value--
if(clockNum.value===0){
-
fuxuan()
}
- inputRef.value.focus();
+
date.value=formatDate(new Date(),'YYYY-mm-dd HH:MM')
if(Number(date.value.substring(11,13))<12){
timeShidaun.value='上午好!'
@@ -705,6 +728,17 @@
}else {
timeShidaun.value='晚上好!'
}
+ //5秒一次验证读取体重数据
+ console.log(clockNum.value,clockNum.value%5==0)
+ if(clockNum.value%3==0){
+ // 验证人脸识别已经通过但是还没有体重数据主动获取数据
+ if(patientInfo.value.name!==''&&weightInfo.value.result==='0'){
+ console.log('主动获取体重')
+ todatatzs(patientInfo.value.datetime)
+ }
+ }
+ inputRef.value.focus();
+
}, 1000)
speech.value = new Speech();
speech.value?.setLanguage('zh-CN')
--
Gitblit v1.8.0