/// <summary> /// 连接到指定的蓝牙设备的RFComm服务 /// </summary> /// <param name="BL">要连接到的设备</param> /// <returns>主机对象的规范名称</returns> public async Task <string> ConnectToRfcommServiceAsync(BluetoothList BL) { if (BL == null) { throw new ArgumentNullException(nameof(BL), "Parameter could not be null"); } try { var Device = await Windows.Devices.Bluetooth.BluetoothDevice.FromIdAsync(BL.Id); var Services = await Device.GetRfcommServicesForIdAsync(RfcommServiceId.ObexObjectPush); if (Services.Services.Count == 0) { throw new Exception(Globalization.GetString("BluetoothUI_Tips_Text_3")); } RfcommDeviceService RfcService = Services.Services[0]; return(RfcService.ConnectionHostName.CanonicalName); } catch { throw new Exception(Globalization.GetString("BluetoothUI_Tips_Text_2")); } }
/// <summary> /// 连接到指定的蓝牙设备的RFComm服务 /// </summary> /// <param name="BL">要连接到的设备</param> /// <returns>主机对象的规范名称</returns> public async Task <string> ConnectToRfcommServiceAsync(BluetoothList BL) { var Device = await Windows.Devices.Bluetooth.BluetoothDevice.FromIdAsync(BL.Id); var Services = await Device.GetRfcommServicesForIdAsync(RfcommServiceId.ObexObjectPush); if (Services.Services.Count == 0) { throw new Exception("无法发现蓝牙设备的ObexObjectPush服务,该设备不受支持"); } RfcommDeviceService RfcService = Services.Services[0]; return(RfcService.ConnectionHostName.CanonicalName); }