Exemplo n.º 1
0
        public void VideoDistribution()
        {
            //Guid uuid = BluetoothService.VideoDistribution ;
            Guid uuid = new Guid(0x1305, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb);

            Assert.AreEqual("VideoDistribution", BluetoothService.GetName(uuid));
        }
Exemplo n.º 2
0
        public void OPP()
        {
            //Guid uuid = BluetoothService.ObexObjectPush;
            Guid uuid = new Guid(0x1105, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb);

            Assert.AreEqual("ObexObjectPush", BluetoothService.GetName(uuid));
        }
Exemplo n.º 3
0
        public void PdlNonHackProtocolId_Avctp()
        {
            //const UInt16 SvcClass16Avcrp = 0x110E;
            const UInt16 SvcClass16AvcrpController_ = 0x110F;
            Guid         SvcClass128AvcrpController = BluetoothService.CreateBluetoothUuid(SvcClass16AvcrpController_);
            //
            const UInt16 SvcClass16ProtocolL2CAP = 0x0100;
            //Debug_Assert_CorrectShortUuid(SvcClass16ProtocolL2CAP, BluetoothService.L2CapProtocol);
            const UInt16 SvcClass16ProtocolAvctp = 0x0017;
            //Debug_Assert_CorrectShortUuid(SvcClass16ProtocolAvctp, BluetoothService.AvctpProtocol);
            //
            const UInt16 PsmAvcrp = 0x0017;
            //const UInt16 PsmAvcrpBrowsing = 0x001B;
            //
            const UInt16 Version = 0x0103; // 1.3.......
            //
            var layer0 = new ServiceElement(ElementType.ElementSequence,
                                            new ServiceElement(ElementType.Uuid16, SvcClass16ProtocolL2CAP),
                                            new ServiceElement(ElementType.UInt16, PsmAvcrp));
            var layer1 = new ServiceElement(ElementType.ElementSequence,
                                            new ServiceElement(ElementType.Uuid16, SvcClass16ProtocolAvctp),
                                            new ServiceElement(ElementType.UInt16, Version));
            ServiceElement pdl = new ServiceElement(ElementType.ElementSequence,
                                                    layer0, layer1);

            ServiceRecord record = new ServiceRecord(
                new ServiceAttribute(UniversalAttributeId.ProtocolDescriptorList, pdl));

            DumpCompleteThirdPartyRecords.DoTestSmart(PdlNonHackProtocolId_Dump, record);
        }
        private void ConnectToBluetoothDevice()
        {
            ICollection <BluetoothDevice> pairedDevices = btAdapter.BondedDevices;

            if (pairedDevices.Count > 0)
            {
                foreach (BluetoothDevice device in pairedDevices)
                {
                    string name    = device.Name;
                    string address = device.Address;
                    Logger.Log($"Name: {name}\nAddress: {address}");
                    if (name == "AKO SI BLUETOOTH")
                    {
                        btDevice = device;
                        break;
                    }
                }
            }

            // TODO AUTO ON NARIN UNG BLUETOOTH BAGO GAWIN TO PARA DIRE-DIRETSO
            handler          = new BluetoothHandler(this);
            btService        = new BluetoothService(this, handler);
            btService.BtUUID = btDevice.GetUuids()[0].Uuid;

            // connect na
            //btService.StartClient(btDevice);
        }
Exemplo n.º 5
0
        public override void OnConnect()
        {
            Console.WriteLine("Device Connected!");

            Windesheart.PairedDevice = this;

            //Check if bluetooth-state changes to off and then on, to enable reconnection management
            BluetoothService.StartListeningForAdapterChanges();

            Characteristics?.Clear();

            CharacteristicDisposable?.Dispose();
            //Find unique characteristics
            CharacteristicDisposable = IDevice.WhenAnyCharacteristicDiscovered().Subscribe(async characteristic =>
            {
                if (characteristic != null && !Characteristics.Contains(characteristic))
                {
                    Characteristics.Add(characteristic);

                    //Check if authCharacteristic has been found, then authenticate
                    if (characteristic.Uuid == MiBand3Resource.GuidCharacteristicAuth)
                    {
                        //Check if this is a new connection that needs authentication
                        await _authenticationService.Authenticate();
                    }
                }
            });
        }
