Example #1
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;
 }
Example #2
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;
        }
Example #3
0
        /// <summary>
        /// Initialise an instance of the class for the specified radio.
        /// </summary>
        /// -
        /// <param name="microsoftWin32BluetoothRadio">
        /// The radio to listen for events from.
        /// Must be non-null and a MSFT+Win32 stack radio.
        /// </param>
        /// -
        /// <remarks>Note that since the Microsoft stack supports only one radio
        /// (controller) there is lilely no benefit in calling this constructor
        /// as opposed to the other constructor or method
        /// <see cref="M:InTheHand.Net.Bluetooth.BluetoothWin32Events.GetInstance"/>.
        /// </remarks>
        public BluetoothWin32Events(BluetoothRadio microsoftWin32BluetoothRadio)
        {
#if NETCF
            throw new NotSupportedException("BluetoothWin32Events is Win32 only.");
#else
            if (microsoftWin32BluetoothRadio == null)
            {
                throw new ArgumentNullException("microsoftWin32BluetoothRadio");
            }
            if (microsoftWin32BluetoothRadio.SoftwareManufacturer != Manufacturer.Microsoft)
            {
                throw new ArgumentException("The specified Radio does not use the Microsoft Bluetooth stack.");
            }
            IntPtr bluetoothRadioHandle = microsoftWin32BluetoothRadio.Handle;
            if (bluetoothRadioHandle == IntPtr.Zero)
            {
                throw new ArgumentException("The bluetoothRadioHandle may not be NULL.");
            }
            _bluetoothRadioHandle = bluetoothRadioHandle;
            Start();
#endif
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SenderBluetoothService"/> class. 
        /// </summary>
        public SenderBluetoothService()
        {
            // this guid is random, only need to match in Sender & Receiver
            // this is like a "key" for the connection!
            _serviceClassId = new Guid("e0cbf06c-cd8b-4647-bb8a-263b43f0f974");

            myRadio = BluetoothRadio.PrimaryRadio;
            if (myRadio == null)
            {
                Console.WriteLine("No radio hardware or unsupported software stack");
                //return;
            }
            RadioMode mode = myRadio.Mode;
            // Warning: LocalAddress is null if the radio is powered-off.
            Console.WriteLine("* Radio, address: {0:C}", myRadio.LocalAddress);

            // mac is mac address of local bluetooth device
             localEndpoint = new BluetoothEndPoint(myRadio.LocalAddress, BluetoothService.SerialPort);
            // client is used to manage connections
            bluetoothClient = new BluetoothClient(localEndpoint);
            // component is used to manage device discovery
            localComponent = new BluetoothComponent(bluetoothClient);
        }
        static BluetoothUtils()
        {
            // Define common Pin codes for Bluetooth devices

            PrimaryRadio = BluetoothRadio.PrimaryRadio;
            if (PrimaryRadio == null) {
                //Console.WriteLine("No radio hardware or unsupported software stack");
                return;
            }

            // Local bluetooth MAC address 
            var mac = PrimaryRadio.LocalAddress;
            if (mac == null) {
                //Console.WriteLine("No local Bluetooth MAC address found");
                return;
            }
            DeviceList = new List<BluetoothDeviceInfo>();
            // mac is mac address of local bluetooth device
            //LocalEndpoint = new BluetoothEndPoint(mac, BluetoothService.SerialPort);
            LocalEndpoint = new BluetoothEndPoint(mac, Guid);             
            // client is used to manage connections
            LocalClient = new BluetoothClient(LocalEndpoint);
        }
Example #6
0
 /// <summary>
 /// 检查电脑端的蓝牙设备是否存在
 /// </summary>
 /// <returns></检查正确择返回真>
 private bool checkBluetooth()
 {
     radio = BluetoothRadio.PrimaryRadio;
     if (radio == null)
         return false;
     if (radio.Mode == RadioMode.PowerOff)
         return false;
     radio.Mode = RadioMode.Discoverable;
     return true;
 }
 /// <summary>
 /// Create a new ZomB FingerServer Factory
 /// </summary>
 /// <param name="teamNumber">Your team number</param>
 /// <param name="from">Path to saved data folder</param>
 /// <param name="to">Save data to this folder</param>
 /// <remarks>
 /// The path should be a reference to a folder that contains all the data files.
 /// Once all the files are sent, the tag .ZomBarchiveXXX is appended to their file name, where
 /// XXX is the time ticks.
 /// The To path works similarly, but .ZomBYYY is appended before the file extension, where 
 /// YYY is the transfer number stored in the file .ZomB in the To path
 /// </remarks>
 internal BTZomBFingerFactory(int teamNumber, string from, string to)
 {
     //AutoExtractor.Extract(AutoExtractor.Files.InTheHandManaged | AutoExtractor.Files.InTheHandNative);
     saveTo = to;
     pullFrom = from;
     //team GUID, last part is random, don't want to calculate
     if (teamgid != null)
         teamgid = new Guid(teamNumber * teamNumber, (short)teamNumber, (short)teamNumber, new byte[] { 0xa1, 0xfc, 0xf7, 0x95, 0x4a, 0x58, 0x6f, 0x25 });
     radio = InTheHand.Net.Bluetooth.BluetoothRadio.PrimaryRadio;
     listen = new BluetoothListener(teamgid);
     bserve = new BTZomBServer(listen, pullFrom, teamNumber, this);
     radio.Mode = RadioMode.Connectable;
     client = new BluetoothClient();
     bfinger = new BTFinger(client, saveTo, teamNumber, this);
     TeamNumber = teamNumber;
 }
        public void showRadioInfo(BluetoothRadio radio = null)
        {
            if (radio == null)
            {
                radio = BluetoothRadio.PrimaryRadio;
            }

            if (radio != null)
            {
                RadioMode mode = radio.Mode;
                Console.WriteLine("***************************");
                Console.WriteLine("Name: " + radio.Name);
                Console.WriteLine("Manufacturer: " + radio.Manufacturer);
                Console.WriteLine("Class of device: " + radio.ClassOfDevice);
                Console.WriteLine("Hardware status: " + radio.HardwareStatus);
                Console.WriteLine("Local address: " + radio.LocalAddress);
                Console.WriteLine("Software Manufacturer: " + radio.SoftwareManufacturer);
            }
            else
            {
                Console.WriteLine("No primary radio");
            }
        }
Example #9
0
 public BluetoothWin32Events(BluetoothRadio microsoftWin32BluetoothRadio)
     : this()
 {
 }
Example #10
0
        public static bool initialise()
        {
            try
            {
                localRadio = BluetoothRadio.PrimaryRadio;
                if (null == localRadio)
                {
                    lastError = "There is no Bluetooth hardware, or it uses unsupported software.";
                    return false;
                }
                localRadioInfo = new BluetoothDeviceInfo(localRadio.LocalAddress);
                if (null == localRadioInfo)
                {
                    lastError = "Bluetooth hardware exists, but failed to attach.";
                    return false;
                }
                localRadio.Mode = RadioMode.Discoverable;

                setServices();
                if (bluetoothServiceItems.Count > 0) service = bluetoothServiceItems[0].name;

                setDevices();
                if (bluetoothDeviceInfos.Count > 0) device = bluetoothDeviceInfos[0].DeviceName;

                BluetoothWin32Events.GetInstance().InRange += new EventHandler<BluetoothWin32RadioInRangeEventArgs>(inRangeEvent);
                BluetoothWin32Events.GetInstance().OutOfRange += new EventHandler<BluetoothWin32RadioOutOfRangeEventArgs>(outOfRangeEvent);
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                lastError = ex.Message;
                return false;
            }
            return true;
        }