Read serial code with control (cmscomm) (high efficiency, different from online common, no plagiarism)!

xiaoxiao2021-03-06  91

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 startemp; if (m_ctrlcomm.getCommEvent () == 2) // The 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 conversion For the COLESAFEARRAY type variable len = SafeArray_inp.getonedimsize (); // Get valid data length for (k = 0; k 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 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!

转载请注明原文地址:https://www.9cbs.com/read-95905.html

New Post(0)