Exemplo n.º 1
0
        public Form1()
        {
            InitializeComponent();

            bwa = new InTheHand.Net.Bluetooth.BluetoothWin32Authentication(new EventHandler <InTheHand.Net.Bluetooth.BluetoothWin32AuthenticationEventArgs>(AuthHandler));
            InTheHand.Net.Bluetooth.BluetoothRadio.PrimaryRadio.Name = "Something Snazzy";
        }
Exemplo n.º 2
0
 void Win32AuthCallback__(EventHandler <BluetoothWin32AuthenticationEventArgs> handler)
 {
     console.WriteLine("Making PC discoverable");
     InTheHand.Net.Bluetooth.BluetoothRadio radio         = InTheHand.Net.Bluetooth.BluetoothRadio.PrimaryRadio;
     InTheHand.Net.Bluetooth.RadioMode      origRadioMode = radio.Mode;
     radio.Mode = InTheHand.Net.Bluetooth.RadioMode.Discoverable;
     //
     using (InTheHand.Net.Bluetooth.BluetoothWin32Authentication auther
                = new InTheHand.Net.Bluetooth.BluetoothWin32Authentication(handler)) {
         console.Pause("Continue to stop authenticating>");
     }
     radio.Mode = origRadioMode;
 }
Exemplo n.º 3
0
        public void Win32AuthCallbackInduceFinalisationFault()
        {
            console.WriteLine("Authenticate a device two times");
            console.WriteLine("Making PC discoverable");
            InTheHand.Net.Bluetooth.BluetoothRadio radio         = InTheHand.Net.Bluetooth.BluetoothRadio.PrimaryRadio;
            InTheHand.Net.Bluetooth.RadioMode      origRadioMode = radio.Mode;
            radio.Mode = InTheHand.Net.Bluetooth.RadioMode.Discoverable;
            //
            Object auther;

            auther = new InTheHand.Net.Bluetooth.BluetoothWin32Authentication(Win32AuthCallbackTwoSeparateAuthenticationsHandler);
            console.Pause("Continue to clear and GC");
            auther = "foo";
            GC.Collect();
            console.Pause("Continue to complete");
            radio.Mode = origRadioMode;
        }
Exemplo n.º 4
0
        internal BluetoothMonitor()
        {
            if (!InTheHand.Net.Bluetooth.BluetoothRadio.IsSupported)
            {
                throw new PlatformNotSupportedException("Bluetooth Radio not detected");
            }
            //make device discoverable, store old mode to restore afterwards
            previousMode = InTheHand.Net.Bluetooth.BluetoothRadio.PrimaryRadio.Mode;
            InTheHand.Net.Bluetooth.BluetoothRadio.PrimaryRadio.Mode = RadioMode.Discoverable;

            //client provides discovery services
            client = new BluetoothClient();
            authentication = new BluetoothWin32Authentication(new EventHandler<BluetoothWin32AuthenticationEventArgs>(AuthenticationHandler));
        }
Exemplo n.º 5
0
            public void SetPin(BluetoothAddress device, string pin)
            {
#if WinXP
                if (pin != null) {
                    m_authenticator = new BluetoothWin32Authentication(device, pin);
                } else {
                    if (m_authenticator != null) {
                        m_authenticator.Dispose();
                    }
                }
#else
                byte[] link = new byte[32];

                //copy remote device address
                if (device != null)
                {
                    Buffer.BlockCopy(device.ToByteArray(), 0, link, 8, 6);
                }

                //copy PIN
                if (pin != null & pin.Length > 0)
                {
                    if (pin.Length > 16)
                    {
                        throw new ArgumentOutOfRangeException("PIN must be between 1 and 16 ASCII characters");
                    }
                    //copy pin bytes
                    byte[] pinbytes = System.Text.Encoding.ASCII.GetBytes(pin);
                    Buffer.BlockCopy(pinbytes, 0, link, 16, pin.Length);
                    BitConverter.GetBytes(pin.Length).CopyTo(link, 0);
                }

                m_socket.SetSocketOption(BluetoothSocketOptionLevel.RFComm, BluetoothSocketOptionName.SetPin, link);
#endif
            }