private static string getName(string serialPort) { var bytes = ByteBuilder.Hello(); var connection = buildConnection(serialPort); string result = ""; try { connection.Open(); Thread.Sleep(15); connection.Write(bytes, 0, bytes.Length); Thread.Sleep(15); result = connection.ReadExisting(); connection.Close(); } catch (Exception) { } if (result.Contains("ARDUINO")) { result = result.Split('|').Last(); } return(result); }
public bool WriteHigh(int pin) { var bytes = ByteBuilder.WriteHigh(pin); _serialPort.Write(bytes, 0, bytes.Length); Thread.Sleep(15); int result = _serialPort.ReadChar() - 48; return(result == 1); }
public bool Ping() { int hash = new Random().Next(0, 63); var bytes = ByteBuilder.Ping(hash); _serialPort.Write(bytes, 0, bytes.Length); Thread.Sleep(15); string result = _serialPort.ReadExisting(); return(result == string.Format("Pong|{0}", hash)); }