Files
endo_an/utils/cmd.js
T
2026-02-10 09:56:08 +08:00

167 lines
5.6 KiB
JavaScript

// 接收数据
// 压差站号:01,温湿度站号:02
// 压差 01 03 02 12 34 B5 33
// 温湿度 01 03 04 02 98 00 BC 7B D5
// IC卡 20 01 00 08 04 00 00 00 0e 26 fe ab 8f 03
// ID卡 20 01 00 05 49 00 b5 6a b5 d8 03
// 卡离开 20 01 00 01 02 fd 03
// 卡片放入和离开 起始位20, 第二位是地址0人员卡,1-16内镜卡
// let RS232 = getApp().globalData.RS232
import store from '@/store/index.js'
export default {
// 开门关门控制 01
Door: async (status) => {
let op = status ? '01' : '00'
let cmd = '5AA5EE01' + op
store.state.relay.door = status
let RS232 = getApp().globalData.RS232
await RS232.sendDataString(cmd);
},
// 开风机指令 02
Wind: async (status) => {
let op = status ? '01' : '00'
let cmd = '5AA5EE02' + op
store.state.relay.wind = status
let RS232 = getApp().globalData.RS232
await RS232.sendDataString(cmd);
},
// 开灯指令 03
Light: async (status) => {
let op = status ? '01' : '00'
let cmd = '5AA5EE03' + op
store.state.relay.light = status
let RS232 = getApp().globalData.RS232
await RS232.sendDataString(cmd);
},
// 开真空指令 04
Vacuum: async (status) => {
let op = status ? '01' : '00'
let cmd = '5AA5EE04' + op
store.state.relay.vacuum = status
let RS232 = getApp().globalData.RS232
await RS232.sendDataString(cmd);
},
// 开关消毒指令 05
Disinfect: async (status) => {
let op = status ? '01' : '00'
let cmd = '5AA5EE05' + op
store.state.relay.disinfect = status
let RS232 = getApp().globalData.RS232
await RS232.sendDataString(cmd);
},
// 获取温湿度
getTemp: () => {
let RS485 = getApp().globalData.RS485
let cmd = '020300000002C438';
RS485.sendDataString(cmd);
},
// 获取压差指令
getPressure: () => {
let RS485 = getApp().globalData.RS485
let cmd = '01030001000295CB'
RS485.sendDataString(cmd);
},
// 解析门卡数据,返回卡号
parse232dData: (hexString) => {
// IC卡 20 01 00 08 04 00 00 00 0e 26 fe ab 8f 03
// ID卡 20 01 00 05 49 00 b5 6a b5 d8 03
// 卡离开 20 01 00 01 02 fd 03
// 01 地址, 04 00 卡类型,0e 26 fe ab 卡号,8f 校验 03固定值
// 人员卡地址号0,卡号4个字节,倒数4个字节,倒数一位03固定值,倒数二位校验
// 内镜卡地址号1-16,卡号4个字节,倒数4个字节,倒数一位03固定值,倒数二位校验
// 卡离开8位,卡进入11位和14位
// 移除空格和换行符
const hexStr = hexString.replace(/\s+/g, '');
// 验证输入
if (hexStr.length === 0) {
throw new Error('请输入Modbus十六进制数据');
}
if (hexStr.length % 2 !== 0) {
throw new Error('请输入有效的Modbus十六进制数据');
}
// 解析后的数据对象
let data = {};
// 刷卡数据 起始字节20,第二字节站号,结束字节03
if (hexStr.substr(0, 2) == '20' && hexStr.substr(hexStr.length - 2, 2) == '03') {
// 卡数据
let hexNum = hexStr.substr(hexStr.length - 12, 8)
// 第二位是地址
let addHex = hexStr.substr(2, 2)
// 转换成10进制地址号
let address = parseInt(addHex, 16)
// 解析后的数据 { address: 0, number: 12345678, cardType: 'ic', action: 'enter', type: 'person' }
data.address = address
if (hexStr.length == 28) {
// 14字节是IC卡号
let icNo = parseInt(hexNum, 16)
data.number = icNo
data.cardType = 'ic'
data.action = 'enter'
}
if (hexStr.length == 22) {
// 11字节是ID卡号
let idNo = parseInt(hexNum, 16)
data.number = idNo
data.cardType = 'id'
data.action = 'enter'
}
if (hexStr.length == 14) {
// 7字节是卡离开
data.action = 'leave'
}
if (address == 0) {
// 人员卡
data.type = 'person'
}
if (address >= 1 && address <= 16) {
// 内镜卡
data.type = 'internal'
}
}
// 关门上报指令
if (hexStr.toUpperCase() == '5AA50000000000FF') {
// 开门数据 8个字节
data.action = 'door'
}
return data
},
parse485Data: (hexString) => {
// 移除空格和换行符
const hexStr = hexString.replace(/\s+/g, '');
// 压差站号:01,温湿度站号:02
let addHex = hexStr.substr(0, 2)
let data = {}
if (hexStr.length == 14 || hexStr.length == 18) {
if (addHex == '01') {
let pressure = parseInt(hexStr.substr(6, 4), 16);
data.pressure = pressure / 10
}
if (addHex == '02') {
let humi = parseInt(hexStr.substr(6, 4), 16);
let temp = parseInt(hexStr.substr(10, 4), 16);
// 温湿度上报数据异常处理,取正常温湿度范围内数据
temp = (temp / 10).toFixed(1)
if (temp >= 0 && temp < 100) {
data.temp = temp
}
humi = (humi / 10).toFixed(1)
if (humi >= 0 && humi < 100) {
data.humi = humi
}
}
}
// console.log('parse485Data:',hexStr, data)
return data
},
}