private string TransmitBufferAndAwaitResponse(Commands command, byte[] buffer, int offset, int count)
{
byte[] header = new byte[3];
header[0] = (byte)command;
header[1] = (byte)(count >> 8);
header[2] = (byte)(count & 0x0FF);
if (!IsOpen)
{
Open();
}
arduinoPort.Write(header, 0, 3);
if (count > 0)
{
arduinoPort.Write(buffer, offset, count);
}
var response = arduinoPort.ReadLine();
if (response.StartsWith("- "))
{
throw new ArduinoConnectionException(response.Substring(2));
}
return response;
}