This commit is contained in:
2026-06-02 15:18:26 +08:00
parent 05a72ac7dd
commit 67d64cc02d
4 changed files with 494 additions and 65 deletions
+32 -4
View File
@@ -172,6 +172,34 @@ const getRS485QueueSize = () => {
}
// ========== RS485 优先级消息队列 END ==========
// ========== RS232 超时保护 START ==========
// RS232波特率115200极快(~1ms/条),无需队列,仅需超时保护防止Promise永久pending
const RS232_SEND_TIMEOUT = 1000 // 发送超时1秒(对115200绰绰有余)
/**
* 带超时的RS232发送封装
* 防止底层串口驱动卡死导致Promise永久pending
*/
const sendRS232WithTimeout = (rs232Instance, cmd) => {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => {
console.warn(`[RS232] 发送超时(${RS232_SEND_TIMEOUT}ms), cmd: ${cmd}`)
reject(new Error('RS232发送超时'))
}, RS232_SEND_TIMEOUT)
const result = rs232Instance.sendDataString(cmd)
if (result && typeof result.then === 'function') {
result.then(res => { clearTimeout(timer); resolve(res) })
.catch(err => { clearTimeout(timer); reject(err) })
} else {
clearTimeout(timer)
resolve(result)
}
})
}
// ========== RS232 超时保护 END ==========
export default {
// 开左门指令 (通过RS485站号03) - 高优先级
// 中盛4路数字IO模块,功能码06(写单个保持寄存器)
@@ -211,7 +239,7 @@ export default {
let cmd = '5AA5EE02' + op
store.state.relay.wind = status
let RS232 = getApp().globalData.RS232
await RS232.sendDataString(cmd);
await sendRS232WithTimeout(RS232, cmd)
},
// 开灯指令 03
Light: async (status) => {
@@ -219,7 +247,7 @@ export default {
let cmd = '5AA5EE03' + op
store.state.relay.light = status
let RS232 = getApp().globalData.RS232
await RS232.sendDataString(cmd);
await sendRS232WithTimeout(RS232, cmd)
},
// 开真空指令 04
Vacuum: async (status) => {
@@ -227,7 +255,7 @@ export default {
let cmd = '5AA5EE04' + op
store.state.relay.vacuum = status
let RS232 = getApp().globalData.RS232
await RS232.sendDataString(cmd);
await sendRS232WithTimeout(RS232, cmd)
},
// 开关消毒指令 05
Disinfect: async (status) => {
@@ -235,7 +263,7 @@ export default {
let cmd = '5AA5EE05' + op
store.state.relay.disinfect = status
let RS232 = getApp().globalData.RS232
await RS232.sendDataString(cmd);
await sendRS232WithTimeout(RS232, cmd)
},
// 获取温湿度(通过RS485站号02)- 低优先级
getTemp: () => {