private void Manager_OnDeviceFound(object sender, wclBluetoothRadio radio, long address)
        {
            var devType = wclBluetoothDeviceType.dtMixed;
            var res     = radio.GetRemoteDeviceType(address, out devType);

            _devices.Add(address.ToString("X12"), radio);

            TraceEvent(address, "Device found", "", "");
        }
        static void Manager_OnDeviceFound(object Sender, wclBluetoothRadio Radio, long Address)
        {
            wclBluetoothDeviceType DevType = wclBluetoothDeviceType.dtMixed;
            Int32 Res = Radio.GetRemoteDeviceType(Address, out DevType);

            if (Res != wclErrors.WCL_E_SUCCESS)
            {
                CSLibrary.Debug.WriteLine("Error: 0x" + Res.ToString("X8"));
            }
            else
            {
                switch (DevType)
                {
                case wclBluetoothDeviceType.dtBle:
                {
                    CSLibrary.DeviceFinder.DeviceInfomation di = new CSLibrary.DeviceFinder.DeviceInfomation();
                    string DevName;
                    sbyte  RSSI;

                    Res = Radio.GetRemoteRssi(Address, out RSSI);
                    if (Res != wclErrors.WCL_E_SUCCESS)
                    {
                        RSSI = 0;
                    }
                    Res = Radio.GetRemoteName(Address, out DevName);
                    if (Res != wclErrors.WCL_E_SUCCESS)
                    {
                        di.deviceName = DevName = "Error: 0x" + Res.ToString("X8");
                    }
                    else
                    {
                        di.deviceName = DevName;
                    }

                    di.ID     = (uint)_deviceDB.Count;
                    di.macAdd = Address;
                    di.nativeDeviceInformation = null;

                    _deviceDB.Add(Address);

                    RaiseEvent <DeviceFinderArgs>(OnSearchCompleted, new DeviceFinderArgs(di));
                }
                break;
                }
            }
        }
Exemple #3
0
        private void FManager_AfterOpen(object sender, EventArgs e)
        {
            lbLog.Items.Add("Bluetooth Manager has been opened");

            if (FManager.Count == 0)
            {
                lbLog.Items.Add("No Bluetooth radio found");
                FManager.Close();
            }
            else
            {
                wclBluetoothRadio Radio = FManager[0];
                lbLog.Items.Add("Found " + Radio.ApiName + " Bluetooth radio");

                Int64[] Devices;
                Int32   Res = Radio.EnumPairedDevices(out Devices);
                if (Res != wclErrors.WCL_E_SUCCESS)
                {
                    lbLog.Items.Add("Enumerate paired devices failed: 0x" + Res.ToString("X8"));
                }
                else
                {
                    if (Devices == null || Devices.Length == 0)
                    {
                        lbLog.Items.Add("Not paired devices found");
                        FManager.Close();
                    }
                    else
                    {
                        Int64 Address = 0;
                        foreach (Int64 a in Devices)
                        {
                            wclBluetoothDeviceType Type;
                            Res = Radio.GetRemoteDeviceType(a, out Type);
                            if (Res == wclErrors.WCL_E_SUCCESS && Type == wclBluetoothDeviceType.dtBle)
                            {
                                Address = a;
                                break;
                            }
                        }

                        if (Address == 0)
                        {
                            lbLog.Items.Add("No BLE device found");
                            FManager.Close();
                        }
                        else
                        {
                            FClient.Address = Address;
                            Res             = FClient.Connect(Radio);
                            if (Res != wclErrors.WCL_E_SUCCESS)
                            {
                                lbLog.Items.Add("Connect failed; 0x" + Res.ToString("X8"));
                            }
                        }
                    }
                }

                if (Res != wclErrors.WCL_E_SUCCESS)
                {
                    FManager.Close();
                }
            }
        }