The serial port wants to use the MSComm control to send any data regardless of what type of variable is to be converted into a variant, by the way to remind you want to send and receive serial port (like, especially to receive) binary data to set that Inputmode to 1 (binary), 0 for the Text.
There is a VC, not just VC, but all for the Windows development environment, as long as he is on the basis of the win API has a byte this type, the type as the name implies is a byte, such as you want to send 127 = 0xFF, you can byte ByVal = 0xFF ;
And if you are using MFC then there is a class in the serial programming inside the absolute use is CByteArray, he is directly manipulating the class of byte array
You want to use the MSComm control to send 127. You can do this
C + + code:
1 CMSComm M_mscomm; 2 // .... 3 4 CByteArray bytes; 5 0xFF ); 6 7 colevariant ovsend (bytes); 8 9 M_mscomm. Setoutput (ovsend); Ten // .....
-
CByteArray
CByteArray is a set class of byte in MFC that declares the data of the CByteArray class and processes it with related functions. This class is a 8-bit unsigned integer byte type, range 0-255, and the header file is Afxcoll.h. Class CByteArray supports the dynamic creation of arrays in bytes.data member editing for the CByteArray classClass CByteArray supports the dynamic creation of arrays in bytes. The member function of class CByteArray is similar to the member function of class CObArray. Therefore, you can also refer to the documentation for the class CObArray. Just change the CObject pointer that appears in the function parameter or return value to byte. For example, a function in class CObArray: cobject* cobarray::getat (int) const; In class CByteArray corresponds to byte* cbytearray::getat (int) const; The CByteArray contains macro implement_serial to support serialization and dumping of objects. If an array of bytes is stored in the file, the elements in it are serialized, regardless of the overridden operator "<<" or the member function serialize. Note: Before using the array, call SetSize to set its size and allocate memory. If you do not use setsize, adding elements to the array causes frequent reallocation of the array memory space and a copy of the data. Frequent redistribution of memory and data copying can affect performance and cause memory fragmentation. If you need output debugging information for each element in the array, set the depth of the CDumpContext object to 1 or greater.function member editing for the CByteArray classconstructor FunctionCByteArray constructs an empty array of bytesBorderGetSize the number of elements in the array (array size) GetUpperBound returns the maximum valid subscript for an array setsize sets the number of array elements (array size)OperationFreeExtra All unused memory RemoveAll Delete all elements in the array after releasing the maximum upper bound of the currently existing data in the arrayelement AccessGetAt Returns the value of the array element at the specified subscriptSetAt assigns a value to the element that specifies the subscript in the array , but cannot dynamically grow the array (the specified subscript cannot be crossed out)ElementAt Returns a temporary reference to a byte in an arrayGetData allows access to elements in the array . can be nullArray GrowthSetatgrow assigns a value to the element that specifies the subscript in the array , and dynamically grows when the subscript is out of bounds add an element at the end of the array, grow the array if necessary append another array at the end of the array, grow the array if necessary Copy copies the contents of another array to this array, growing the array if necessaryInsert/DeleteInsertAt Inserts an element (or the contents of another array ) at the specified subscriptRemoveAt Deletes an element at the specified subscriptoperator operator[] takes the value of the element at the specified subscript, or assigns a value to it
Serial port to send binary data