private Task _ReadInputStreamTaskAsync() { return(Task.Run(() => { var inputStream = RfcommConnection.InputStream; bool disconnected = false; while (true) { byte[] buffer = new byte[255]; var readSize = inputStream.Read(buffer, 0, buffer.Length); if (readSize == 0) { disconnected = true; break; } var readBytes = new byte[readSize]; Array.Copy(buffer, 0, readBytes, 0, readSize); var msg = new RXReceiveMessage { RXConnection = this, Bytes = readBytes }; OnReceived?.Invoke(this, msg); } if (disconnected) { RfcommConnection.Dispose(); ConnectionState = RXConnectionState.Destoryed; OnConnectionStateChanged?.Invoke(this, ConnectionState); } })); }
private void RXConnectionManager_OnReceived(object sender, RXReceiveMessage e) { Device.BeginInvokeOnMainThread(() => { ReceiveMessageList.Add(Encoding.UTF8.GetString(e.Bytes)); }); }
private void ConnectionManager_OnReceived(object sender, RXReceiveMessage e) { if (e.RXConnection.RemoteRXDevice == RemoteRXDevice && e.ChannelCode == ATTRIBUTE_CHANNEL_CODE) { var response = AttributeReadResult.DecodeFromByteArray(e.Bytes); lock (_WaitingThreadDictLock) { if (_WaitingThreadDict.ContainsKey(response.RequestGuid)) { var bundle = _WaitingThreadDict[response.RequestGuid]; bundle.Result = response; bundle.Thread.Interrupt(); } } } }