/// <summary> /// 连接到指定的蓝牙设备的RFComm服务 /// </summary> /// <param name="BL">要连接到的设备</param> /// <returns>主机对象的规范名称</returns> public async Task <string> ConnectToRfcommServiceAsync(BluetoothDeivceData BL) { if (BL == null) { throw new ArgumentNullException(nameof(BL), "Parameter could not be null"); } try { using (Windows.Devices.Bluetooth.BluetoothDevice Device = await Windows.Devices.Bluetooth.BluetoothDevice.FromIdAsync(BL.Id)) { RfcommDeviceServicesResult Services = await Device.GetRfcommServicesForIdAsync(RfcommServiceId.ObexObjectPush); if (Services.Services.Any()) { return(Services.Services.Select((Service) => Service.ConnectionHostName?.CanonicalName).Where((Name) => !string.IsNullOrEmpty(Name)).FirstOrDefault()); } else { throw new Exception(Globalization.GetString("BluetoothUI_Tips_Text_3")); } } } catch { throw new Exception(Globalization.GetString("BluetoothUI_Tips_Text_2")); } }
private void _device_NameChanged(Windows.Devices.Bluetooth.BluetoothDevice sender, object args) { RaiseNameChanged(); }
private void _device_ConnectionStatusChanged(Windows.Devices.Bluetooth.BluetoothDevice sender, object args) { _connectionStatusChanged?.Invoke(this, EventArgs.Empty); }
private BluetoothDevice(Windows.Devices.Bluetooth.BluetoothDevice device) { _device = device; }
public static string BluetoothAddressAsString(this Windows.Devices.Bluetooth.BluetoothDevice dev) { return(Regex.Replace(dev.BluetoothAddress.ToString("X12"), "(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})", "$1:$2:$3:$4:$5:$6")); }