Exemplo n.º 6
0
        //----------------
        /// <summary>
        /// Attempt to create a Bluetooth UUID from user input either in 128-bit
        /// UUID form or integer short-form.
        /// </summary>
        /// <param name="line">The user input.</param>
        /// <param name="result"></param>
        /// <returns><see langword="true"/> if a valid UUID was input,
        /// <see langword="false"/> otherwise.
        /// </returns>
        protected bool BluetoothService_TryParseIncludingShortForm(string line, out Guid result)
        {
            if (Guid_TryParse(line, out result))
            {
                return(true);
            }
            UInt32 u32;

#if !NETCF
            if (UInt32.TryParse(line, NumberStyles.HexNumber, CultureInfo.InvariantCulture,
                                out u32))
            {
                result = BluetoothService.CreateBluetoothUuid(u32);
                return(true);
            }
            return(false);
#else
            try {
                u32 = UInt32.Parse(line, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
            } catch (FormatException) {
                return(false);
            }
            result = BluetoothService.CreateBluetoothUuid(u32);
            return(true);
#endif
        }
Exemplo n.º 7
0
 public static void SendValue(String value)
 {
     if (IsConnected)
     {
         BluetoothService.WritetoBluetooth(value);
     }
 }
Exemplo n.º 8
0
 public void Empty()
 {
     // Should it special-case Empty and return null?
     Assert.AreEqual("Empty",
                     //Assert.IsNull(
                     BluetoothService.GetName(Guid.Empty));
 }
        protected override void OnStart()
        {
            base.OnStart();
            handler   = new BluetoothHandler(this);
            btService = new BluetoothService(this, handler);

            TurnOnBluetooth();
        }
Exemplo n.º 10
0
 public static void StartConnection()
 {
     if (!IsConnected)
     {
         //print(deviceName);
         IsConnected = BluetoothService.StartBluetoothConnection(deviceName);
     }
 }
Exemplo n.º 11
0
 public void StopButton()
 {
     if (IsConnected)
     {
         BluetoothService.StopBluetoothConnection();
     }
     Application.Quit();
 }
        public void FromUuid_AgHandfree()
        {
            Type enumClass = new GiveAccess_SdpClassToAttributeIdList().GetAttributeIdEnumType(
                BluetoothService.CreateBluetoothUuid(0x111F));

            Assert.IsNotNull(enumClass);
            Assert.AreEqual("HandsFreeProfileAttributeId", enumClass.Name);
        }
Exemplo n.º 13
0
        public async Task EnumerateDevicesAsync()
        {
            BluetoothService btService = BluetoothService.GetDefault();

            btService.SearchForPairedDevicesFailed    += btService_SearchForPairedDevicesFailed;
            btService.SearchForPairedDevicesSucceeded += btService_SearchForPairedDevicesSucceeded;
            await btService.SearchForPairedDevicesAsync();
        }
        public void FromUuid_Opp()
        {
            Type enumClass = new GiveAccess_SdpClassToAttributeIdList().GetAttributeIdEnumType(
                BluetoothService.CreateBluetoothUuid(0x1105));

            Assert.IsNotNull(enumClass);
            Assert.AreEqual("ObexAttributeId", enumClass.Name);
        }
Exemplo n.º 15
0
        private async void QueueContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            var Deferral = args.GetDeferral();

            try
            {
                if (BluetoothControl.SelectedIndex == -1 || !BluetoothDeviceCollection[BluetoothControl.SelectedIndex].DeviceInfo.Pairing.IsPaired)
                {
                    Tips.Text       = Globalization.GetString("BluetoothUI_Tips_Text_1");
                    Tips.Visibility = Visibility.Visible;
                    args.Cancel     = true;
                }
                else
                {
                    //首先连接到RFComm服务,获取到设备的规范名称
                    string CanonicalName = await ConnectToRfcommServiceAsync(BluetoothDeviceCollection[BluetoothControl.SelectedIndex]).ConfigureAwait(true);

                    BluetoothService BTService = BluetoothService.GetDefault();
                    BTService.SearchForPairedDevicesSucceeded += BTService_SearchForPairedDevicesSucceeded;

                    void BTService_SearchForPairedDevicesSucceeded(object sender, SearchForPairedDevicesSucceededEventArgs e)
                    {
                        BTService.SearchForPairedDevicesSucceeded -= BTService_SearchForPairedDevicesSucceeded;

                        if (e.PairedDevices.FirstOrDefault((Device) => Device.DeviceHost.CanonicalName == CanonicalName) is BluetoothDevice BTDevice)
                        {
                            ObexServiceProvider.SetObexInstance(BTDevice, BluetoothDeviceCollection[BluetoothControl.SelectedIndex].Name);

                            if (ObexServiceProvider.GetObexInstance() == null)
                            {
                                throw new Exception(Globalization.GetString("BluetoothUI_Tips_Text_2"));
                            }
                        }
                        else
                        {
                            throw new Exception(Globalization.GetString("BluetoothUI_Tips_Text_2"));
                        }
                    }

                    //能到这里说明该设备已经配对,启动搜索,完成后PairedBluetoothDeviceCollection被填充
                    await BTService.SearchForPairedDevicesAsync().ConfigureAwait(true);
                }
            }
            catch (Exception e)
            {
                args.Cancel = true;

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    Tips.Text       = e.Message;
                    Tips.Visibility = Visibility.Visible;
                });
            }
            finally
            {
                Deferral.Complete();
            }
        }
