Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A serial port doesn't know what is connected on the other side. You need to try to open each one and send something like <code>"AT\r\n"</code> and expect <code>"OK"</code> to check on which one your modem is connected.</p> <p>EDIT:</p> <pre><code> using System; using System.IO.Ports; using System.Collections; using System.Collections.Generic; using System.Text; private static bool IsModem(string PortName) { SerialPort port= null; try { port = new SerialPort(PortName,9600); //9600 baud is supported by most modems port.ReadTimeout = 200; port.Open(); port.Write("AT\r\n"); //some modems will return "OK\r\n" //some modems will return "\r\nOK\r\n" //some will echo the AT first //so for(int i=0;i&lt;4;i++) //read a maximum of 4 lines in case some other device is posting garbage { string line = port.ReadLine(); if(line.IndexOf("OK")!=-1) { return true; } } return false; } catch(Exception ex) { // You should implement more specific catch blocks so that you would know // what the problem was, ie port may be in use when you are trying // to test it so you should let the user know that as he can correct that fault return false; } finally { if(port!=null) { port.Close(); } } } public static string[] FindModems() { List&lt;string&gt; modems = new List&lt;string&gt;(); string[] ports = SerialPort.GetPortNames(); for(int i =0;i&lt;ports.Length;i++) { if(IsModem(ports[i])) { modems.Add(ports[i]); } } return modems.ToArray(); } </code></pre> <p>Something like this should work, I didn't test it ( can't test it ).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload