none
Open an serial port with CF 3.5 sometimes failed. RRS feed

  • Question

  • To open and use the serial ports working fine, but after some system restarts is it possible the ports are unusable for the CF(C#). On the same time an C program works.

    Can anyone help, please.

    private static SerialPort sp = null;
     
    static void Main(string[] args)
    {
          Console.WriteLine("Opening COM2 ...");
          sp = new SerialPort("COM2", 9600);
          sp.Open();
          Console.WriteLine("Closing COM2.");
          sp.Close();
          Console.WriteLine("Opening COM3 ...");
          sp.PortName = "COM3";
          sp.Open();
          Console.WriteLine("Closing COM3.");
          sp.Close();
          Console.WriteLine("Opening COM4 ...");
          sp.PortName = "COM4";
          sp.Open();
          Console.WriteLine("Closing COM4.");
          sp.Close();
    }
    


    Tuesday, October 4, 2011 1:33 PM

All replies

  • Are those serial ports true physical UARTs or are they or some of them USB ports? Make sure you've given all the UART registry settings the proper "Index" value so that the ports come back with the same number every time and make sure the ports you open are indeed the ports you think you are opening. Also show us the exception or error you get.
    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.
    Tuesday, October 4, 2011 2:05 PM
    Moderator
  • Thank you for your very fast answer.

     

    Are those serial ports true physical UARTs or are they or some of them USB ports?
    Yes there are all physical UARTs.
    Make sure you've given all the UART registry settings the proper "Index" value so that the ports come back with the same number every time and make sure the ports you open are indeed the ports you think you are opening.

    The system works correctly and I can use the serial ports with C# and C code. Sometimes after the system is restarted I can't open the serial ports with C# with an exeption. When I restart the C# program it also throw an exeption, but the C program use this serial ports fine. After an restart of the system the C# program works also without any exeption.

     

    Wednesday, October 5, 2011 8:37 AM
  • What is the exception?

     

    Please also note that serial ports are opened exclusively, meaning only 1 application can have the serial port open at a time.


    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.
    Wednesday, October 5, 2011 8:42 AM
    Moderator
  • System.IO.IOException: IOException
       at System.IO.Ports.SerialStream.WinIOError(Int32 errorCode, String str)
       at System.IO.Ports.SerialStream.CheckResult(Int32 err)
       at System.IO.Ports.SerialStream.InitializeDCB(Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Boolean discardNull)
       at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
       at System.IO.Ports.SerialPort.Open()
       at COMTest.Program.Main(String[] args)
    
    
    This is the exeption output from Message an StackTrace.

    Thursday, October 6, 2011 8:20 AM
  • Change your code like this and show us the debug output:

     

    try
    {
        //your code
    }
    catch (Exception x)
    {
        string msg = "Exception \"" + x.Message + "\"";
        msg += (x.InnerException == null) ? "" : "; \"" + x.InnerException.Message + "\"";
        Console.WriteLine(msg);
    }
    
    

    and show us the console output when the exception is thrown.

     


    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.
    Thursday, October 6, 2011 8:50 AM
    Moderator
  • The console output is:

    Excption "IOException"

    Thursday, October 6, 2011 9:29 AM
  • Ok, that doesn't help much... Can you create a debug kernel (either with or without KITL) and capture the debug output of the kernel and show the relevant output here? You may want to set the debugzones for your serial driver to 0xFFFF.
    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.
    Thursday, October 6, 2011 9:37 AM
    Moderator