private void mSendDo(CProtocolMessage msg)
        {
            mCheckPortIsOpen();

              List<byte> rawMessage = msg.GetRawData();
              rawMessage.Insert(0, START_CHAR);
              rawMessage.Add(END_CHAR);

              Debug.WriteLine("SendToPic, Data=" + string.Join(",", rawMessage));
              mSerialPort.Write(rawMessage.ToArray(), 0, rawMessage.Count);
        }
        public bool SendAndRead(ECommands cmd, List<Byte> data, ECommands matchCmd, out List<Byte> matchData)
        {
            var txMsg = new CProtocolMessage(mGetNextTxPacketId(), cmd, data);

              byte expectedResponsePacketId;
              //The machine always responds with a packet Ok with id 255 upon reset
              if (cmd == ECommands.RESET_COMMAND)
              {
            mCurrentTxPacketId = 255;
            expectedResponsePacketId = 255;
              }
              else
            expectedResponsePacketId = mCurrentTxPacketId;

              for (int i = 1; i <= 10; i++)
              {
            mSendDo(txMsg);
            CProtocolMessage rxMsg = Read();
            byte correctCRC;
            if (rxMsg.ID != expectedResponsePacketId)
              Logging.Log.LogError("Received invalid packet ID, desired " + expectedResponsePacketId + ", received " + rxMsg.ID);
            else if (!rxMsg.VerifyCRC(out correctCRC))
              Logging.Log.LogError("Received invalid packet CRC, desired " + correctCRC + ", received " + rxMsg.CRC);
            else if (rxMsg.Cmd != matchCmd)
              Logging.Log.LogError("Received invalid response command, desired " + matchCmd.ToString() + ", received " + rxMsg.Cmd.ToString());
            else
            {
              matchData = rxMsg.Data;
              return true;
            }
              }

              matchData = null;
              return false;
        }