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

Voorgesteld antwoord How do I check to see which ports are open Using.System.IO.Ports

  • woensdag 25 februari 2009 6:09
     
     
         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

Alle reacties

  • donderdag 23 april 2009 14:28
     
     Voorgesteld antwoord
    IsOpen should work, but If you get null values for SP.GetPortNames() then the problem maybe you have no availble ports at all.