Click here to Skip to main content
15,899,825 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Hello ... I'm Working in project to find the Android Comport ...
I will add the Code that I used but >>>
it's Show All the Comport in my Computer ... I need to Show only Android Comport ..
is there Any way to do it ?

What I have tried:

C#
{
    string[] ArrayComPortsNames = null;
    int index = -1;
    string ComPortName = null;

    ArrayComPortsNames = SerialPort.GetPortNames();
           
    do
    {
        index += 1;
        metroComboBox1.Items.Add ( ArrayComPortsNames[index]);
    }
    while (!((ArrayComPortsNames[index] == ComPortName) ||
                        (index == ArrayComPortsNames.GetUpperBound(0))));

}
Posted
Updated 8-May-16 4:18am
v2
Comments
George Jonsson 8-May-16 9:08am    
What is your filter criteria for an Android COM port?
List all the ports you find and show which one(s) you want to show.
That will make it possible to give some help forward.
George Jonsson 8-May-16 9:10am    
And why not use a foreach-loop instead?
Member 12509947 8-May-16 9:35am    
Where to use Foreach -loop ? And how Can I add pic to show the oprt that listed in metroComboBox1 .... ?
what if I wanted to Connect it with Andorid ADB InterFace ?
its taht possible ?
i used to call CMD with "adb.exe" and use "adb devices " Command to c the connected on ... but .. I don't wanna used it anymore I wanna Scan For open port/And Connect to it ...
George Jonsson 8-May-16 10:08am    
You cannot add a pic here.
You have to write a list manually.
Kornfeld Eliyahu Peter 8-May-16 9:24am    
I hope you know that connecting an android device to your PC does not automatically opens a COM port! For that you have to install the proper USB-to-COM diver for that device first...

1 solution

IF you really want to list all COM port names and try to filter out which one(s) that are Android ports you can do something like this.

C#
foreach (string portName in SerialPort.GetPortNames())
{
    if (portName == someThing)
        metroComboBox1.Items.Add(portName);
}

You have to fill in the code for the someThing.

You can also use
C#
if (portName.StartsWith(someThing))
or
if (portName.EndsWith(someThing))
or
if (portName.Contains(someThing))


There are other ways to do it, but they are maybe a little bit too advanced.

In any case, you will have to know some key word or key data for your port to make this fool proof.

Do you really have that many COM ports on your computer?
 
Share this answer
 
Comments
Member 12509947 8-May-16 10:40am    
O.o yes I have ...
Btw ... I'm just Beginner .. And Try to do it .. Thank for help ..
George Jonsson 8-May-16 22:21pm    
I kind of figured out that you are a beginner. :-)
Decide what you want to do and then search for ways how to do it.
Member 12509947 9-May-16 5:42am    
Please I have another Question ...
when the proces start :
I name it pro the Code :
pro.Start();
StringBuilder p = new StringBuilder();
while (!pro.HasExited)
{
p.Append(pro.StandardOutput.ReadToEnd());

}

string r = p.ToString();
I need to Copy Specific Line (or ) part of line ..
for e.g : In the line 2 : nth nth Model : bla bla
I need to copy bla bla !
can I do it ?
Thank u for being Helpful ... :)
George Jonsson 9-May-16 20:15pm    
Please post this as a new question. The comment section is not really made for posting code.
ridoy 8-May-16 13:23pm    
good one, my 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900