RxAndroidBLE 执行 BLE 扫描无需排队扫描操作
RxAndroidBLE perform BLE scan without queueing scan operation
在我的应用程序中,我使用了 RxAndroidBLE 库。感谢很棒的图书馆。但我有一些问题。我正在尝试使用
连接到 BLE 设备
rxBleDevice.establishConnection(false)
设备超出范围。连接操作超时为 30 秒。同时我想使用
发现其他设备
rxBleClient.scanBleDevices(scanSettings)
但是扫描操作正在排队,将在连接操作超时(30 秒)后执行。我可以在日志中看到此行为:
08-01 17:25:59.978 : QUEUED ConnectOperation(155884145)
08-01 17:25:59.981 : STARTED ConnectOperation(155884145)
08-01 17:25:59.989 : Connecting without reflection
08-01 17:26:15.585 : QUEUED ScanOperationApi21(75017989)
08-01 17:26:18.353 : onConnectionStateChange newState=0 status=133
08-01 17:26:18.361 : Connection operations queue to be terminated (C3:27:5F:B2:60:C9)
08-01 17:26:18.363 : Terminated.
08-01 17:26:18.370 : FINISHED ConnectOperation(155884145) in 18385 ms
08-01 17:26:18.377 : STARTED ScanOperationApi21(75017989)
08-01 17:26:18.379 : Scan operation is requested to start.
08-01 17:26:18.381 : QUEUED DisconnectOperation(41108292)
08-01 17:26:18.398 : FINISHED ScanOperationApi21(75017989) in 26 ms
08-01 17:26:18.401 : STARTED DisconnectOperation(41108292)
08-01 17:26:18.410 : FINISHED DisconnectOperation(41108292) in 10 ms
这是正确的预期行为吗?我能以某种方式立即开始扫描操作而无需排队吗?
Is this correct and expected behavior?
是的,这是预期的行为。一些 BLE 堆栈实现没有很好地处理可能导致 status=133
的同时扫描和连接。 It is still advised to not to do it.
And can I somehow start scan operation immediately without queueing?
在使用 RxAndroidBle
时,每个扫描操作都在主客户端队列中排队。在牢记上述警告的同时,您可以尝试使用 autoConnect=true
的连接,这不会长时间阻塞主客户端队列。
或者您可以使用 vanilla Android API 来执行扫描。
在我的应用程序中,我使用了 RxAndroidBLE 库。感谢很棒的图书馆。但我有一些问题。我正在尝试使用
连接到 BLE 设备rxBleDevice.establishConnection(false)
设备超出范围。连接操作超时为 30 秒。同时我想使用
发现其他设备rxBleClient.scanBleDevices(scanSettings)
但是扫描操作正在排队,将在连接操作超时(30 秒)后执行。我可以在日志中看到此行为:
08-01 17:25:59.978 : QUEUED ConnectOperation(155884145)
08-01 17:25:59.981 : STARTED ConnectOperation(155884145)
08-01 17:25:59.989 : Connecting without reflection
08-01 17:26:15.585 : QUEUED ScanOperationApi21(75017989)
08-01 17:26:18.353 : onConnectionStateChange newState=0 status=133
08-01 17:26:18.361 : Connection operations queue to be terminated (C3:27:5F:B2:60:C9)
08-01 17:26:18.363 : Terminated.
08-01 17:26:18.370 : FINISHED ConnectOperation(155884145) in 18385 ms
08-01 17:26:18.377 : STARTED ScanOperationApi21(75017989)
08-01 17:26:18.379 : Scan operation is requested to start.
08-01 17:26:18.381 : QUEUED DisconnectOperation(41108292)
08-01 17:26:18.398 : FINISHED ScanOperationApi21(75017989) in 26 ms
08-01 17:26:18.401 : STARTED DisconnectOperation(41108292)
08-01 17:26:18.410 : FINISHED DisconnectOperation(41108292) in 10 ms
这是正确的预期行为吗?我能以某种方式立即开始扫描操作而无需排队吗?
Is this correct and expected behavior?
是的,这是预期的行为。一些 BLE 堆栈实现没有很好地处理可能导致 status=133
的同时扫描和连接。 It is still advised to not to do it.
And can I somehow start scan operation immediately without queueing?
在使用 RxAndroidBle
时,每个扫描操作都在主客户端队列中排队。在牢记上述警告的同时,您可以尝试使用 autoConnect=true
的连接,这不会长时间阻塞主客户端队列。
或者您可以使用 vanilla Android API 来执行扫描。