Ejemplo n.º 1
0
        /// <summary> Switch Bluetooth Radio On and Off. </summary>
        /// <param name="State"> The new Bluetooth Radio state. </param>
        /// <returns> The function returns <c>True</c> if operation has been completed
        ///   with success. Otherwise the function returns <c>False</c>. </returns>
        /// <remarks> If is required that your application targets Windows platform.
        ///   That means that on x64 bit Windows your application must run as x64.
        ///   Otherwise the function returns <c>False</c>. That is because of
        ///   Windows Bluetooth Manager implementation. </remarks>
        /// <seealso cref="BluetoothRadioState" />
        public static Boolean SwitchBluetooth(BluetoothRadioState State)
        {
            IRadioInstance Radio;
            Boolean        Result = GetRadioInstance(out Radio);

            if (Result)
            {
                DEVICE_RADIO_STATE SysState;
                if (State == BluetoothRadioState.rsOn)
                {
                    SysState = DEVICE_RADIO_STATE.DRS_RADIO_ON;
                }
                else
                {
                    SysState = DEVICE_RADIO_STATE.DRS_SW_RADIO_OFF;
                }
                Result = Succeeded(Radio.SetRadioState(SysState, 10));
                Radio  = null;
            }
            return(Result);
        }
Ejemplo n.º 2
0
        /// <summary> Gets the current Bluetooth Radio state. </summary>
        /// <param name="State"> If the function completed with success on output
        ///   indicates the current Bluetooth Radio State. </param>
        /// <returns> The function returns <c>True</c> if operation has been completed
        ///   with success. Otherwise the function returns <c>False</c>. </returns>
        /// <remarks> If is required that your application targets Windows platform.
        ///   That means that on x64 bit Windows your application must run as x64.
        ///   Otherwise the function returns <c>False</c>. That is because of
        ///   Windows Bluetooth Manager implementation. </remarks>
        /// <seealso cref="BluetoothRadioState" />
        public static Boolean GetBluetoothState(out BluetoothRadioState State)
        {
            State = BluetoothRadioState.tsOff;

            IRadioInstance Radio;
            Boolean        Result = GetRadioInstance(out Radio);

            if (Result)
            {
                DEVICE_RADIO_STATE SysState;
                if (Succeeded(Radio.GetRadioState(out SysState)))
                {
                    if (SysState == DEVICE_RADIO_STATE.DRS_RADIO_ON)
                    {
                        State = BluetoothRadioState.rsOn;
                    }
                    Result = true;
                }
                Radio = null;
            }
            return(Result);
        }