feat(ch934x_serial): 添加串口写入功能的端口索引参数
- write方法新增可选的serialPortIndex参数,支持直接写入指定端口 - 传入端口索引时不会改变当前活跃端口,保持原有活跃端口行为 - 添加对负数端口索引的验证处理,直接返回零避免异常 - 更新文档说明多端口并发客户端应使用显式端口写入方式 - 增加相关单元测试覆盖新参数的各种使用场景 - 同步更新Android原生层实现以支持端口索引传递
This commit is contained in:
+11
-13
@@ -29,16 +29,14 @@ class Ch934xSerial {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// 获取所有已连接的 CH934X 设备信息。
|
||||
Future<List<Ch934xDeviceInfo>> getDeviceList() =>
|
||||
_platform.getDeviceList();
|
||||
Future<List<Ch934xDeviceInfo>> getDeviceList() => _platform.getDeviceList();
|
||||
|
||||
/// 获取指定设备序列号;非 CH934X 设备时返回 null。
|
||||
Future<String?> getSerialNumber(int deviceId) =>
|
||||
_platform.getSerialNumber(deviceId);
|
||||
|
||||
/// 获取指定设备类型,取值见 [Ch934xDeviceType]。
|
||||
Future<int> getDeviceType(int deviceId) =>
|
||||
_platform.getDeviceType(deviceId);
|
||||
Future<int> getDeviceType(int deviceId) => _platform.getDeviceType(deviceId);
|
||||
|
||||
/// 获取指定设备的串口列表。
|
||||
Future<List<Ch934xSerialPortInfo>> getSerialPortList(
|
||||
@@ -85,7 +83,11 @@ class Ch934xSerial {
|
||||
Future<Uint8List> read(int length) => _platform.read(length);
|
||||
|
||||
/// 写入数据,返回实际写入的字节数。
|
||||
Future<int> write(Uint8List data) => _platform.write(data);
|
||||
///
|
||||
/// [serialPortIndex] 为空时沿用当前活跃串口;传入时直接写入指定端口,
|
||||
/// 不会改变当前活跃串口。
|
||||
Future<int> write(Uint8List data, {int? serialPortIndex}) =>
|
||||
_platform.write(data, serialPortIndex: serialPortIndex);
|
||||
|
||||
/// 构造一个持续从串口拉取数据的 `Stream<Uint8List>`。
|
||||
///
|
||||
@@ -180,12 +182,10 @@ class Ch934xSerial {
|
||||
Future<int> getCurrentMode() => _platform.getCurrentMode();
|
||||
|
||||
/// 获取 GPIO 数量。
|
||||
Future<int> getGpiocount(int deviceId) =>
|
||||
_platform.getGpiocount(deviceId);
|
||||
Future<int> getGpiocount(int deviceId) => _platform.getGpiocount(deviceId);
|
||||
|
||||
/// 获取 GPIO 组数。
|
||||
Future<int> getGpiogroup(int deviceId) =>
|
||||
_platform.getGpiogroup(deviceId);
|
||||
Future<int> getGpiogroup(int deviceId) => _platform.getGpiogroup(deviceId);
|
||||
|
||||
/// 使能 GPIO。
|
||||
Future<bool> enableGpio({
|
||||
@@ -222,12 +222,10 @@ class Ch934xSerial {
|
||||
);
|
||||
|
||||
/// 查询设备是否已打开。
|
||||
Future<bool> isConnected(int deviceId) =>
|
||||
_platform.isConnected(deviceId);
|
||||
Future<bool> isConnected(int deviceId) => _platform.isConnected(deviceId);
|
||||
|
||||
/// 获取当前已打开的设备 ID 列表。
|
||||
Future<List<int>> getConnectedDevices() =>
|
||||
_platform.getConnectedDevices();
|
||||
Future<List<int>> getConnectedDevices() => _platform.getConnectedDevices();
|
||||
|
||||
/// 配置当前活跃串口的参数。
|
||||
Future<bool> setSerialParameter({
|
||||
|
||||
Reference in New Issue
Block a user