2009-05-04 77 views
1

我正在调试一些使用串口的单声道代码。 在一些点,单写一个表,下面的代码:Mono System.IO.Ports SerialPort类错误处理

// 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) 

我的理解是,一个串口写方法DOS不能正确处理-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 

回答

2

考虑升级到更新的版本。

该错误修复了here

+0

它没有成为1.9.1,似乎被广泛使用,至少在debian和朋友。 – shodanex 2009-05-04 12:59:18

0

我有一个解决办法,但我不认为这是一个很好的解决方案:

progressBar = new ProgressBar(); 

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

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

{ 

    MySP.Write(MyCRC[i].ToString("x8")); 
    while(WySP.BytesToWrite != 0) 
    { 
     ; 
    } 
    progressBar.Percent = (((Double)(i+1))/MyCRC.Length); 

} 

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