diff --git a/AirISP/BasicOperation.cs b/AirISP/BasicOperation.cs
index 19911f0..9125786 100644
--- a/AirISP/BasicOperation.cs
+++ b/AirISP/BasicOperation.cs
@@ -276,6 +276,26 @@ public static bool ResetAPP()
}
}
+ ///
+ /// 读取连续完整的串口数据
+ ///
+ ///
+ private static byte[] readSerial()
+ {
+ //一次性读完,防止读不全
+ var buff = new List();
+ var toRead = serial.BytesToRead;
+ while (toRead > 0)
+ {
+ var buffer = new byte[toRead];
+ serial.Read(buffer, 0, toRead);
+ buff.AddRange(buffer);
+ Thread.Sleep(1);
+ toRead = serial.BytesToRead;
+ }
+ return buff.ToArray();
+ }
+
///
/// 向芯片中写入一系列数据,并检查是否有ACK
///
@@ -303,8 +323,7 @@ public static bool Write(byte[] data, int timeOut = 200, int ACKCount = 1)
length = serial.BytesToRead;
if (length > 0)
{
- var rev = new byte[length];
- serial.Read(rev, 0, length);
+ var rev = readSerial();
if (baseParameter.Trace == true)
{
ColorfulConsole.LogLine($"Retrieved data: {BitConverter.ToString(rev)}");
@@ -346,8 +365,7 @@ public static bool Write(byte[] data, int timeOut = 200, int ACKCount = 1)
length = serial.BytesToRead;
if (length > 0)
{
- var rev = new byte[length];
- serial.Read(rev, 0, length);
+ var rev = readSerial();
if (baseParameter.Trace == true)
{
ColorfulConsole.LogLine($"Retrieved data: {BitConverter.ToString(rev)}");