getDeviceSelector上的ArgumentException

时间:2016-03-30 14:43:09

标签: c# bluetooth

我正在使用C#查找靠近我的Windows Phone的蓝牙设备,但我不仅仅是卡住了。我现在的代码如下:

class BluetoothImplementation
{
    public BluetoothLEDevice currentDevice { get; set; }
    public List<string> deviceList = new List<string>();
    public List<string> serviceList = new List<string>();
    public List<string> characteristicList = new List<string>();
    private GattCharacteristic selectedCharacteristic;
    private GattDeviceService selectedService;

    private const int CHARACTERISTIC_INDEX = 0;
    private const GattClientCharacteristicConfigurationDescriptorValue CHARACTERISTIC_NOTIFICATION_TYPE = GattClientCharacteristicConfigurationDescriptorValue.Notify;

    public async Task<List<string>> getDevices()
    {
        foreach (DeviceInformation di in await DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelector()))
        {
            BluetoothLEDevice bleDevice = await BluetoothLEDevice.FromIdAsync(di.Id);
            deviceList.Add(bleDevice.Name);
        }
        return deviceList;
    }
}

我在“Bluetooth.getDeviceSelector()”上遇到错误。 Althoug Visual Studio告诉我没关系,当我编译时遇到System.ArgumentException错误。我尝试通过执行以下操作来修复它:

foreach (DeviceInformation di in await DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelector(RfcommServiceId.SerialPort)))

这不能解决问题,也不会解决以下问题:

foreach (DeviceInformation di in await DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelector(RfcommServiceId.ObexObjectPush)))

我按下按钮执行代码。代码如下:

private async void bluetoothTest_Click(object sender, RoutedEventArgs e)
{
    BluetoothImplementation bi = new BluetoothImplementation();
    await bi.getDevices();
    System.Diagnostics.Debug.WriteLine(bi.deviceList.ToString());
}

任何帮助表示赞赏!提前谢谢!

0 个答案:

没有答案