feat(ch934x_serial): 添加串口写入功能的端口索引参数

- write方法新增可选的serialPortIndex参数,支持直接写入指定端口
- 传入端口索引时不会改变当前活跃端口,保持原有活跃端口行为
- 添加对负数端口索引的验证处理,直接返回零避免异常
- 更新文档说明多端口并发客户端应使用显式端口写入方式
- 增加相关单元测试覆盖新参数的各种使用场景
- 同步更新Android原生层实现以支持端口索引传递
This commit is contained in:
2026-07-13 20:51:27 +08:00
parent 020904bd2a
commit 7fe87f8d7c
10 changed files with 137 additions and 73 deletions
+3 -1
View File
@@ -79,7 +79,9 @@ abstract class Ch934xSerialPlatform extends PlatformInterface {
Future<Uint8List> read(int length, {int? serialPortIndex});
/// 向串口写入数据(对应 6.2.1 `UsbSerial.write`)。
Future<int> write(Uint8List data);
///
/// [serialPortIndex] 为空时使用当前活跃端口;传入时直接写入指定端口。
Future<int> write(Uint8List data, {int? serialPortIndex});
// ---------------------------------------------------------------------------
// GPIO