The code to read the serial port is covered on the Internet, but they are almost entirely, the first person writes is the hero, the other is not. This code is similar to the following:
Variant Variant_inp; ColesafeArray Safearray_inp; Long Len, K; BYTE RXDATA [2048]; // Set Byte array an 8-bit integerthat is not sign.cstring startTemp; if (m_ctrlcomm.getCommEvent () == 2) // Event value is 2 Indicates that there is a character {below in the receiving buffer you can join the processing code variant_inp = m_ctrlcomm.getinput (); // read buffer SafeArray_inp = variant_inp; // variant type variable to COLESAFEARRAY Variables Len = SafeArray_inp .Getonedimsize (); // Get effective data length for (k = 0; k Let me give my code first: VARIANT REC_DATA; INT DATA_LEN; char REC_DATA_ARRAY [2048]; if (m_ctrlcomm.getCommEvent () == 2) // The event value is 2 indicates that the receiving buffer has character {REC_DATA = m_serialcom.getinput (); int Data_len = REC_DATA. PARRAY-> RGSABOUND-> CELEMENTS; // Remove the one-dimensional data number Memcpy (REC_DATA_ARRAY, (CHAR *) REC_DATA.PARRAY-> PVDATA, DATA_LEN); // Copy Data REC_DATA_ARRAY [DATA_LEN] = 0;} Updatedata False); / / Update the edit box content My code has the following characteristics: 1: Simple program; second: the most important, high efficiency! I didn't use the ColesafeArray class. Everyone knows that the class should be constructed and destructure, I dare to guarantee, I have the above program, when I have the first code constructor, my code has been received. Another point is secondary, but I have to mention it, see the number of variables applied for two segments, the length, readability, my code should be better!