private async void RfcommScanner_Added(object sender, Bluetooth.IBluetoothDevice e)
        {
            if (e.Address == BluetoothUtils.AddressStringToInt64("DC:53:60:DD:AE:63"))
            {
                //var serviceResult = await e.GetRfcommServicesAsync();
                await e.RfcommConnectAsync();

                //var serviceResult = await e.GetRfcommServicesForIdAsync(Constants.ServiceId);
                var serviceResult = await e.GetRfcommServicesAsync();

                IRfcommDeviceService service = null;
                if (serviceResult.Error == BluetoothError.Success && serviceResult.Services.Count > 0)
                {
                    foreach (var ser in serviceResult.Services)
                    {
                        if (ser.ServiceId == Constants.ServiceId)
                        {
                            service = ser;
                            break;
                        }
                    }
                }
                if (service == null)
                {
                    return;
                }
                var connection = new RfcommRXConnection(service, ConnectionGroup);
                OnConnectionReceived?.Invoke(this, connection);
            }
        }
        public RXConnPage()
        {
            ReceiveMessageList = new ObservableCollection <string>();
            InitializeComponent();
            ReceiveListView.ItemsSource = ReceiveMessageList;
            IManagerManager managerManager = DependencyService.Get <IManagerManager>();

            BluetoothManager    = managerManager.BluetoothManager;
            RXConnectionManager = managerManager.RXConnectionManager;

            LocalConnectionGroup localConnectionGroup = new LocalConnectionGroup(RXConnectionManager);

            RXConnectionManager.AddConnectionGroup(localConnectionGroup);

            RfcommRXConnectionGroup rfcommConnectionGroup = new RfcommRXConnectionGroup(BluetoothManager, RXConnectionManager);

            RXConnectionManager.AddConnectionGroup(rfcommConnectionGroup);
            RXConnectionManager.OnReceived += RXConnectionManager_OnReceived;

            Dictionary <string, byte[]> pairs = new Dictionary <string, byte[]>();

            pairs.Add("DeviceName", Encoding.UTF8.GetBytes("MY MACHINE"));
            pairs.Add("DeviceId", Guid.NewGuid().ToByteArray());
            pairs.Add("Rfcomm.N", Encoding.UTF8.GetBytes("XEON-J-LAPTOP-1"));
            pairs.Add("Rfcomm.A", BitConverter.GetBytes(BluetoothUtils.AddressStringToInt64("DC:53:60:DD:AE:63")));
            (localConnectionGroup.Scanner as LocalConnectionScanner).AddConnection(pairs);
        }
Esempio n. 3
0
 public object ConvertBack(object value, Type targetType, object parameter, string language)
 {
     try
     {
         return(BluetoothUtils.AddressStringToInt64(targetType.ToString()));
     }
     catch (Exception)
     {
         return(0ul);
     }
 }
Esempio n. 4
0
 public static BluetoothDeviceWrapper GetFromAddress(this IEnumerable <BluetoothDeviceWrapper> bluetoothDevices, string macAddress)
 {
     foreach (var device in bluetoothDevices)
     {
         if (BluetoothUtils.AddressStringToInt64(macAddress) == device.Address)
         {
             return(device);
         }
     }
     return(null);
 }
Esempio n. 5
0
        internal RXBluetoothDevice GetBluetoothDeviceFromDeviceInformation(DeviceInformation deviceInformation)
        {
            ulong address = BluetoothUtils.AddressStringToInt64(RXBluetoothUtils.GetAddressStringFromDeviceId(deviceInformation.Id));

            foreach (var device in _BluetoothDeviceList)
            {
                if (device.Address == address)
                {
                    return(device);
                }
            }
            RXBluetoothDevice rxBluetoothDevice = new RXBluetoothDevice(this, deviceInformation);

            _BluetoothDeviceList.Add(rxBluetoothDevice);
            return(rxBluetoothDevice);
        }
Esempio n. 6
0
        internal RXBluetoothDevice RemoveBluetoothDeviceFromDeviceInformationUpdate(DeviceInformationUpdate deviceInformationUpdate)
        {
            ulong             address             = BluetoothUtils.AddressStringToInt64(RXBluetoothUtils.GetAddressStringFromDeviceId(deviceInformationUpdate.Id));
            RXBluetoothDevice deviceReadyToDelete = null;

            foreach (var device in _BluetoothDeviceList)
            {
                if (device.Address == address)
                {
                    deviceReadyToDelete = device;
                    break;
                }
            }
            if (deviceReadyToDelete != null)
            {
                _BluetoothDeviceList.Remove(deviceReadyToDelete);
            }
            return(deviceReadyToDelete);
        }