编辑:是硬件问题.....获得重复的设备或电缆似乎可以解决问题。
您好,我正在努力从 .NETCF 中的串行端口读取大量数据(~1MB)。
我正在读取 GPS 数据转储,但在调用 m_serial.Read(..) 时随机收到 TimeoutException
串行端口上肯定有数据流 - 转储需要几分钟。当我得到超时时,我可以将串行电缆插入另一台计算机并稳定地看到数据流。
我尝试了几种不同的方法——SerialPort.Read、SerialPort.ReadLine、SerialPort.ReadExisting——它们都将读取一小段时间(随机量),然后因 TimeoutException 而失败。
任何帮助将不胜感激,谢谢!当肯定有可用数据以 38400 波特流传输时,我基本上不知道如何超时
//m_serial is a SerialPort object, ReadTimeout set to 9000
string eoftest = "\r\n$PSRF206";
byte[] bEOFTest = ASCIIEncoding.ASCII.GetBytes(eoftest);
int bufferSize = 1024 * 16;
byte[] buffer = new byte[bufferSize];
int testingIndex = 0;
while (testingIndex < bEOFTest.Length)
{
int count = m_serial.Read(buffer, 0, bufferSize);
if (count > 0)
{
for (int i = 0; i < count; i++)
{
if (buffer[i] == bEOFTest[testingIndex])
{
testingIndex++;
if (testingIndex >= bEOFTest.Length)
break;
}
else
testingIndex = 0;
}
writer.Write(buffer, 0, count);
}
}
更新:
我发现代码在 Motorola Symbol 设备上运行良好,但在我拥有的 intermec 设备上运行良好。我已经更换了所有硬件以尝试消除这种可能性,但它仍然无法正常工作。
两台设备都是 Windows Mobile 5.0