Phil Rounds

Phil Rounds

  • NA
  • 1
  • 922

Problems with SerialPort

Oct 15 2014 1:10 PM

I'm having a problem using  System.IO.Ports   I have an application which communicates with a micro controller, using a serial port over USB.  At one point it was working fine, then I added some threading functionality (which had nothing to do with the serial communications).  Probably coincidentally, but maybe not, the serial communications stopped at this time.  I eliminated the threading functionality, and the serial communications still behaves oddly.

using System.IO.Ports
... 
 namespace MyNameSpace
{
 public partial class MyClass : Form
{... 

private SerialPort Port;

....
  public MyClass()
{
..
 Port = new System.IO.Port.SerialPort();
 Port.PortName = "COM12:";
Port.BaudRate = 115200;
Port.HandShake = HandShake.None;
Port.Open();
 
 
 The problem is that, even after doing this,  Port remains null.  I can create, open and use the port at any time, but outside of the method I do this in, the port reverts to null.  It's not timing out, as I can either waste cpu going into a loop 5 minutes, or go to sleep, but the port still works, as long as you're in any given method.  Once the method completes, the port reverts to null.
 
.Net 4.0, Visual Studio 2010.