Could you help me?
I need show in comboBoxUSB only USB Serial Port?
Thanks in advance,
ocaccy
private void Form1_Load(object sender,EventArgs e)
{
CommPort com=CommPort.Instance;
int foundRSP=0;
string[] portList=com.GetAvailablePorts();
#region This code takes all the serial ports
for(int i=0;i<portList.Length;++i)
{
string name=portList[i];
comboBox1.Items.Add(name);
if(name==Settings.Port.PortName)
foundRSP=i;
}
if(portList.Length>0)
comboBox1.SelectedIndex=foundRSP;
#endregion
ManagementObjectSearcher searcher=new ManagementObjectSearcher("root\\WMI","SELECT * FROM MSSerial_PortName");
string[] USBPorts=System.IO.Ports.SerialPort.GetPortNames();
#region In this code I need only the USB Serial Port
//FriendlyName
//PID & VID
foreach(ManagementObject queryObj in searcher.Get)
{
lbl_InstanceName.Text="InstanceName: {0}"+queryObj["InstanceName"];
lbl_PortName.Text="PortName: {0}"+queryObj["PortName"];
//If the serial port's instance name contains USB Serial Port
//it must be a USB to serial device
if(queryObj["InstanceName"].ToString().Contains("USB Serial Port"))
{
comboBoxUSB.Items.Add(queryObj["PortName"]);
}
}
#endregion
Int32[] baudRates= {
100,300,600,1200,2400,4800,9600,14400,19200,
38400,56000,57600,115200,128000,256000,0
};
foundRSP=0;
for(int i=0;baudRates[i]!=0;++i)
{
comboBox2.Items.Add(baudRates[i].ToString());
if(baudRates[i]==Settings.Port.BaudRate)
foundRSP=i;
}
comboBox2.SelectedIndex=foundRSP;
comboBox3.Items.Add("5");
comboBox3.Items.Add("6");
comboBox3.Items.Add("7");
comboBox3.Items.Add("8");
comboBox3.SelectedIndex=Settings.Port.DataBits-5;
foreach(string s in Enum.GetNames(typeof(Parity)))
{
comboBox4.Items.Add(s);
}
comboBox4.SelectedIndex=(int)Settings.Port.Parity;
foreach(string s in Enum.GetNames(typeof(StopBits)))
{
comboBox5.Items.Add(s);
}
comboBox5.SelectedIndex=(int)Settings.Port.StopBits;
foreach(string s in Enum.GetNames(typeof(Handshake)))
{
comboBox6.Items.Add(s);
}
comboBox6.SelectedIndex=(int)Settings.Port.Handshake;
switch(Settings.Option.AppendToSend)
{
case Settings.Option.AppendType.AppendNothing:
radioButton1.Checked=true;
break;
case Settings.Option.AppendType.AppendCR:
radioButton2.Checked=true;
break;
case Settings.Option.AppendType.AppendLF:
radioButton3.Checked=true;
break;
case Settings.Option.AppendType.AppendCRLF:
radioButton4.Checked=true;
break;
}
checkBox1.Checked=Settings.Option.HexOutput;
checkBox2.Checked=Settings.Option.MonoFont;
checkBox3.Checked=Settings.Option.LocalEcho;
checkBox4.Checked=Settings.Option.StayOnTop;
checkBox5.Checked=Settings.Option.FilterUseCase;
}





MultiQuote



|