Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Xabre Android分别在扫描和连接时变慢_C#_Xamarin_Bluetooth Lowenergy - Fatal编程技术网

C# Xabre Android分别在扫描和连接时变慢

C# Xabre Android分别在扫描和连接时变慢,c#,xamarin,bluetooth-lowenergy,C#,Xamarin,Bluetooth Lowenergy,我有一个应用程序,其中我使用Xabre库连接到一个BLE设备 在Android上(我在Galaxy A40和Galaxy S7上进行了测试),我体验到该应用程序需要花费大量时间分别进行扫描和连接 我已将扫描模式的延迟更改为ScanMode.LowLatency——这稍微增加了扫描时间。(尽管仍然不能接受) 此外,当设备连接到设备时,它会花费大量时间,并在连接之前重新连接数次。(是的,设备在附近,其他应用程序如LightBlue连接没有任何问题) 在连接期间,我已将ConnectParameter

我有一个应用程序,其中我使用Xabre库连接到一个BLE设备

在Android上(我在Galaxy A40和Galaxy S7上进行了测试),我体验到该应用程序需要花费大量时间分别进行扫描和连接

我已将扫描模式的延迟更改为
ScanMode.LowLatency
——这稍微增加了扫描时间。(尽管仍然不能接受)

此外,当设备连接到设备时,它会花费大量时间,并在连接之前重新连接数次。(是的,设备在附近,其他应用程序如LightBlue连接没有任何问题)

在连接期间,我已将ConnectParameters设置为
ConnectParameters(true,true)

我还没有用这个项目在iOS上测试过,但以前在iOS上使用过Xabre,我没有经历过类似的行为

我正在使用的以下代码是:

public async void Connect(IDevice unit)
{
    await adapter.StopScanningForDevicesAsync();
    try
    {
        var parameters = new ConnectParameters(true, true);
        await adapter.ConnectToDeviceAsync(unit, parameters);
        //Add device
        Bluetooth.Device = unit;
        Console.Write(unit.Id);
        //Add service and characteristics to Device object
        Bluetooth.Service = await Bluetooth.Device.GetServiceAsync(Guid.Parse(Service_UUID));
        Bluetooth.Characteristic = await Bluetooth.Service.GetCharacteristicAsync(Guid.Parse(Characteristic_UUID));
        Characteristic_ValueUpdated();
    }
    catch (DeviceConnectionException e)
    {
        Console.WriteLine("Error: " + e);
        Connect(unit);
    }
}
public async void Disconnect()
{
    try
    {
        await Characteristic.StopUpdatesAsync();
        await adapter.DisconnectDeviceAsync(Device);
    }
    catch
    {
    }
}
public async void Scan()
{
    adapter.ScanMode = ScanMode.LowLatency;
    adapter.DeviceDiscovered += (s, a) =>
    {
        if (a.Device.Name == "Device_name")
        {
                Connect(a.Device);
        }
    };
    await adapter.StartScanningForDevicesAsync();
}

在Galaxy S7上,运行速度通常会快一些,但我仍然会经历几次重新连接。

尝试设置扫描时间限制,这会有什么帮助?我的BLE设备有一个nRF51802芯片。我想这可能就是困扰我的原因。