Exemplo n.º 16
0
 protected internal override void onDestroy()
 {
     base.onDestroy();
     if (mService != null)
     {
         mService.stop();
     }
     mService = null;
 }
Exemplo n.º 17
0
    // Start is called before the first frame update
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }

        IsConnected = false;
        BluetoothService.CreateBluetoothObject();
    }
Exemplo n.º 18
0
 protected internal override void onDestroy()
 {
     base.onDestroy();
     if (mService != null)
     {
         mService.cancelDiscovery();
     }
     mService = null;
     this.unregisterReceiver(mReceiver);
 }
        public SearchingDevicePageViewModel(DataContext mMContext, BluetoothService bluetoothService, INavigationService navigation)
        {
            _mMContext        = mMContext;
            _bluetoothService = bluetoothService;
            _navigation       = navigation;

            Devices = new ObservableCollection <IDevice>();
            IsBusy  = false;
            Subscribe();
        }
Exemplo n.º 20
0
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string temp = string.Empty;

            foreach (var guid in value as Guid[])
            {
                string name = BluetoothService.GetName(guid);
                temp += (string.IsNullOrEmpty(name) ? guid.ToString() : name) + ", ";
            }
            return(temp);
        }
Exemplo n.º 21
0
        public void SetServiceStateDoIt(Guid service, bool state)
        {
            UInt16?classId16 = BluetoothService.GetAsClassId16(service);

            if (!classId16.HasValue)
            {
                throw new ArgumentException("BlueSoleil only supports standard Bluetooth UUID16 services.");
            }
            //
            // MSDN says the posible errors are:
            //   ERROR_INVALID_PARAMETER The dwServiceFlags are invalid.
            //   ERROR_SERVICE_DOES_NOT_EXIST The GUID specified in pGuidService is not supported.
            // Numerically:
            //   #define ERROR_FILE_NOT_FOUND             2L
            //   #define ERROR_SERVICE_DOES_NOT_EXIST     1060L
            //   #define ERROR_NOT_FOUND                  1168L
            //
            // Seen:
            // • 0x00000424 = 1060 ----> ERROR_SERVICE_DOES_NOT_EXIST
            // When service not present, or device not present.
            //
            // • 0x80070002        -/\-> ERROR_FILE_NOT_FOUND
            // PANU on Broadcom peer.  "No driver for service"?
            //
            // • 0x00000490 = 1168 ----> ERROR_NOT_FOUND
            // Setting 'False' on a service not set previously registered.
            //--
            BtSdkError ret;

            if (state)
            {
                UInt32 hConn;
                ret = _factory.Api.Btsdk_ConnectEx(_hDev, classId16.Value, 0, out hConn);
                if (ret != BtSdkError.OK)
                {
                    throw new Win32Exception((int)Win32Error.ERROR_SERVICE_DOES_NOT_EXIST, "Failed to enable the service.");
                }
            }
            else
            {
                var hConnList = FindConnection(_hDev, classId16.Value);
                if (hConnList == null || hConnList.Count == 0)
                {
                    throw new Win32Exception((int)Win32Error.ERROR_NOT_FOUND, "No matching enabled service found.");
                }
                // TO-DO SetServiceState, before disabling, ensure its not BluetoothClient's connection.
                Debug.Assert(hConnList.Count == 1, "SetServiceState: What to do if more than one match?");
                ret = _factory.Api.Btsdk_Disconnect(hConnList[0]);
                if (ret != BtSdkError.OK)
                {
                    throw new Win32Exception((int)Win32Error.ERROR_SERVICE_DOES_NOT_EXIST, "Failed to disabled the service.");
                }
            }
        }
