Serial Data Not Transmitted in C# Application

Posted by Jim Fell on Stack Overflow See other posts from Stack Overflow or by Jim Fell
Published on 2010-05-17T19:01:11Z Indexed on 2010/05/17 19:20 UTC
Read the original article Hit count: 158

Filed under:
|

Hello. I have a C# application wherein serial (COM1) data appears to sometimes not get transmitted. Following is a simplified snippet of my code (calls to textBox writes have been removed):

        try
        {
           serialPort1.Write("D");
           serialPort1.Write(msg, 0, 512);
           serialPort1.Write("d");
           serialPort1.Write(pCsum, 0, 2);
        }
        catch (SystemException ex)
        {
           /* ... */
        }

What is odd is that this same code works just fine when the port is configured for 115.2Kbps. However, when running at 9600bps data that should be transmitted by this code seems to not get transmitted. I have verified this by monitoring the receive flag on the remote device. No exceptions are thrown from within the try statement. Is there something else (Flush, etc.) that I should be doing to make sure the data is transmitted? Any thoughts or suggestions you may have would be appreciated. I'm using Microsoft Visual C# 2008 Express Edition. Thanks.

© Stack Overflow or respective owner

Related posts about c#

Related posts about serial-communications