|
The data sent by the external device to the serial port is hexadecimal, and I read it in binary:
m_ComPort.SetInputMode (1);
What should I do with the data after reading it to convert it to a decimal number?
VARIANT variant_inp;
COleSafeArray safearray_inp;
LONG len, k;
BYTE rxdata [2048]; // Set BYTE array
CString strtemp;
if (m_ctrlComm.GetCommEvent () == 2)
{
variant_inp = m_ctrlComm.GetInput (); // Read buffer
safearray_inp = variant_inp; // VARIANT type variables are converted to ColeSafeArray type variables
len = safearray_inp.GetOneDimSize (); // Get effective data length
for (k = 0; k <len; k ++)
safearray_inp.GetElement (&k, rxdata + k); // Convert to BYTE type array
When i write like this
safearray_inp = variant_inp; // VARIANT type variables are converted to ColeSafeArray type variables
When the program is running, I get an exception in this sentence.I read a lot of information and wrote it like this. I don't know why. Please help me! |
|