Exemplo n.º 22
0
 protected List <BluetoothDevice> getBTDevicesInRangeAndRecognized()
 {
     BluetoothService.Mode = BluetoothService.BluetoothMode.MONITORING;
     try
     {
         return(BluetoothService.GetAvailableBluetoothDevices().ToList());
     }
     catch (InvalidOperationException)
     {
         return(new List <BluetoothDevice>());
     }
 }
Exemplo n.º 23
0
        private const int REQUEST_CONNECT_DEVICE = 1;         //��ȡ�豸��Ϣ



        /// <summary>
        /// Called when the activity is first created. </summary>
        public override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);
            ContentView = R.layout.main;
            mService    = new BluetoothService(this, mHandler);
            //�����������˳�����
            if (mService.Available == false)
            {
                Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
                finish();
            }
        }
Exemplo n.º 24
0
		private const int REQUEST_CONNECT_DEVICE = 1; //��ȡ�豸��Ϣ



		/// <summary>
		/// Called when the activity is first created. </summary>
		public override void onCreate(Bundle savedInstanceState)
		{
			base.onCreate(savedInstanceState);
			ContentView = R.layout.main;
			mService = new BluetoothService(this, mHandler);
			//�����������˳�����
			if (mService.Available == false)
			{
				Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
				finish();
			}
		}
Exemplo n.º 25
0
        private void Init()
        {
            _bluetoothService         = new BluetoothService();
            devicesComBox.ItemsSource = _bluetoothService.GetDevices();

            aBtn.Click += async(s, e) => await DoAsync(Actions.A);

            bBtn.Click += async(s, e) => await DoAsync(Actions.B);

            cBtn.Click += async(s, e) => await DoAsync(Actions.C);

            dBtn.Click += async(s, e) => await DoAsync(Actions.D);

            startBtn.Click += async(s, e) => await DoAsync(Actions.Start);

            selectBtn.Click += async(s, e) => await DoAsync(Actions.Select);

            upBtn.Click += async(s, e) => await MoveAsync(Directions.Up);

            downBtn.Click += async(s, e) => await MoveAsync(Directions.Down);

            leftBtn.Click += async(s, e) => await MoveAsync(Directions.Left);

            rightBtn.Click += async(s, e) => await MoveAsync(Directions.Right);

            connectBtn.Click += async(s, e) =>
            {
                var port = devicesComBox.SelectedValue as string;
                if (port != null)
                {
                    if (!_bluetoothService.IsConnected)
                    {
                        connectBtn.IsEnabled = false;
                        connectBtn.Content   = "Disconnect";
                        await _bluetoothService.ConnectAsync(port);

                        connectBtn.IsEnabled = true;
                    }
                    else
                    {
                        connectBtn.IsEnabled = false;
                        connectBtn.Content   = "Connect";
                        _bluetoothService.Disconnect();
                        connectBtn.IsEnabled = true;
                    }
                }
            };

            refreshBtn.Click += (s, e) =>
            {
                devicesComBox.ItemsSource = _bluetoothService.GetDevices();
            };
        }
