public async Task <byte> ATTClientReadByTypeAsync(byte connectionHandle, UInt16 startATTHandle, UInt16 endATTHandle, IEnumerable <byte> attributeTypeUUID) { const int TIMEOUT_MS = 6000; var cmd = _bglib.BLECommandATTClientReadByType( connectionHandle, startATTHandle, endATTHandle, attributeTypeUUID.ToArray() ); await _bglib.SendCommandAsync(cmd).ConfigureAwait(false); using (var cts = new CancellationTokenSource(TIMEOUT_MS)) { bool didTimeout = false; try { await _cmdRespWaitHandle.WaitAsync(cts.Token).ConfigureAwait(false); } catch (OperationCanceledException) { didTimeout = true; } if (didTimeout) { throw new TimeoutException(); } } if (_lastResult != 0) { var error = Enum.ToObject(typeof(BGErrorCode), _lastResult); string errMsg = $"ATTClientReadByType returned: error={error} code={_lastResult:X4}"; throw new Exception(errMsg); } byte conHandle = ((ReadByTypeEventArgs)_lastResponseArgs).connection; return(conHandle); }