Check SerialPort Exist Modem?

67 views Asked by At

In C# 2005, I used the Nokia E63, I want to check SerialPort Exist Modem, While it run does not get run COM port, you see my code

private void btnGetPort_Click(object sender, EventArgs e)
        {
            cmbPort.Items.Clear();
            foreach (string portName in SerialPort.GetPortNames())
            {
                try
                {
                    using (SerialPort sp = new SerialPort(portName, 9600))
                    {
                        if (!(sp.IsOpen)) sp.Open();
                        sp.DiscardInBuffer();
                        sp.DiscardOutBuffer();
                        sp.Write("AT\r\n");
                        System.Threading.Thread.Sleep(100);
                        string response = sp.ReadExisting();
                        if (response == "OK")
                        {
                            cmbPort.Items.Add(portName);
                        }
                    }
                }
                catch (Exception ex)
                {
                    continue;
                }
            }
        }
0

There are 0 answers