feat(ch934x_serial): 添加串口写入功能的端口索引参数
- write方法新增可选的serialPortIndex参数,支持直接写入指定端口 - 传入端口索引时不会改变当前活跃端口,保持原有活跃端口行为 - 添加对负数端口索引的验证处理,直接返回零避免异常 - 更新文档说明多端口并发客户端应使用显式端口写入方式 - 增加相关单元测试覆盖新参数的各种使用场景 - 同步更新Android原生层实现以支持端口索引传递
This commit is contained in:
@@ -584,9 +584,14 @@ public class Ch934xSerialPlugin implements FlutterPlugin, MethodCallHandler, Act
|
||||
if (data == null || data.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
Integer portIndex = call.argument("serialPortIndex");
|
||||
int idx = portIndex != null ? portIndex : activeSerialNumber;
|
||||
if (idx < 0) {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
return CH934XManager.getInstance().writeData(
|
||||
activeDevice, activeSerialNumber, data, data.length, 2000);
|
||||
activeDevice, idx, data, data.length, 2000);
|
||||
} catch (ChipException e) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user