Find serial-objectquery ("SELECT * from Win32_serialport")

Source: Internet
Author: User

Using System.IO.Ports;
Using System.Management; After adding this sentence, there is still a red wavy line hint that you need to manually add the DLL reference (VS2012)

[ComVisibleAttribute (TRUE)]//Add COM visibility under namespaces

     String tmpstr1 = "";        String tmpport = "";        list<string> usefulport = new list<string> ();  private void Openacclecomprot () {//com lookup/objectquery query = new ObjectQuery ("SELECT * FROM Win32_serialport ");            Win32_USBControllerDevice ManagementObjectSearcher searcher = new ManagementObjectSearcher (query);            Usefulport.clear ();            int loadcount = 0; Find/foreach (ManagementObject obj2 in searcher) based on the feature you set. Get ()) {if (obj2. properties["Pnpdeviceid"]. Value.tostring (). Contains (@ "usb\vid_26ac&pid_0010")) {//messagebox.show (obj2. properties["Name"].                    Value.tostring ()); TMPSTR1 = Obj2. properties["Name"].                    Value.tostring ();                    Usefulport.add (TMPSTR1);                loadcount++;            }} string[] Allports = Serialport.getportnames (); Foreach (String port in Allports) {if (tmpstr1.                    Contains (port)) {//messagebox.show (port);                Tmpport = port; }            }        }

  

The most basic USB device structure

Class Usbdeviceinfo        {public            usbdeviceinfo (string DeviceID, String Pnpdeviceid, string description)            { This                . DeviceID = DeviceID;                This. Pnpdeviceid = Pnpdeviceid;                This. Description = Description;            }            public string DeviceID {get; private set;}            public string Pnpdeviceid {get; private set;}            public string Description {get; private set;}        }

The structure of USB serial port

https://msdn.microsoft.com/en-us/library/aa394504 (v=vs.85). aspx

[Dynamic, Provider ("CIMWin32"), UUID ("{98c7e2c7-d592-11d2-b355-00105a0a323a}"), Amendment]class Win32_ usbcontroller:cim_usbcontroller{  uint16   availability;  String   Caption;  UInt32   Configmanagererrorcode;  Boolean  configmanageruserconfig;  String   creationclassname;  String   Description;  String   DeviceID;  Boolean  errorcleared;  String   errordescription;  DateTime installdate;  UInt32   LastErrorCode;  string   manufacturer;  UInt32   maxnumbercontrolled;  String   Name;  String   Pnpdeviceid;  UInt16   powermanagementcapabilities[];  Boolean  powermanagementsupported;  UInt16   protocolsupported;  String   Status;  UInt16   StatusInfo;  String   systemcreationclassname;  String   SystemName;  DateTime timeoflastreset;};

  

Find serial-objectquery ("SELECT * from Win32_serialport")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.