Created
May 16, 2017 01:19
-
-
Save elbruno/30e27acbe41e584c48a26c0cc1530ed6 to your computer and use it in GitHub Desktop.
Lego EV3 Network communication Connect Async start lines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task ConnectAsync() | |
{ | |
_client = new TcpClient(); | |
await _client.ConnectAsync(_address, 5555); | |
_stream = _client.GetStream(); | |
// unlock the brick (doesn't actually need serial number?) | |
byte[] buff = Encoding.UTF8.GetBytes(UnlockCommand); | |
await _stream.WriteAsync(buff, 0, buff.Length); | |
// read the "Accept:EV340\r\n\r\n" response | |
int read = await _stream.ReadAsync(buff, 0, buff.Length); | |
string response = Encoding.UTF8.GetString(buff, 0, read); | |
if(string.IsNullOrEmpty(response)) | |
throw new Exception("LEGO EV3 brick did not respond to the unlock command."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment