I am trying to slightly modify some sample code for a USB device that reads serial data. The current way the data is displayed is very confusing. The device reads 30 bits worth of data. The following section of code is what I am trying to manipulate...
private string GetDataString()
{
string strTemp;
strTemp = "";
if ((m_Msg.MSGTYPE & TPCANMessageType.PCAN_MESSAGE_RTR) == TPCANMessageType.PCAN_MESSAGE_RTR)
return "Remote Request";
else
// UNCOMMENT FOR DECIMAL
for (int i = Form1.GetLengthFromDLC(m_Msg.DLC, (m_Msg.MSGTYPE & TPCANMessageType.PCAN_MESSAGE_FD) == 0) - 1; i >= 0; i--)
strTemp += string.Format("{0:000} ", m_Msg.DATA[i]);
//// UNCOMMENT FOR HEX
//for (int i = Form1.GetLengthFromDLC(m_Msg.DLC, (m_Msg.MSGTYPE & TPCANMessageType.PCAN_MESSAGE_FD) == 0) - 1; i >= 0; i--)
// strTemp += string.Format("{0:X2} ", m_Msg.DATA[i]);
return strTemp;
}
The returned string is in one of two formats, depending upon which section I uncomment. Below is a sample read in each format:
"000 000 123 255 " (decimal)
"00 00 7B FF " (hex)
The problem is that there are two sections of information encoded here: the rightmost 12 bits of data (call these ST) and the next 18 bits (call these MT). Data is displayed in little-endian format (LSB to the right). I am trying to modify this section of code to display each section via its corresponding decimal value.
So the above examples would be displayed as:
"7 3071"
(MT) (ST)
Any recommendations on how to perform this conversion? I apologize in advance if this is a stupid question, but I am quite inexperienced in C# programming.