Example #1
0
        public void Connect()
        {
            ////////////////////////////////////////////////
            ListnerThread.Start();

            MyConnection = new BluetoothConnection();


            MyConnection.GetAdapter();

            MyConnection.BAdapter.StartDiscovery();

            try
            {
                MyConnection.GetDevice(DeviceName);
                MyConnection.BDevice.SetPairingConfirmation(false);
                //   myConnection.thisDevice.Dispose();
                MyConnection.BDevice.SetPairingConfirmation(true);
                MyConnection.BDevice.CreateBond();
            }
            catch
            {
                //test
            }

            MyConnection.BAdapter.CancelDiscovery();

            Socket = MyConnection.BDevice.CreateRfcommSocketToServiceRecord(Java.Util.UUID.FromString("00001101-0000-1000-8000-00805f9b34fb"));

            MyConnection.BSocket = Socket;

            System.Threading.Thread.Sleep(500);
            try
            {
                MyConnection.BSocket.Connect();


                if (ListnerThread.IsAlive == false)
                {
                    ListnerThread.Start();
                }
                //else
                //{
                //    ListnerThread.Abort();
                //}
            }
            catch
            {
            }
        }
Example #2
0
        public void Disconnect()
        {
            try
            {
                ListnerThread.Dispose();//stop

                MyConnection.BDevice.Dispose();

                MyConnection.BSocket.OutputStream.WriteByte(187);
                MyConnection.BSocket.OutputStream.Close();

                MyConnection.BSocket.Close();

                MyConnection = new BluetoothConnection();
                Socket       = null;
            }
            catch { }
        }