Related API functions for serial port programming

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.