How to get Bluetooth Device Com serial Port in winform C#?

邮差的信 提交于 2019-12-13 06:50:20

问题


How do I get the port details of the Bluetooth device that I have paired within my windows form c# application? Manually I can get all port names but I need the com port name that allocated to particular Bluetooth Device.


回答1:


Check this post

the Win32_PnPEntity is Plug and play devices MSDN

you can go on the drivers also to find your device

            // The WMI query 
            const string QueryString = "SELECT * FROM Win32_PnPSignedDriver ";


            SelectQuery WMIquery = new SelectQuery(QueryString);
            ManagementObjectSearcher WMIqueryResults = new ManagementObjectSearcher(WMIquery);

            // Make sure results were found
            if (WMIqueryResults == null)
                return;

            // Scan query results to find port
            ManagementObjectCollection MOC = WMIqueryResults.Get();

            foreach (ManagementObject mo in MOC)
            { 
                if (mo["FriendlyName"] != null && mo["FriendlyName"].ToString().Contains("YOUR_DEVICE_NAME"))
                {}
              //Check the mo Properties to find the COM port
            }


来源:https://stackoverflow.com/questions/26439091/how-to-get-bluetooth-device-com-serial-port-in-winform-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!