Exemplo n.º 26
0
        private void StartBluetoothService()
        {
            BluetoothManager manager  = (BluetoothManager)GetSystemService(Context.BluetoothService);
            BluetoothService bService = new BluetoothService(manager);

            if (!bService.IsEnabled)
            {
                Intent enableBtIntent = new Intent(BluetoothAdapter.ActionRequestEnable);
                StartActivityForResult(enableBtIntent, 1);
            }

            bService.StartScanning();
        }
Exemplo n.º 27
0
        private void BtnConnect_Click(object sender, EventArgs e)
        {
            btService = TransporterClass.bluetoothService;
            barBot    = TransporterClass.barBot;

            Button btnSend = FindViewById <Button>(Resource.Id.btnSend);

            btnSend.Clickable = true;
            btnSend.Enabled   = true;
            FindViewById <Button>(Resource.Id.btnDisConnect).Enabled   = true;
            FindViewById <Button>(Resource.Id.btnUpdateBottle).Enabled = true;
            FindViewById <Button>(Resource.Id.btnOrderDrink).Enabled   = true;
        }
Exemplo n.º 28
0
        private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            var Deferral = args.GetDeferral();

            if (BluetoothControl.SelectedIndex == -1 || !BluetoothDeviceCollection[BluetoothControl.SelectedIndex].DeviceInfo.Pairing.IsPaired)
            {
                Tips.Text       = "请先选择一个已配对的设备";
                Tips.Visibility = Visibility.Visible;
                args.Cancel     = true;
                Deferral.Complete();
                return;
            }


            try
            {
                //首先连接到RFComm服务,获取到设备的规范名称
                string CanonicalName = await ConnectToRfcommServiceAsync(BluetoothDeviceCollection[BluetoothControl.SelectedIndex]);

                BluetoothService BTService = BluetoothService.GetDefault();
                BTService.SearchForPairedDevicesSucceeded += (s, e) =>
                {
                    PairedBluetoothDeviceCollection = e.PairedDevices;
                };

                //能到这里说明该设备已经配对,启动搜索,完成后PairedBluetoothDeviceCollection被填充
                await BTService.SearchForPairedDevicesAsync();

                foreach (var BTDevice in from BTDevice in PairedBluetoothDeviceCollection
                         //找到符合刚刚RFComm服务获取到的规范名称的蓝牙设备
                         where BTDevice.DeviceHost.CanonicalName == CanonicalName
                         select BTDevice)
                {
                    //从该设备的BluetoothDevice对象获取到Obex服务的实例
                    ObexServiceProvider.SetObexInstance(BTDevice);
                    break;
                }

                if (ObexServiceProvider.GetObexNewInstance() == null)
                {
                    throw new Exception("未能找到已配对的设备,请打开该设备的蓝牙开关");
                }
            }
            catch (Exception e)
            {
                Tips.Text       = e.Message;
                Tips.Visibility = Visibility.Visible;
            }

            Deferral.Complete();
        }
Exemplo n.º 29
0
    public void SendButton()
    {
        if (IsConnected && (dataToSend.ToString() != "" || dataToSend.ToString() != null))
        {
            print(dataToSend.text);

            BluetoothService.WritetoBluetooth(dataToSend.text.ToString());
            dataToShown.text = dataToSend.text;
        }
        else
        {
            BluetoothService.WritetoBluetooth("@O");
            dataToShown.text = "@O";
        }
    }
