gpt4 book ai didi

c# - Mono System.IO.Ports SerialPort 类错误处理

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:31:01 28 4
gpt4 key购买 nike

我正在调试一些使用串口的单声道代码。在某些时候,mono 用以下代码写了一个表:

   // Send the 1024 byte (256 word) CRC table

progressBar = new ProgressBar();

progressBar.Update(0.0,"Sending CRC table...");

for (int i = 0; i < MyCRC.Length; i++)

{

MySP.Write(MyCRC[i].ToString("x8"));

progressBar.Percent = (((Double)(i+1))/MyCRC.Length);

}

progressBar.Update(100.0,"CRC table sent.");

MySP 是一个 SerialPort 实例。但是,当我使用 strace 跟踪此代码时,我认为这是生成的系统调用:

16620 write(3, "3ab551ce", 8)           = -1 EAGAIN (Resource temporarily unavailable)
16620 write(3, "\0003ab551c", 8) = -1 EAGAIN (Resource temporarily unavailable)
16620 write(3, "\0\0003ab551", 8) = -1 EAGAIN (Resource temporarily unavailable)
16620 write(3, "\0\0\0003ab55", 8) = -1 EAGAIN (Resource temporarily unavailable)
16620 write(3, "\10\0\0\0003ab5", 8) = -1 EAGAIN (Resource temporarily unavailable)
16620 write(3, "\0\10\0\0\0003ab", 8) = -1 EAGAIN (Resource temporarily unavailable)

...

16620 write(3, "\0005\0\230O+\10\0", 8) = -1 EAGAIN (Resource temporarily unavailable)
16620 write(3, "E\0005\0\230O+\10", 8) = -1 EAGAIN (Resource temporarily unavailable)
16620 write(3, "\0E\0005\0\230O+", 8) = -1 EAGAIN (Resource temporarily unavailable)
16620 write(3, "\0\0E\0005\0\230O", 8) = -1 EAGAIN (Resource temporarily unavailable)
16620 write(3, "\0\0\0E\0005\0\230", 8) = -1 EAGAIN (Resource temporarily unavailable)
16620 write(3, "4\0\0\0E\0005\0", 8) = 8
16620 write(3, "\230O+\10\0\0\0\0", 8) = 8
16620 write(3, "\0\0\0\0\10\0\0\0", 8) = -1 EAGAIN (Resource temporarily unavailable)

我的理解是 SerialPort Write 方法没有正确处理 -EAGAIN 情况,并在重新开始写入之前将索引更新为 -1。因为每次尝试后,原始缓冲区的内容都会移动一个字节。

我的问题是,这是一个已知问题吗?我如何修改 SerialPort 类以使其行为正确或以阻塞方式使用串行端口?

Mono documentation for the SerialPort class不是很有帮助

附加信息:单声道 -V 输出:

Mono JIT compiler version 1.2.6 (tarball)
Copyright (C) 2002-2007 Novell, Inc and Contributors. www.mono-project.com
TLS: __thread
GC: Included Boehm (with typed GC)
SIGSEGV: altstack
Notifications: epoll
Architecture: x86
Disabled: none

最佳答案

考虑升级到更新的版本。

错误已修复here .

关于c# - Mono System.IO.Ports SerialPort 类错误处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/819515/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com