Exemplo n.º 1
0
        private void ConnectToDevice()
        {
            if (curDeviceAddress == null)
            {
                DataGridViewRow selectedRow = dgvDeviceDiscovery.SelectedRows[0];
                selectedDevice   = (BtDevice)dgvDeviceDiscovery.CurrentCell.Value;
                curDeviceAddress = selectedDevice.DeviceAddress;
            }
            BtConnectionParameters cxParam = new BtConnectionParameters();

            cxParam.ConnectionIntervalMs = 30;
            //cxParam.SlaveLatency = 0;
            //cxParam.SupervisionTimeoutMs = 10000;
            try
            {
                if (false && isBonded)
                {
                    masterEmulator.Connect(curDeviceAddress, cxParam);
                }
                else
                {
                    if (masterEmulator.Connect(curDeviceAddress, cxParam))
                    {
                        //masterEmulator.Bond();
                        DiscoverPipes();
                    }
                }
            }
            catch (Exception ex)
            {
                DisplayErrorMessage(ex);
            }
        }
Exemplo n.º 2
0
        private BtDevice DiscoverPeerAddress(BtDeviceAddress address, int duration)
        {
            IEnumerable <BtDevice> devices;

            try
            {
                BtScanParameters scanParams = new BtScanParameters();
                scanParams.ScanIntervalMs = 100;
                scanParams.ScanWindowMs   = 12;
                devices = masterEmulator.DiscoverDevices(1, scanParams);
                foreach (BtDevice dev in devices)
                {
                    if (address.Value == dev.DeviceAddress.Value)
                    {
                        return(dev);
                    }
                }
                return(null);
            }
            catch (Exception ex)
            {
                DisplayErrorMessage(ex);
                return(null);
            }
        }
Exemplo n.º 3
0
        void OnDgvDeviceDiscoveryClick(object sender, EventArgs e)
        {
            if (isConnected)
            {
                return;
            }

            if (dgvDeviceDiscovery.CurrentCell != null)
            {
                string deviceKey = (string)(dgvDeviceDiscovery.CurrentCell.Value);
                selectedDevice     = discoveredDevicesList[deviceKey];
                curDeviceAddress   = selectedDevice.DeviceAddress;
                btnConnect.Enabled = true;
            }
        }
Exemplo n.º 4
0
 public void conn_BELT()
 {
     if (true)
     {
         //if (dgvDeviceDiscovery.SelectedRows.Count > 0)
         {
             //DataGridViewRow selectedRow = dgvDeviceDiscovery.SelectedRows[0];
             //BtDeviceAddress selectedDevice = (BtDeviceAddress)selectedRow.Cells["Data"].Value;
             try
             {
                 //this.Cursor = Cursors.WaitCursor;
                 BtDeviceAddress address        = new BtDeviceAddress(Belt_address);
                 bool            connectSuccess = masterEmulator.Connect(address);
                 if (connectSuccess)
                 {
                     //masterEmulator.Bond();
                     //DiscoverPipes();
                     OnConnected();
                 }
             }
             catch (Exception ex)
             {
                 //DisplayErrorMessage(ex);
             }
             finally
             {
                 //this.Cursor = Cursors.Default;
             }
         }
     }
     else
     {
         try
         {
             //this.Cursor = Cursors.WaitCursor;
             masterEmulator.Disconnect();
             //pipeDiscoveryComplete = false;
         }
         catch (Exception ex)
         {
             //DisplayErrorMessage(ex);
         }
         finally
         {
             //this.Cursor = Cursors.Default;
         }
     }
 }
Exemplo n.º 5
0
        void OnBtnConnectDisconnectClick(object sender, RoutedEventArgs e)
        {
            if (!isConnected)
            {

                if (lbDeviceDiscovery.SelectedItems.Count > 0)
                {
                    StringValue selecterRow = (StringValue)lbDeviceDiscovery.SelectedItem;
                    BtDeviceAddress selectedDevice = (BtDeviceAddress)selecterRow.Data;
                    try
                    {
                        this.Cursor = Cursors.Wait;
                        BtDeviceAddress address = new BtDeviceAddress(selectedDevice.Value);
                        if (masterEmulator.Connect(address))
                        {
                            DiscoverPipes();
                            OpenRemotePipes();
                            isPipeDiscoveryComplete = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        DisplayErrorMessage(ex);
                    }
                    finally
                    {
                        this.Cursor = null;
                    }
                }
            }
            else
            {
                try
                {
                    this.Cursor = Cursors.Wait;
                    masterEmulator.Disconnect();
                    isPipeDiscoveryComplete = false;
                }
                catch (Exception ex)
                {
                    DisplayErrorMessage(ex);
                }
                finally
                {
                    this.Cursor = null;
                }
            }
        }