chenyc
2024-07-11 b7b73d339a42d09ecc3f0115c49e23dc46893d5e
src/samples/deviceApi/M503.ts
@@ -1,4 +1,3 @@
// 欧姆龙 HBP-9030 115200
import { ElMessage } from 'element-plus'
const { SerialPort } = require('serialport')
const { DelimiterParser } = require('@serialport/parser-delimiter')
@@ -30,9 +29,10 @@
    //ST,GS 70.4kg
    //
    //
    //53 54 2C 47 53 20 20 20 20 20 30 2E 30 6B 67 0D 0A
    //
    //
    //
    // 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
    // 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[])=>{
@@ -40,19 +40,24 @@
        const str=value.toString()
        const list=str.split(' ')
        console.log(list)
        if(list.length===5&&list[0].search('ST,GS')!==-1){
            const re=list[4].trim()
        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,'获取到的体重')
            sockteStore().setweightSockte(
                {
                    deviceName:'台衡M503',
                    type:"体重秤",
                    result:res,
                    resultTime:new Date().toString(),
                    state:2
                }
            )
            if(Number(res)>=20){
                sockteStore().setweightSockte(
                    {
                        deviceName:'台衡M503',
                        type:"体重秤",
                        result:res,
                        resultTime:new Date().toString(),
                        state:2
                    }
                )
            }else{
                console.log('体重小于30KG')
            }
        }else{
            console.log('数据格式不对')
        }