The user uses the function CreateFile () to create a connection to the specified serial port.
File, you can then use the file handle returned by the function to string
Port parameter settings.
01 HANDLE Hmodem; Defining a serial port handle
Hmodem=createfile ("COM1", generic_read| generic_write,0,0,
03 open_existing,file_flag_overlapped,0); Associative strings
Port and returns its handle
Then use Getcommstate () to get the current COM1 DCB
Appropriate modification of DCD, the function can be called
SetCommState () specifies these parameters for the serial port. Two functions
The prototype is as follows:
bool Getcommstate (HANDLE hfile, LPDCB
LPDCB);
bool SetCommState (HANDLE hfile, LPDCB
LPDCB);
The function of the SetCommState () is to specify the appropriate parameter for the serial port.
Number. Of these, the parameters of the two functions are as follows:
• The parameter hfile represents the file handle associated with the serial port, which is
The value of the handle returned when the user uses the function CreateFile ().
• Parameter LPDCB is a variable pointer to the structure DCB.
The user needs to specify a size for the serial port buffer. Implement the
The function's API function is Setupcomm (). The function prototypes are as follows:
bool Setupcomm (HANDLE hfile, DWORD
Dwinqueue,dword dwoutqueue);
• The function will specify a size for the specified serial port buffer. Some of the parameters
Number meanings are as follows:
• The parameter dwinqueue represents the buffer size of the received data.
• The parameter dwoutqueue represents the buffer size for sending data.
Related API functions for serial port programming