For implementationYou can use APIs to implement Windows serial communication, but it is inconvenient. You can also use the Active control.
InsertThe Active control Microsoft comm contronl (MSComm ).
SComm control attributes
MSComm control attributes
Commp ORT: Set the serial port number. Type: short: 1-comm1 2-comm2.
Settings: sets the serial communication parameters, type CString: B-baud rate P-parity (N-no verification,
E-even verification, O-odd verification) D-byte valid bits S-Stop bits.
PortOpen: set or return the serial port status. Type: BOOL: True-enable FALSE-Disable.
InputMode: sets the format for reading data from the receiving buffer, type long: 0-Text 1-Bin.
Input: Read the data type VARIANT from the receiving buffer.
InBufferCount: number of bytes in the receiving buffer; Type: short.
InBufferSize: the size of the receiving buffer. Type: short.
Output: write data to the sending buffer. Type: VARIANT.
OutBufferCount: number of bytes in the sending buffer; Type: short.
OutBufferSize: size of the sending buffer; Type: short.
InputLen: Specifies or returns the number of bytes read from Input. Type: short.
CommEvent: Serial Port event, type: short.
Program example
Serial Port Initialization
If (! M_comm.GetPortOpen ())
M_comm.SetPortOpen (TURE );/* Open the serial port
M_comm.SetSettings ("4800, n, 8, 1 ");/* Set serial port Parameters
M_comm.SetInputMode (0 );/* Set the TEXT buffer input mode
M_comm.SetRthresHold (1 );/* The OnComm () event is triggered every time one character is received.
Receive data
M_comm.SetInputLen (1 );/* Read one character each time
VARINAT V1 = m_comm.GetInput ();/* Read characters
M_V1 = V1.bstrval;
Sending character
M_comm.SetOutput (COlevariant ("Hello");/* Send "Hello"