C# code converted from C++ not working

2018-06-05 08:31:30

Consider the following C++ code which sends data over RS232 to a device.

strcpy(m_MsgBytes, "SRT1");

iTmp = finalizeNL20Message(m_MsgBytes, 4);

int CVTSSLTNL20Message::finalizeNL20Message(BYTE *pMsgData, int iInLen)

{

BYTE ucMsg[MAX_MESSAGE_LENGTH];

ucMsg[0] = MSG_STX; // 0x02

ucMsg[1] = NL20_BLOCK_ID; // ox01

ucMsg[2] = ATTR_CMD; // 'C'

memcpy(&ucMsg[3], pMsgData, iInLen);

ucMsg[3 + iInLen] = MSG_ETX;

ucMsg[4 + iInLen] = calculateNL20Checksum(ucMsg, 4 + iInLen);

ucMsg[5 + iInLen] = MSG_CR;

ucMsg[6 + iInLen] = MSG_LF;

memcpy(pMsgData, ucMsg, 7 + iInLen);

return 7 + iInLen;

}

BYTE CVTSSLTNL20Message::calculateNL20Checksum(const BYTE *pData, int iInLen)

{

BYTE ucChk = 0;

for (int iCnt = 0; iCnt < iInLen; iCnt++)

ucChk = ucChk ^ pData[iCnt];

return ucChk;

}

I've rewritten this code in C# as the following:

public static string Generate()

{

return RIONNLHelper.FinalizeMessage("SRT1");

}

public static