Example #1
0
        public string GetPortInformation()
        {
            ManagementClass            processClass = new ManagementClass("Win32_PnPEntity");
            ManagementObjectCollection Ports        = processClass.GetInstances();

            foreach (ManagementObject property in Ports)
            {
                var name = property.GetPropertyValue("Name");
                if (name != null && name.ToString().Contains("USB") && name.ToString().Contains("COM"))
                {
                    var portInfo = new SerialPortInfo(property);
                    //Thats all information i got from port.
                    //Do whatever you want with this information
                    OutToRichLog("Com", "" + name);
                }
            }
            return(string.Empty);
        }
Example #2
0
        public string GetCurrentPortInformation(string selectedport)
        {
            ManagementClass            processClass = new ManagementClass("Win32_PnPEntity");
            ManagementObjectCollection Ports        = processClass.GetInstances();

            foreach (ManagementObject property in Ports)
            {
                var name   = property.GetPropertyValue("Name");
                var desc   = property.GetPropertyValue("Description");
                var status = property.GetPropertyValue("Status");

                if (name != null && name.ToString().Contains(selectedport))
                {
                    var portInfo = new SerialPortInfo(property);
                    Debug.WriteLine(status);
                    Debug.WriteLine(desc);
                    Debug.WriteLine(portInfo);
                }
            }
            return(string.Empty);
        }