コード例 #1
0
        private async void buttonConnect_Click(object sender, EventArgs e)
        {
            if (listBoxDeviceSearch.SelectedIndex < 0 || string.IsNullOrEmpty(SelectDeviceString))
            {
                MessageBox.Show("未选择设备!");
                return;
            }


            var dev = BleGattDevice.String2Device(SelectDeviceString);

            if (dev != null)
            {
                if (await CsrBleControl.Only().BleHostConnect(dev))
                {
                    OnDeviceConnectEvent(dev);
                    OnUpdateDeviceConnectResult(dev);
                }
            }
            else
            {
                OnDeviceConnectEvent(null);
                OnUpdateDeviceConnectResult(null);
            }

            listBoxDeviceSearch.SelectedItem = null;
            SelectDeviceString = string.Empty;
            SelectAddr         = string.Empty;
        }
コード例 #2
0
        private async void buttonConnect_Click(object sender, EventArgs e)
        {
            if (listBoxDeviceSearch.SelectedIndex < 0 || string.IsNullOrEmpty(_selectSearchDeviceString))
            {
                MessageBox.Show("未选中设备!");
                return;
            }

            var dev = BleGattDevice.String2Device(_selectSearchDeviceString);

            if (dev != null)
            {
                if (await CsrBleControl.Only().BleHostConnect(dev))
                {
                    OnDeviceConnectResults(CsrBleControl.Only().GattConnectDevices);
                    OnDeviceSearchResults(CsrBleControl.Only().GattSearchDevices);

                    _selectConnectDeviceString        = string.Empty;
                    listBoxDeviceConnect.SelectedItem = null;
                }
                else
                {
                    MessageBox.Show("设备连接异常!");
                }
            }
            else
            {
                MessageBox.Show("设备连接异常!");
                OnDeviceConnectResults(CsrBleControl.Only().GattConnectDevices);
            }


            _selectSearchDeviceString = string.Empty;
            _selectSearchAddress      = string.Empty;
        }
コード例 #3
0
        private void listBoxDeviceSearch_SelectedIndexChanged(object sender, EventArgs e)
        {
            SelectDeviceString = listBoxDeviceSearch.Text?.ToString();
            SelectAddr         = BleGattDevice.GetAddress(SelectDeviceString);

            CsrBleControl.Only().BleHostScanStop();
        }
コード例 #4
0
        private void listBoxDeviceSearch_SelectedIndexChanged(object sender, EventArgs e)
        {
            _selectSearchDeviceString = listBoxDeviceSearch.SelectedItem.ToString();
            _selectSearchAddress      = BleGattDevice.GetAddress(_selectSearchDeviceString);

            CsrBleControl.Only().BleHostScanStop();
        }
コード例 #5
0
        private void buttonEnum_Click(object sender, EventArgs e)
        {
            labelBleConnectStatus.Text      = "查找中...";
            labelBleConnectStatus.BackColor = Color.Gold;

            CsrBleControl.Only().BleHostScanStart();

            OnUpdateDeviceSearchResults(CsrBleControl.Only().GattSearchDevices);
        }
コード例 #6
0
        private void buttonEnum_Click(object sender, EventArgs e)
        {
            buttonEnum.Text      = "查找中...";
            buttonEnum.BackColor = Color.Gold;

            CsrBleControl.Only().BleHostScanStart();

            OnDeviceSearchResults(CsrBleControl.Only().GattConnectDevices);
        }
コード例 #7
0
        private async void buttonDisconnect_Click(object sender, EventArgs e)
        {
            OnDeviceDisconnectEvent(null);

            await CsrBleControl.Only().BleHostDisconnect();

            OnUpdateDeviceConnectResult(null);

            listBoxDeviceSearch.SelectedItem = null;
            SelectDeviceString = string.Empty;
            SelectAddr         = string.Empty;
        }
コード例 #8
0
        private void CsrBleUserMultiControl_Load(object sender, EventArgs e)
        {
            _minRssi = Properties.Settings.Default.MultiMinRssi;

            comboBoxRssiDbm.Items.AddRange(Enumerable.Range(1, 9).Select(r => (object)(r * -10).ToString()).ToArray());
            comboBoxRssiDbm.SelectedItem = _minRssi.ToString();

            CsrBleControl.Only().DeviceSearchEvent  += OnDeviceSearchResults;
            CsrBleControl.Only().DeviceConnectEvent += OnDeviceConnectUpdate;

            buttonEnum.PerformClick();
        }
コード例 #9
0
        public static async void CsrBleTerminate()
        {
            if (!CsrBleControl.Only().IsBleHosted)
            {
                return;
            }

            await CsrBleControl.Only().BleHostDisconnect();

            Thread.Sleep(300);
            CsrBleControl.Only().BleHostScanStop();
            Thread.Sleep(300);
            CsrBleControl.Only().BleHostTerminate();
        }
コード例 #10
0
        private void comboBoxRssiDbm_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                _minRssi = int.Parse(comboBoxRssiDbm.Text);

                Properties.Settings.Default.MultiMinRssi = _minRssi;
                Properties.Settings.Default.Save();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            OnDeviceSearchResults(CsrBleControl.Only().GattSearchDevices);
        }
コード例 #11
0
        private async void buttonDisconnect_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(_selectConnectDeviceString))
            {
                await CsrBleControl.Only().BleHostDisconnect(BleGattDevice.GetAddress(_selectConnectDeviceString));

                OnDeviceConnectResults(CsrBleControl.Only().GattConnectDevices);

                _selectConnectDeviceString        = string.Empty;
                listBoxDeviceConnect.SelectedItem = null;
            }
            else
            {
                await CsrBleControl.Only().BleHostDisconnect();

                OnDeviceConnectResults(null);
            }
        }
コード例 #12
0
        public static void CsrBleInitialize()
        {
            //csr uenergy host init
            CsrBleControl.Only().BleHostInitialize();

            var i = 0;

            while (i++ < 60)
            {
                Application.DoEvents();
                Thread.Sleep(100);
                if (CsrBleControl.Only().IsBleHosted)
                {
                    break;
                }
            }

            if (!CsrBleControl.Only().IsBleHosted)
            {
                MessageBox.Show("蓝牙打开失败!");
                Application.Exit();
            }
        }
コード例 #13
0
        private void CsrBleUserControl_Load(object sender, EventArgs e)
        {
            CsrBleControl.Only().DeviceSearchEvent += OnUpdateDeviceSearchResults;

            buttonEnum.PerformClick();
        }
コード例 #14
0
 public static CsrBleControl Only()
 {
     return(ins ?? (ins = new CsrBleControl()));
 }
コード例 #15
0
 private void OnDeviceConnectUpdate(string obj)
 {
     OnDeviceConnectResults(CsrBleControl.Only().GattConnectDevices);
 }