KsBuildCommDCB
The availability of this function depends on what the device supports.
Fills a specified DCB structure with values specified in a device-control string. The device-control string uses the syntax of the mode command.
Syntax
BOOL KsBuildCommDCB(
LPCWSTR lpDef,
LPDCB lpDCB
);
Parameters
lpDef: the device-control information. The function takes this string, parses it, and then sets appropriate values in the DCB structure pointed to by lpDCB.
The string must have the same form as the mode command's command-line arguments:
COMx[:][baud=b][parity=p][data=d][stop=s][to={on|off}][xon={on|off}][odsr={on|off}][octs={on|off}][dtr={on|off|hs}][rts={on|off|hs|tg}][idsr={on|off}]
The device name is optional, but it must specify a valid device if used.
For example, the following string specifies a baud rate of 1200, no parity, 8 data bits, and 1 stop bit:
baud=1200 parity=N data=8 stop=1
lpDCB: a pointer to a DCB structure that receives the information.
Return value
If the function succeeds, it returns TRUE, otherwise FALSE. To get extended error information, call GetLastError.
Remarks
The KsBuildCommDCB function adjusts only those members of the DCB structure that are specifically affected by the lpDef parameter, with the following exceptions:
- If the specified baud rate is 110, the function sets the stop bits to 2 to remain compatible with the system's mode command.
- By default, KsBuildCommDCB disables XON/XOFF and hardware flow control. To enable flow control, you must explicitly set the appropriate members of the DCB structure.
The KsBuildCommDCB function only fills in the members of the DCB structure. To apply these settings to a serial port, use the KsSetCommState function.
There are older and newer forms of the mode syntax. The KsBuildCommDCB function supports both forms. However, you cannot mix the two forms together.
The newer form of the mode syntax lets you explicitly set the values of the flow control members of the DCB structure. If you use an older form of the mode syntax, the BuildCommDCB function sets the flow control members of the DCB structure, as follows:
- For a string that does not end with an x or a p:
- fInX, fOutX, fOutXDsrFlow, and fOutXCtsFlow are all set to FALSE
- fDtrControl is set to DTR_CONTROL_ENABLE
- fRtsControl is set to RTS_CONTROL_ENABLE
- For a string that ends with an x:
- fInX and fOutX are both set to TRUE.
- fOutXDsrFlow and fOutXCtsFlow are both set to FALSE
- fDtrControl is set to DTR_CONTROL_ENABLE
- fRtsControl is set to RTS_CONTROL_ENABLE
- For a string that ends with a p:
- fInX and fOutX are both set to FALSE
- fOutXDsrFlow and fOutXCtsFlow are both set to TRUE
- fDtrControl is set to DTR_CONTROL_HANDSHAKE
- fRtsControl is set to RTS_CONTROL_HANDSHAKE
Example
N/A
Requirements
RT | Win32 | |
---|---|---|
Minimum supported version | 4.0 | 4.0 |
Header | kscom.h | kscom.h |
Library | KsApi_Rtss.lib | ksapi.h |
See also