none
How do I check to see which ports are open Using.System.IO.Ports RRS feed

  • Pergunta

  •      Hi, I'm using System.IO.Ports to connect to various communication devices (one at a time of course)

    and well whenever I connected my PICDEM 2+ board to hyper terminal I'm making for it, the app is saying it can't open COM 1.

    Well of course, it's not connected to COM 1, and it usually various between COM 3 - COM 7.

    However, I'm not sure which it usually connect to, so I would like to run a small algorithm as the app is loading, and see which ports are open, and are connected.

    I tried something along the lines of

    SerialPort SP = new SerialPort("COM 1")

    if(SP.IsOpen()) break;

    else

    SP = new SerialPort("COM 2");

    if(SP.IsOpen()) break;

    else...

    etc.. up to COM 7

    but it didn't work.


    What would be a more clever way doing this?

    I have also tried

    SP.GetPortNames();

    but I get a null array in return

    so I'm not sure what specific function it is that I need to call to get this going correctly.

    Thanks in advance for suggestions, and comments,

    thanks,

    C



    csfinch
    quarta-feira, 25 de fevereiro de 2009 06:09

Todas as Respostas