| File was renamed from src/samples/deviceApi/yaoHua.ts |
| | |
| | | // 欧姆龙 HBP-9030 115200 |
| | | // 6.诊之助 TM2655VP |
| | | import { ElMessage } from 'element-plus' |
| | | const { SerialPort } = require('serialport') |
| | | const { DelimiterParser } = require('@serialport/parser-delimiter') |
| | |
| | | |
| | | |
| | | const initPort=(path:String,baudRate:Number)=>{ |
| | | console.log('初始化打开耀华体重秤端口') |
| | | console.log('初始化打开诊之助 TM2655VP端口') |
| | | const serialport = new SerialPort({ path, baudRate }, (err: any) => { |
| | | if (err) { |
| | | console.log(err) |
| | | ElMessage({ |
| | | message: '耀华体重秤端口打开失败!', |
| | | message: '诊之助 TM2655VP端口打开失败!', |
| | | type: 'error', |
| | | }) |
| | | console.log(err) |
| | | }else{ |
| | | ElMessage({ |
| | | message: '耀华体重秤端口打开成功', |
| | | message: '诊之助 TM2655VP端口打开成功', |
| | | type: 'success', |
| | | }) |
| | | } |
| | | }) |
| | | serialport.on("close",(err: any)=>{ |
| | | console.log('耀华体重秤端口异常端口链接断开') |
| | | console.log('诊之助 TM2655VP端口异常端口链接断开') |
| | | console.log(err) |
| | | }) |
| | | // 解析分割数据流 |
| | | const parser = serialport.pipe(new ByteLengthParser({ length: 14*4-1 })) |
| | | const parser = serialport.pipe(new ByteLengthParser({ length: 32*2 })) |
| | | parser.on('data', (value: string | any[])=>{ |
| | | console.log(value.toString()) |
| | | const str=value.toString() |
| | | const list=str.split(',') |
| | | console.log(list) |
| | | if(list.length===11){ |
| | | |
| | | console.log(str.length) |
| | | const re=str.substring(34,37)+','+str.substring(39,41)+','+str.substring(44,46) |
| | | console.log(re) |
| | | if(str.length>=11){ |
| | | sockteStore().setxyjSockte( |
| | | { |
| | | deviceName:'HBP-9030', |
| | | deviceName:'TM2655VP', |
| | | type:"血压计", |
| | | result:list[7]+','+list[8]+','+list[9], |
| | | result:str.substring(34,37)+','+str.substring(44,47)+','+str.substring(49,52), |
| | | resultTime:new Date().toString(), |
| | | state:2 |
| | | } |