public static bool SendDataPacket(UART uart, byte[] value) { ushort serviceCode = (ushort)TegamServiceCode_t.TEGAM_DATA_PACKET_UPD_REQ; ushort valueSize = 12; byte[] cmdbuf = new byte[22]; byte[] cobsbuf = new byte[24]; cmdbuf[0] = CMD_MARK_START; cmdbuf[1] = CMD_MARK_HEADER & 0x00FF; cmdbuf[2] = (CMD_MARK_HEADER & 0xFF00) >> 8; cmdbuf[3] = CMD_VERSION_CODE & 0x00FF; cmdbuf[4] = (CMD_VERSION_CODE & 0xFF00) >> 8; cmdbuf[5] = (byte)(serviceCode & 0x00FF); cmdbuf[6] = (byte)((serviceCode & 0xFF00) >> 8); cmdbuf[7] = (byte)(valueSize & 0x00FF); cmdbuf[8] = (byte)((valueSize & 0xFF00) >> 8); cmdbuf[9] = value[0]; cmdbuf[10] = value[1]; cmdbuf[11] = value[2]; cmdbuf[12] = value[3]; cmdbuf[13] = value[4]; cmdbuf[14] = value[5]; cmdbuf[15] = value[6]; cmdbuf[16] = value[7]; cmdbuf[17] = value[8]; cmdbuf[18] = value[9]; cmdbuf[19] = value[10]; cmdbuf[20] = value[11]; cmdbuf[21] = CMD_MARK_END; COBS.Encode(cmdbuf, 22, ref cobsbuf); cobsbuf[23] = 0; if (WRITE) { uart.Write(cobsbuf, 24); } if (VERIFY) { System.Threading.Thread.Sleep(100); char[] readBuf = uart.ReadBuffer(); byte[] decodedBuf = new byte[11]; // decoded what was read from UART COBS.Decode(Encoding.Default.GetBytes(readBuf), 11, ref decodedBuf); // reset the UART read buffer after obtaining read data uart.ResetReadBuffer(); // ensure ACK command is valid return(ValidateACK(decodedBuf, TegamServiceCode_t.TEGAM_DATA_PACKET_UPD_ACK)); } else { return(true); } }