feat: 完善I2C读的逻辑

This commit is contained in:
alivender
2025-07-15 17:57:15 +08:00
parent 533e2561ab
commit 4b140ef683
2 changed files with 19 additions and 5 deletions

View File

@@ -201,7 +201,7 @@ public class I2c
/// <returns>操作结果,成功返回读取到的数据,否则返回异常信息</returns>
public async ValueTask<Result<byte[]>> ReadData(UInt32 devAddr, byte[] data, int dataReadLength, I2cProtocol proto)
{
if (dataReadLength <= 0 || dataReadLength > 0x0000_FFFF)
if (dataReadLength < 1 || dataReadLength > 0x0000_FFFF)
{
logger.Error($"Read length {dataReadLength} is invalid or exceeds maximum allowed 0x0000_FFFF");
return new(new ArgumentException($"Read length {dataReadLength} is invalid or exceeds maximum allowed 0x0000_FFFF"));