SysComSetSettingsEx

This function of type BOOL with the parameters of type  POINTER TO COMSETTINGSEX is used to set all relevant parameters of a serial communication port. Not only the parameters of the above function are set, but also the parameters for flowcontrol and character size can be set with this function. This is performed by filling them into the structure COMSETTINGSEX.

The return value of the function is true if the parameters were successfully set and false if the parameters could not be applied to the communication port. It is hardware-dependent whether the settings can be changed more often than one time after opening a port. It may be necessary to close and reopen the port before setting the parameters new.

Input Variable Data Type Description
ComSettingsEx POINTER TO  COMSETTINGSEX; Pointer to the structure COMSETTINGSEX; Use the ADR operator to determine an address.
dwHandle DWORD Port handle, acquired by SysComOpen

Structure COMSETTINGSEX:

TYPE COMSETTINGSEX  :

STRUCT

Size:INT; (*The size in bytes of the structure. Use the sizeof() operator to fill in. Used for backward compatibility.*)
Port:PORTS; (*Port number, see below: Enumeration PORTS *)
dwBaudRate:DWORD; (* 4800, 9600, 19200, 38400, 57600, 115200 *)
byStopBits:BYTE; (* 0 = ONESTOPBIT, 1=ONE5STOPBITS, 2=TWOSTOPBITS *)
byParity:BYTE; (* 0 = NOPARITY, 1 = ODDPARITY, 2 = EVENPARITY *)
dwTimeout:DWORD; (* Timeout of the port in ms, Default = 0 *)
dwBufferSize:DWORD; (* Buffersize used by the driver, Default = 0 *)
dwScan:DWORD; (* Poll-time of the serial driver. Should be set to 0. Only change if the documentation of the hardware-vendor tells so. *)
cByteSize : BYTE; (*4…8: Character size in bits.*)
fOutxCtsFlow :  BOOL; (*Specifies whether the CTS (clear-to-send) signal is monitored for output flow control. If this member is TRUE and CTS is turned off, output is suspended until CTS is sent again. *)
fDtrControl : BYTE;

(*0:Disables the DTR line when the device is opened and leaves it disabled.

1:Enables the DTR line when the device is opened and leaves it on.

2:Enables DTR handshaking. *)

fDsrSensitivity : BOOL; (*Specifies whether the communications driver is sensitive to the state of the DSR signal. If this member is TRUE, the driver ignores any bytes received, unless the DSR modem input line is high. *)
fRtsControl : BYTE;

(*0: Disables the RTS line when the device is opened and leaves it disabled.

1: Enables the RTS line when the device is opened and leaves it on.

2: Enables RTS handshaking. The driver raises the RTS line when the “type-ahead” (input) buffer is less than one-half full and lowers the RTS line when the buffer is more than three-quarters full.

3: Specifies the RTS line will be high if bytes are available for transmission. After all buffered bytes have been sent, the RTS line will be low. *)

fOutxDsrFlow : BOOL; (*Specifies whether the DSR (data-set-ready) signal is monitored for output flow control. If this member is TRUE and DSR is turned off, output is suspended until DSR is sent again. *)

END_STRUCT

END_TYPE

Enumeration PORTS

TYPE PORTS : (COM1:=1, COM2, COM3, COM4, COM5, COM6, COM7, COM8);

END_TYPE

Example for the settings to perform a hardwarehandshake:

dwHandle: DWORD;

pt_comsettingsex:COMSETTINGSEX:=(Port:=COM1,

dwBaudRate:=38400,

byStopBits:=0,

dwTimeout:=5000,

cByteSize:=7,

byParity := 2,

fOutxCtsFlow := FALSE,

fOutxDsrFlow:=TRUE,

DtrControl := 2,

fRtsControl := 2);

Implementation:

pt_comsettingsex.Size := sizeof(pt_comsettingsex);

SysComSetSettingsEx(dwHandle := Handle, ComSettingsExt := ADR(pt_comsettingsex));

Where Handle is the returnvalue of a call to SysComOpen(COM1).