ComSetup Procedure

Sets the specified serial port characteristics.

Syntax

[ lStatus = ] ComSetup ( lPort , lBaudRate , lDataBits , enParity , enStopBits , enHandshake [, bInfrared] )

The ComSetup procedure syntax has the following parts:

 

Name

Type

Description

lStatus

Long

Status of setup operation. 0 = OK, -1 = operation failed.

lPort

Val Long

Serial port number (1 for COM1, etc.)

lBaudRate

Val Long

Baud Rate Number: 110, 300, 600, 1200,2400, 4800, 9600, 14400, 19200, 38400, 56000, 57600, 115200, 128000, 256000... (see below for maximum baud rate)

lDataBits

Val Long

Number of data bits: 5-8

enParity

enumAComParity

Parity type.

enStopBits

enumAComStopBits

Number of stop bits.

enHandshake

enumAComHandshake

COM handshake

bInfrared

Bool

A boolean expression specifying whether the port is an infrared port.

Where

enumAComParity can have one of the following values:

 

Name

Value

Description

aComParityNone

0 *

No parity

aComParityOdd

1

Odd parity

aComParityEven

2

Even parity

aComParityMark

3

Marked parity

aComParitySpace

4

Spaced Parity

enumAComStopBits can have one of the following values:

 

Name

Value

Description

aComStopBits1

0 *

1 Stop Bit

aComStopBits1_5

1

1.5 Stop Bits (this is not supported by most windows drivers and might cause the function to return -1)

aComStopBits2

2

2 Stop Bits

enumAComHandshake can have one of the following values:

 

Name

Value

Description

aComHandshakeNone

0

None

aComHandshakeXonXoff

1

XonXoff

aComHandshakeHardware

2

Hardware

bInfrared can have one of the following values:

 

Value

Description

True

The COM port is an infrared port.

False *

The COM port is not an infrared port.

Comments

The lPort must be opened by calling the ComOpen procedure or by configuring an RS232 driver in the System.

The specified port must be open before this function is called. This could occur when an RS-232 Driver configured with the specified lPort address is in the Drivers' Property page.

For baud rate values, 256K is the top value that you can select from, however you can pass any value. The maximum baud rate and the rate resolution depends on the actual hardware and the Windows internal communication driver, not the communication driver; for example, the UART clock or clock divider is the limiting factor. ATEasy does not limit the baud rate value.

Do not use the Xon/Xoff for transferring binary data since the data might have the Xon (0x11) or Xoff (0x13) characters and  would interfere with data transfer.

Example

The following example sets the COM2 port to 9600 baud, 8 data bits, even parity, one stop bits and hardware handshake, with the port not being an infrared port:

lStatus=ComSetup(2, 9600, 8, aComParityEven,0, 2)

See Also

ComOpen, GetDriverAddress