public async Task <byte> ATTClientReadByHandleAsync(byte connectionHandle, UInt16 characteristicUUID) { const int TIMEOUT_MS = 4000; var cmd = _bglib.BLECommandATTClientReadByHandle(connectionHandle, characteristicUUID); 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 = $"ATTClientReadByHandle returned: error={error} code={_lastResult:X4}"; throw new Exception(errMsg); } byte conHandle = ((ReadByHandleEventArgs)_lastResponseArgs).connection; return(conHandle); }