// #ifdef APP import ecUI from '@/utils/ecUI.js' import ecBLE from '@/utils/ecBLE/ecBLE.js' // #endif // #ifdef MP const ecUI = require('@/utils/ecUI.js') const ecBLE = require('@/utils/ecBLE/ecBLE.js') // #endif export function hexToString(hex) { var tmp = ''; if(hex < 0) { hex=hex+256; } tmp = hex.toString(16) tmp = tmp.padStart(2, '0') return tmp } export function send_uart(id,cc,icode,len,msg) { var code='' var send_data=[],send_stringdata='',send_length=0; if(cc == '08') { send_length = 18 } else if(cc == '8f') { send_length = len+12; } else{ send_length = len+14; } send_data[0]='68'; send_data[7]='68'; for(var i=0 ; i<6; i ++) { send_data[6-i] = id.substr(2*i,2); } //获取控制码 send_data[8]=cc; var i1,i2,i3,i4 if(cc == '08'||cc == '8f') { //获取长度 send_data[9]=hexToString(len); //获取时钟 ss mm hh dd mm yy+33H for(var i1=0 ; i1 { ecBLE.onBLECharacteristicValueChange((str, strHex) => { recv_uart(strHex) console.log('设备回复:'+strHex); resolve(getApp().globalData.uart_645datalink) }) }) } //串口接收解析 export function recv_uart(rec) { var uart_645datalink={ id:'', cc:'', len:'', icode:'', data:[], uart_recvflag: 0,//接收正确645协议 0:未收到正确报文 1:收到正确报文 } var recv_data=[],recv_length=0 //去除fe,获得完整645协议报文 var start = rec.indexOf('68') recv_length = rec.length/2; rec = rec.slice(start,rec.length) recv_length = rec.length/2; uart_645datalink.text = rec if(recv_length > 0) { //获取645报文,按照字节存储到数组 for(var i=0 ; i=2) { //获取标识编码 uart_645datalink.icode = hexToString(parseInt(recv_data[11],16)-51)+hexToString(parseInt(recv_data[10],16)-51); //获取数据 for(var k=0;k