Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.