Skip to content

Instantly share code, notes, and snippets.

@elbruno
Created May 16, 2017 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elbruno/30e27acbe41e584c48a26c0cc1530ed6 to your computer and use it in GitHub Desktop.
Save elbruno/30e27acbe41e584c48a26c0cc1530ed6 to your computer and use it in GitHub Desktop.
Lego EV3 Network communication Connect Async start lines
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