// 6.诊之助 TM2655VP
|
import { ElMessage } from 'element-plus'
|
const { SerialPort } = require('serialport')
|
const { DelimiterParser } = require('@serialport/parser-delimiter')
|
const { ByteLengthParser } = require('@serialport/parser-byte-length')
|
import {sockteStore} from '@/stores/sockteInfo'
|
|
|
const initPort=(path:String,baudRate:Number)=>{
|
console.log('初始化打开诊之助 TM2655VP端口')
|
const serialport = new SerialPort({ path, baudRate }, (err: any) => {
|
if (err) {
|
console.log(err)
|
ElMessage({
|
message: '诊之助 TM2655VP端口打开失败!',
|
type: 'error',
|
})
|
console.log(err)
|
}else{
|
ElMessage({
|
message: '诊之助 TM2655VP端口打开成功',
|
type: 'success',
|
})
|
}
|
})
|
serialport.on("close",(err: any)=>{
|
console.log('诊之助 TM2655VP端口异常端口链接断开')
|
console.log(err)
|
})
|
// 解析分割数据流
|
const parser = serialport.pipe(new ByteLengthParser({ length: 32*2 }))
|
parser.on('data', (value: string | any[])=>{
|
console.log(value.toString())
|
const str=value.toString()
|
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:'TM2655VP',
|
type:"血压计",
|
result:str.substring(34,37)+','+str.substring(44,47)+','+str.substring(49,52),
|
resultTime:new Date().toString(),
|
state:2
|
}
|
)
|
}
|
|
})
|
}
|
|
export {
|
initPort,
|
}
|