Beispiel #1
0
        public void Open()
        {
            this.Close();

            if (_bda == null)
                return;
            try
            {
                //_socket = new System.Net.Sockets.Socket();
                _bluetoothClient = new BluetoothClient();
                _bta = new BluetoothAddress(_bda);
                _bluetoothClient.Connect(new BluetoothEndPoint(_bta, BluetoothService.SerialPort));

                _networkStream = _bluetoothClient.GetStream();
                if(_networkStream!=null)
                    _thread = new myThread(ref _networkStream);
            }
            catch (SocketException sx)
            {
                System.Diagnostics.Debug.WriteLine("SocketException in Open(): " + sx.Message);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception in Open(): " +ex.Message);
            }

        }
 private void btnSearch_Click(object sender, EventArgs e)
 {
     this.Enabled = false;
     Cursor.Current = Cursors.WaitCursor;
     BluetoothDeviceInfo[] bdi;
     BluetoothClient bc = new BluetoothClient();
     bdi = bc.DiscoverDevices();
     comboBox1.DisplayMember = "DeviceName";
     comboBox1.ValueMember = "DeviceID";
     comboBox1.DataSource = bdi;
     if(comboBox1.Items.Count>0)
         comboBox1.SelectedIndex = 0;
     bc.Close();
     Cursor.Current = Cursors.Default;
     this.Enabled = true;
 }