Exemplo n.º 30
0
 public void StartButton()
 {
     if (!IsConnected)
     {
         //print(deviceName.text.ToString());
         IsConnected = BluetoothService.StartBluetoothConnection(str_DeviceName);
         if (IsConnected)
         {
             deviceName.text = str_DeviceName + " is Connected";
         }
         else
         {
             deviceName.text = str_DeviceName + " is Disconnected";
         }
     }
 }
Exemplo n.º 31
0
        public FinishPageViewModel(DataContext mMContext, BluetoothService bluetoothService, INavigationService navigation, MagicMirrorRepository magicMirrorRepository)
        {
            _mMContext        = mMContext;
            _bluetoothService = bluetoothService;
            _navigation       = navigation;

            if (_mMContext.Result)
            {
                Result = "Success connection";
                magicMirrorRepository.AddOrUpdate(_mMContext.MagicMiror);
            }
            else
            {
                Result = _mMContext.ErrorInfo;
            }
        }
Exemplo n.º 32
0
        public BluetoothConnection ConnectService(BluetoothService service)
        {
            ValidateThread();
            int connectionHandle = 0;
            NativeMethods.BTSTATUS status = NativeMethods.BT_ConnectService(service.Device.DeviceInfo, service.ServiceInfo, ref connectionHandle);
            ValidateStatus(status);
            BluetoothConnection connection = new BluetoothConnection(this, service, connectionHandle);

            lookupConnections.Add(connectionHandle, connection);
            connections.Add(connection);

            OnConnectionOpened(new BluetoothConnectionEventArgs(connection));
            return connection;
        }
Exemplo n.º 33
0
        private BluetoothService CreateService()
        {
            BluetoothService service = null;

            try
            {
                // check if Bluetooth-Stick is available
                if (BluetoothRadio.IsSupported)
                {
                    // Device visible for others
                    // RadioMode setting not supported as long as the
                    // WinCE image doesn't include the BthUtil.dll
                    //BluetoothRadio.PrimaryRadio.Mode =
                    //     BluetoothRadioMode.Discoverable;

                    // set device Name
                    BluetoothRadio.PrimaryRadio.Name = "AbflussRobot";
                    // desired service
                    Guid serviceId = BluetoothServiceList.Robot06;
                    //Guid serviceId = new Guid("{FB4B43E4-0328-4056-82A5-7E03BE347082}");

                    // start new service
                    service = new BluetoothService();
                    service.CreateService(serviceId);
                    Console.WriteLine("Service " + serviceId.ToString() + " started.");
                }
                else
                {
                    Console.WriteLine("No Bluetooth-Stick is available");
                    throw new BluetoothNotStartedException();
                    return null;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return service;
        }
Exemplo n.º 34
0
 internal BluetoothConnection(BluesoleilService owner, BluetoothService service, int connectionHandle)
 {
     this.owner = owner;
     this.service = service;
     this.connectionHandle = connectionHandle;
 }
Exemplo n.º 35
0
		protected internal override void onDestroy()
		{
			base.onDestroy();
			if (mService != null)
			{
				mService.stop();
			}
			mService = null;
		}
Exemplo n.º 36
0
 public BluetoothService[] BrowseServices(BluetoothDevice device)
 {
     ValidateThread();
     NativeMethods.GENERAL_SERVICE_INFO[] serviceInfos;
     NativeMethods.BTSTATUS status = NativeMethods.BT_BrowseServices(device.DeviceInfo, true, out serviceInfos);
     ValidateStatus(status);
     BluetoothService[] services = new BluetoothService[serviceInfos.Length];
     for (int i = 0; i < serviceInfos.Length; i++)
     {
         services[i] = new BluetoothService(this, device, serviceInfos[i]);
     }
     return services;
 }