public override async Task <List <IBluetoothDevice> > GetPairedDevices() { var devices = new List <IBluetoothDevice>(); var bluetoothDevices = await GetBluetoothPairedDevices(); var serialPortDevices = await GetSerialPortDevices(); foreach (var deviceInfo in bluetoothDevices) { var address = GetAddress(deviceInfo); if (!string.IsNullOrEmpty(address)) { var bluetoothDevice = new UWPBluetoothDevice() { Name = deviceInfo.Name, Address = address }; var trimmedAddress = address.Replace(":", ""); ulong t = Convert.ToUInt64(trimmedAddress, 16); var bluetoothDeviceQuery = await BluetoothDevice.FromBluetoothAddressAsync(t); bluetoothDevice.BluetoothDeviceReference = bluetoothDeviceQuery; var serialQuery = serialPortDevices.FirstOrDefault(x => x.Id.Contains(deviceInfo.Id)); if (serialQuery != null) { var identifiers = GetUniqueIdentifiers(serialQuery); bluetoothDevice.UniqueIdentifiers.AddRange(identifiers); } devices.Add(bluetoothDevice); } } return(devices); }
public override async Task <List <IBluetoothDevice> > GetPairedDevices() { var devices = new List <IBluetoothDevice>(); var selector = BluetoothDevice.GetDeviceSelector(); DeviceInformationCollection DeviceInfoCollection = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort)); foreach (var deviceInfo in DeviceInfoCollection) { var device = new UWPBluetoothDevice() { Name = deviceInfo.Name, Address = string.Empty }; device.BluetoothDevice = deviceInfo; var id = string.Empty; if (deviceInfo.Id.Contains("BTHENUM#{")) { var index = deviceInfo.Id.IndexOf("BTHENUM#{") + 9; id = deviceInfo.Id.Substring(index, 36); } if (!String.IsNullOrEmpty(id)) { var guid = Guid.Parse(id); device.UniqueIdentifiers.Add(guid); } devices.Add(device); } return(devices); }