示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create CubinoteBLE
            CubinoteBLE SDK = new CubinoteBLE();
            //Get status of Cubinote
            String res = SDK.CubinoteBLE_GetStatus(comboBox1.Text);

            textBox1.Clear();
            textBox1.Text = res;
        }
示例#2
0
        public System.Collections.Generic.List <string> GetAllPorts()
        {
            //List all com port simulated by Bluetooth that connected with Cubinote
            List <String> allPorts = new System.Collections.Generic.List <String>();

            try
            {
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                                                 "SELECT * FROM Win32_PnPEntity WHERE Caption LIKE '%Bluetooth%'");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    if (queryObj["Caption"] != null && queryObj["Caption"].ToString().Contains("(COM"))
                    {
                        String portName = queryObj["Caption"].ToString();
                        int    ipos     = portName.LastIndexOf("COM");
                        if (ipos < 0)
                        {
                            continue;
                        }
                        portName = portName.Substring(ipos);
                        ipos     = portName.IndexOf(")");
                        if (ipos < 0)
                        {
                            continue;
                        }
                        portName = portName.Substring(0, ipos);
                        if (allPorts.IndexOf(portName) == -1)
                        {
                            CubinoteBLE SDK    = new CubinoteBLE();
                            String      result = SDK.CubinoteBLE_GetStatus(portName);
                            if (result.StartsWith("1880") || result.StartsWith("{"))
                            {
                                //Connected with Cubintoe
                                allPorts.Add(portName);
                                comboBox1.Items.Add(portName);
                            }
                        }
                    }
                }
            }
            catch (ManagementException e)
            {
                ;
            }
            return(allPorts);
        }