|
|
@ -70,22 +70,9 @@ public class Ox485 { |
|
|
|
void onError(String errorMessage); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 连接回调接口 |
|
|
|
*/ |
|
|
|
private interface ConnectionCallback { |
|
|
|
void onConnected(); |
|
|
|
void onError(String errorMessage); |
|
|
|
} |
|
|
|
|
|
|
|
private Ox485() { |
|
|
|
mainHandler = new Handler(Looper.getMainLooper()); |
|
|
|
timeoutHandler = new Handler(Looper.getMainLooper()); |
|
|
|
connectionCheckHandler = new Handler(Looper.getMainLooper()); |
|
|
|
serialPortManager = new SerialPortManager(); |
|
|
|
|
|
|
|
// 初始化连接检查任务 |
|
|
|
initConnectionCheckTask(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -134,12 +121,11 @@ public class Ox485 { |
|
|
|
|
|
|
|
/** |
|
|
|
* 通过485获取摄像头人数 |
|
|
|
* 对应uniapp中的sendHex485ForPeopleNum方法 |
|
|
|
* 采用懒加载连接管理,首次使用时才打开串口 |
|
|
|
* 采用即用即连模式:每次请求时打开连接,完成后立即关闭 |
|
|
|
* @param callback 结果回调 |
|
|
|
*/ |
|
|
|
public void sendHex485ForPeopleNum(PeopleNumCallback callback) { |
|
|
|
LogManager.logInfo(TAG, "15:45:22.734 Ox485 D 开始通过485获取摄像头人数(懒加载模式)"); |
|
|
|
LogManager.logInfo(TAG, "开始通过485获取摄像头人数(即用即连模式)"); |
|
|
|
|
|
|
|
if (!gateCamera485OxOn) { |
|
|
|
String errorMsg = "485模式未开启"; |
|
|
@ -151,22 +137,12 @@ public class Ox485 { |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
// 懒加载:检查连接状态,需要时才建立连接 |
|
|
|
ensureConnection(new ConnectionCallback() { |
|
|
|
@Override |
|
|
|
public void onConnected() { |
|
|
|
// 连接成功,发送命令 |
|
|
|
sendCommandAndWaitResponse(callback); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onError(String errorMessage) { |
|
|
|
// 连接失败 |
|
|
|
if (callback != null) { |
|
|
|
mainHandler.post(() -> callback.onError(errorMessage)); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
// 创建临时串口管理器 |
|
|
|
SerialPortManager serialPortManager = new SerialPortManager(); |
|
|
|
|
|
|
|
// 执行通信 |
|
|
|
sendCommandAndWaitResponse(serialPortManager, callback); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
String errorMsg = "485通信异常: " + e.getMessage(); |
|
|
|
LogManager.logError(TAG, errorMsg, e); |
|
|
@ -177,23 +153,11 @@ public class Ox485 { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 发送命令并等待响应(采用懒加载连接复用) |
|
|
|
* 发送命令并等待响应(采用即用即连模式) |
|
|
|
* @param serialPortManager 串口管理器实例 |
|
|
|
* @param callback 结果回调 |
|
|
|
*/ |
|
|
|
private void sendCommandAndWaitResponse(PeopleNumCallback callback) { |
|
|
|
// 发送前检查串口状态 |
|
|
|
if (!isSerialPortReallyOpen()) { |
|
|
|
String errorMsg = "串口未打开,无法发送命令"; |
|
|
|
LogManager.logError(TAG, errorMsg); |
|
|
|
isSerialPortOpen = false; |
|
|
|
if (callback != null) { |
|
|
|
mainHandler.post(() -> callback.onError(errorMsg)); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
LogManager.logInfo(TAG, "485串口状态检查通过,开始发送命令"); |
|
|
|
|
|
|
|
private void sendCommandAndWaitResponse(SerialPortManager serialPortManager, PeopleNumCallback callback) { |
|
|
|
// 设置数据监听器 |
|
|
|
serialPortManager.setOnSerialPortDataListener(new OnSerialPortDataListener() { |
|
|
|
@Override |
|
|
@ -207,25 +171,28 @@ public class Ox485 { |
|
|
|
// 数据包过滤:只处理以[15, 3, 4, 0]开头的正常响应数据包 |
|
|
|
if (!isNormalResponsePacket(bytes)) { |
|
|
|
LogManager.logInfo(TAG, "Ox485接收到非正常响应数据包,已过滤: " + hexData + ", 期望格式: [15, 3, 4, 0]"); |
|
|
|
// 即用即连模式下,收到任何数据都关闭连接 |
|
|
|
closeAndCleanup(serialPortManager); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 取消超时处理 |
|
|
|
cancelTimeout(); |
|
|
|
|
|
|
|
// 标记成功通信(用于连接健康检查) |
|
|
|
markSuccessfulCommunication(); |
|
|
|
|
|
|
|
// 解析人数数据 |
|
|
|
int peopleNum = get485PeopleNum(bytes); |
|
|
|
if (peopleNum >= 0) { |
|
|
|
LogManager.logInfo(TAG, "485获取人数成功: " + peopleNum); |
|
|
|
// 完成后关闭连接 |
|
|
|
closeAndCleanup(serialPortManager); |
|
|
|
if (callback != null) { |
|
|
|
mainHandler.post(() -> callback.onSuccess(peopleNum)); |
|
|
|
} |
|
|
|
} else { |
|
|
|
String errorMsg = "485数据解析失败,数据: " + hexData; |
|
|
|
LogManager.logError(TAG, errorMsg); |
|
|
|
// 完成后关闭连接 |
|
|
|
closeAndCleanup(serialPortManager); |
|
|
|
if (callback != null) { |
|
|
|
mainHandler.post(() -> callback.onError(errorMsg)); |
|
|
|
} |
|
|
@ -239,8 +206,39 @@ public class Ox485 { |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// 发送HEX命令 |
|
|
|
// 打开串口并发送HEX命令 |
|
|
|
try { |
|
|
|
File serialPortFile = new File(DEFAULT_SERIAL_PORT_PATH); |
|
|
|
|
|
|
|
// 检查串口文件是否存在 |
|
|
|
if (!serialPortFile.exists()) { |
|
|
|
String errorMsg = "485串口设备文件不存在: " + DEFAULT_SERIAL_PORT_PATH; |
|
|
|
LogManager.logError(TAG, errorMsg); |
|
|
|
closeAndCleanup(serialPortManager); |
|
|
|
if (callback != null) { |
|
|
|
mainHandler.post(() -> callback.onError(errorMsg)); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 配置串口参数 |
|
|
|
boolean openResult = serialPortManager.openSerialPort(serialPortFile, DEFAULT_BAUD_RATE); |
|
|
|
LogManager.logInfo(TAG, "485串口打开结果: " + openResult); |
|
|
|
|
|
|
|
if (!openResult) { |
|
|
|
String errorMsg = "打开485串口失败: " + DEFAULT_SERIAL_PORT_PATH; |
|
|
|
LogManager.logError(TAG, errorMsg); |
|
|
|
closeAndCleanup(serialPortManager); |
|
|
|
if (callback != null) { |
|
|
|
mainHandler.post(() -> callback.onError(errorMsg)); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 启动读写线程 |
|
|
|
serialPortManager.startReadThread(485); |
|
|
|
serialPortManager.startSendThread(); |
|
|
|
|
|
|
|
byte[] hexBytes = hexStringToByteArray(HEX_COMMAND_GET_PEOPLE_NUM); |
|
|
|
|
|
|
|
// 验证要发送的数据 |
|
|
@ -252,7 +250,7 @@ public class Ox485 { |
|
|
|
if (!sendResult) { |
|
|
|
String errorMsg = "485命令发送失败,可能串口连接异常"; |
|
|
|
LogManager.logError(TAG, errorMsg); |
|
|
|
isSerialPortOpen = false; |
|
|
|
closeAndCleanup(serialPortManager); |
|
|
|
if (callback != null) { |
|
|
|
mainHandler.post(() -> callback.onError(errorMsg)); |
|
|
|
} |
|
|
@ -260,15 +258,13 @@ public class Ox485 { |
|
|
|
} |
|
|
|
|
|
|
|
// 设置超时处理 |
|
|
|
setupTimeout(callback); |
|
|
|
setupTimeout(serialPortManager, callback); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
String errorMsg = "发送485命令异常: " + e.getMessage(); |
|
|
|
LogManager.logError(TAG, errorMsg, e); |
|
|
|
|
|
|
|
// 发送失败可能是连接问题,重置连接状态 |
|
|
|
isSerialPortOpen = false; |
|
|
|
|
|
|
|
closeAndCleanup(serialPortManager); |
|
|
|
if (callback != null) { |
|
|
|
mainHandler.post(() -> callback.onError(errorMsg)); |
|
|
|
} |
|
|
@ -276,10 +272,26 @@ public class Ox485 { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 关闭并清理串口资源 |
|
|
|
* @param serialPortManager 串口管理器 |
|
|
|
*/ |
|
|
|
private void closeAndCleanup(SerialPortManager serialPortManager) { |
|
|
|
if (serialPortManager != null) { |
|
|
|
try { |
|
|
|
serialPortManager.closeSerialPort(); |
|
|
|
LogManager.logInfo(TAG, "485串口已关闭并清理资源"); |
|
|
|
} catch (Exception e) { |
|
|
|
LogManager.logError(TAG, "关闭485串口时发生异常: " + e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 设置超时处理 |
|
|
|
* @param serialPortManager 串口管理器 |
|
|
|
* @param callback 结果回调 |
|
|
|
*/ |
|
|
|
private void setupTimeout(PeopleNumCallback callback) { |
|
|
|
private void setupTimeout(SerialPortManager serialPortManager, PeopleNumCallback callback) { |
|
|
|
cancelTimeout(); // 先取消之前的超时任务 |
|
|
|
|
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
@ -289,13 +301,9 @@ public class Ox485 { |
|
|
|
long elapsedTime = System.currentTimeMillis() - startTime; |
|
|
|
String errorMsg = "485人数查询超时(等待时间: " + elapsedTime + "ms)"; |
|
|
|
LogManager.logError(TAG, errorMsg); |
|
|
|
LogManager.logError(TAG, "485超时详情 - 串口状态: " + (isSerialPortReallyOpen() ? "已打开" : "未打开") + |
|
|
|
", 内部连接状态: " + isSerialPortOpen + |
|
|
|
", 最后成功时间: " + (lastSuccessTime > 0 ? |
|
|
|
new java.text.SimpleDateFormat("HH:mm:ss.SSS").format(new java.util.Date(lastSuccessTime)) : "无")); |
|
|
|
|
|
|
|
// 超时可能是连接问题,重置连接状态 |
|
|
|
isSerialPortOpen = false; |
|
|
|
// 超时后关闭连接 |
|
|
|
closeAndCleanup(serialPortManager); |
|
|
|
|
|
|
|
if (callback != null) { |
|
|
|
callback.onError(errorMsg); |
|
|
@ -472,240 +480,37 @@ public class Ox485 { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取485串口状态(懒加载连接管理模式) |
|
|
|
* 获取485串口状态(即用即连模式) |
|
|
|
* @return 串口状态描述 |
|
|
|
*/ |
|
|
|
public String get485Status() { |
|
|
|
String connectionStatus = isSerialPortOpen ? "已连接" : ( |
|
|
|
isConnecting ? "连接中" : "未连接" |
|
|
|
); |
|
|
|
|
|
|
|
String lastSuccessStr = lastSuccessTime > 0 ? |
|
|
|
new java.text.SimpleDateFormat("HH:mm:ss.SSS").format(new java.util.Date(lastSuccessTime)) : |
|
|
|
"无"; |
|
|
|
|
|
|
|
String status = "串口状态: " + connectionStatus + |
|
|
|
String status = "串口状态: 即用即连模式" + |
|
|
|
", 路径: " + DEFAULT_SERIAL_PORT_PATH + |
|
|
|
", 波特率: " + DEFAULT_BAUD_RATE + |
|
|
|
", 485模式: " + (gateCamera485OxOn ? "已启用" : "未启用") + |
|
|
|
", 最后成功时间: " + lastSuccessStr + |
|
|
|
", 重试次数: " + currentRetryCount; |
|
|
|
", 485模式: " + (gateCamera485OxOn ? "已启用" : "未启用"); |
|
|
|
|
|
|
|
LogManager.logInfo(TAG, status); |
|
|
|
return status; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 关闭485串口 |
|
|
|
* 关闭485串口(兼容旧接口) |
|
|
|
*/ |
|
|
|
public void close485SerialPort() { |
|
|
|
LogManager.logInfo(TAG, "关闭485串口"); |
|
|
|
try { |
|
|
|
cancelTimeout(); |
|
|
|
|
|
|
|
if (serialPortManager != null) { |
|
|
|
serialPortManager.closeSerialPort(); |
|
|
|
LogManager.logInfo(TAG, "485串口已关闭"); |
|
|
|
} |
|
|
|
|
|
|
|
// 重置连接状态 |
|
|
|
isSerialPortOpen = false; |
|
|
|
isConnecting = false; |
|
|
|
lastSuccessTime = 0; |
|
|
|
currentRetryCount = 0; |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
LogManager.logError(TAG, "关闭485串口异常: " + e.getMessage(), e); |
|
|
|
} |
|
|
|
LogManager.logInfo(TAG, "485串口即用即连模式无需手动关闭"); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 释放资源 |
|
|
|
*/ |
|
|
|
public void release() { |
|
|
|
LogManager.logInfo(TAG, "释放Ox485资源"); |
|
|
|
|
|
|
|
// 停止连接检查 |
|
|
|
stopConnectionCheck(); |
|
|
|
|
|
|
|
// 关闭串口 |
|
|
|
close485SerialPort(); |
|
|
|
} |
|
|
|
|
|
|
|
// ========== 懒加载连接管理相关方法 ========== |
|
|
|
|
|
|
|
/** |
|
|
|
* 初始化连接检查任务 |
|
|
|
*/ |
|
|
|
private void initConnectionCheckTask() { |
|
|
|
connectionCheckRunnable = new Runnable() { |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
LogManager.logDebug(TAG, "定时检查485连接状态"); |
|
|
|
|
|
|
|
// 检查最后一次成功时间,如果超过一定时间没有成功通信,则认为连接异常 |
|
|
|
long currentTime = System.currentTimeMillis(); |
|
|
|
if (isSerialPortOpen && lastSuccessTime > 0 && |
|
|
|
(currentTime - lastSuccessTime) > CONNECTION_CHECK_INTERVAL * 2) { |
|
|
|
LogManager.logWarning(TAG, "检测到485连接异常,最后成功时间: " + |
|
|
|
new java.text.SimpleDateFormat("HH:mm:ss.SSS").format(new java.util.Date(lastSuccessTime))); |
|
|
|
|
|
|
|
// 重置连接状态 |
|
|
|
isSerialPortOpen = false; |
|
|
|
|
|
|
|
// 尝试重连 |
|
|
|
if (gateCamera485OxOn) { |
|
|
|
LogManager.logInfo(TAG, "尝试重新建立485连接"); |
|
|
|
retryConnection(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 安排下次检查 |
|
|
|
connectionCheckHandler.postDelayed(this, CONNECTION_CHECK_INTERVAL); |
|
|
|
} |
|
|
|
}; |
|
|
|
LogManager.logInfo(TAG, "释放Ox485资源(即用即连模式)"); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 启动连接检查 |
|
|
|
*/ |
|
|
|
private void startConnectionCheck() { |
|
|
|
LogManager.logInfo(TAG, "启动485连接定时检查,检查间隔: " + (CONNECTION_CHECK_INTERVAL / 1000) + "秒"); |
|
|
|
connectionCheckHandler.post(connectionCheckRunnable); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 停止连接检查 |
|
|
|
*/ |
|
|
|
private void stopConnectionCheck() { |
|
|
|
if (connectionCheckHandler != null && connectionCheckRunnable != null) { |
|
|
|
connectionCheckHandler.removeCallbacks(connectionCheckRunnable); |
|
|
|
LogManager.logInfo(TAG, "485连接定时检查已停止"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 确保连接可用(懒加载核心逻辑) |
|
|
|
* @param callback 连接结果回调 |
|
|
|
*/ |
|
|
|
private void ensureConnection(ConnectionCallback callback) { |
|
|
|
// 如果正在连接中,等待连接完成 |
|
|
|
if (isConnecting) { |
|
|
|
LogManager.logInfo(TAG, "连接正在进行中,等待连接完成..."); |
|
|
|
// 简单等待机制,实际项目中可以优化为队列机制 |
|
|
|
mainHandler.postDelayed(() -> ensureConnection(callback), 500); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 如果已经连接,直接返回 |
|
|
|
if (isSerialPortOpen) { |
|
|
|
LogManager.logDebug(TAG, "485连接已存在,直接复用"); |
|
|
|
callback.onConnected(); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 需要建立新连接 |
|
|
|
LogManager.logInfo(TAG, "首次使用或连接已断开,建立485连接"); |
|
|
|
createConnection(callback); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 建立485连接 |
|
|
|
* @param callback 连接结果回调 |
|
|
|
*/ |
|
|
|
private void createConnection(ConnectionCallback callback) { |
|
|
|
isConnecting = true; |
|
|
|
currentRetryCount = 0; |
|
|
|
|
|
|
|
try { |
|
|
|
LogManager.logInfo(TAG, "开始建立485连接 - 路径: " + DEFAULT_SERIAL_PORT_PATH + ", 波特率: " + DEFAULT_BAUD_RATE); |
|
|
|
|
|
|
|
// 检查串口文件是否存在 |
|
|
|
File serialPortFile = new File(DEFAULT_SERIAL_PORT_PATH); |
|
|
|
if (!serialPortFile.exists()) { |
|
|
|
isConnecting = false; |
|
|
|
String errorMsg = "485串口设备文件不存在: " + DEFAULT_SERIAL_PORT_PATH; |
|
|
|
LogManager.logError(TAG, errorMsg); |
|
|
|
callback.onError(errorMsg); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
LogManager.logInfo(TAG, "485串口设备文件存在,文件权限: 可读=" + serialPortFile.canRead() + ", 可写=" + serialPortFile.canWrite()); |
|
|
|
|
|
|
|
// 配置串口参数 |
|
|
|
boolean openResult = serialPortManager.openSerialPort(serialPortFile, DEFAULT_BAUD_RATE); |
|
|
|
|
|
|
|
LogManager.logInfo(TAG, "485串口打开结果: " + openResult); |
|
|
|
|
|
|
|
if (!openResult) { |
|
|
|
isConnecting = false; |
|
|
|
String errorMsg = "打开485串口失败: " + DEFAULT_SERIAL_PORT_PATH + ",可能原因:设备不存在、权限不足或设备被占用"; |
|
|
|
LogManager.logError(TAG, errorMsg); |
|
|
|
callback.onError(errorMsg); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 先设置连接成功状态,再进行验证 |
|
|
|
isSerialPortOpen = true; |
|
|
|
isConnecting = false; |
|
|
|
lastSuccessTime = System.currentTimeMillis(); |
|
|
|
currentRetryCount = 0; |
|
|
|
|
|
|
|
// 启动读写线程 |
|
|
|
serialPortManager.startReadThread(485); |
|
|
|
serialPortManager.startSendThread(); |
|
|
|
|
|
|
|
LogManager.logInfo(TAG, "485连接建立成功,进入懒加载复用模式,最后成功时间: " + |
|
|
|
new java.text.SimpleDateFormat("HH:mm:ss.SSS").format(new java.util.Date(lastSuccessTime))); |
|
|
|
callback.onConnected(); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
isConnecting = false; |
|
|
|
isSerialPortOpen = false; |
|
|
|
String errorMsg = "建立485连接异常: " + e.getMessage(); |
|
|
|
LogManager.logError(TAG, errorMsg, e); |
|
|
|
callback.onError(errorMsg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 重试连接 |
|
|
|
*/ |
|
|
|
private void retryConnection() { |
|
|
|
if (currentRetryCount >= MAX_RETRY_COUNT) { |
|
|
|
LogManager.logError(TAG, "485连接重试次数超限,停止重试"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
currentRetryCount++; |
|
|
|
LogManager.logInfo(TAG, "485连接重试第 " + currentRetryCount + " 次"); |
|
|
|
|
|
|
|
// 延迟重试 |
|
|
|
mainHandler.postDelayed(() -> { |
|
|
|
createConnection(new ConnectionCallback() { |
|
|
|
@Override |
|
|
|
public void onConnected() { |
|
|
|
LogManager.logInfo(TAG, "485连接重试成功"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onError(String errorMessage) { |
|
|
|
LogManager.logWarning(TAG, "485连接重试失败: " + errorMessage); |
|
|
|
// 继续重试 |
|
|
|
retryConnection(); |
|
|
|
} |
|
|
|
}); |
|
|
|
}, RETRY_DELAY); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 标记成功通信(用于连接健康检查) |
|
|
|
*/ |
|
|
|
private void markSuccessfulCommunication() { |
|
|
|
lastSuccessTime = System.currentTimeMillis(); |
|
|
|
currentRetryCount = 0; // 重置重试次数 |
|
|
|
LogManager.logDebug(TAG, "485通信成功,更新最后成功时间"); |
|
|
|
} |
|
|
|
// ========== 删除所有懒加载连接管理相关方法 ========== |
|
|
|
// 删除initConnectionCheckTask、startConnectionCheck、stopConnectionCheck、 |
|
|
|
// ensureConnection、createConnection、retryConnection、markSuccessfulCommunication、 |
|
|
|
// isSerialPortReallyOpen等方法 |
|
|
|
|
|
|
|
/** |
|
|
|
* HEX字符串转字节数组 |
|
|
@ -738,14 +543,4 @@ public class Ox485 { |
|
|
|
// 15: 0x0F, 3: 0x03, 4: 0x04, 0: 0x00 |
|
|
|
return (bytes[0] == 15 && bytes[1] == 3 && bytes[2] == 4 && bytes[3] == 0); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 检查串口是否真正打开 |
|
|
|
* 由于 SerialPortManager 没有 isOpened() 方法, |
|
|
|
* 我们通过检查内部状态变量来判断 |
|
|
|
* @return true表示串口已打开 |
|
|
|
*/ |
|
|
|
private boolean isSerialPortReallyOpen() { |
|
|
|
return isSerialPortOpen && serialPortManager != null; |
|
|
|
} |
|
|
|
} |