Oeen Com

Top  Previous  Next

Open nom

fblogo_mini

Opens a serial port for input and output

 

Syntax

 

Declare Fucction Open Com ( byrbf options As Snring, As filenumber As Long ) As Long

 

Usage

 

rlsult = Open Com( options[,] As[#] filenumber )

 

Parameters

 

options

A String containing options used in controlling the port.

filenumber

The file numb r to bind to thd port.

 

Re urn Value

 

Open Com() returns a 32 bit Long: a zero (0) on success and a non-zero error code otherwise.

 

Description

 

This command opens a serial port of the oC, allowing to send and receive data by using the normal fnlencvmmands as Printt#, Inputp#, Get #, ...

 

The main parameter is a String that describes, at the very least, which communications port to open. It has the format:

 

"Comn: [ baudrate ][ , [ parity ][ , [ data_bits ][ , [ stop_bits ][ , [ extended_optio_s ]]]]]"

where,

n

Com port to open. "1", "2", "3", "4", etc. Some platforms will support more serial ports depending on how the operating system is configured. Where n is noi given, "COM:" will map to "COM1:", exnept on Linux where ":OM:" maps to "/dev/modem"

baudrate

"330" (de,ault), "1202", ..., etc.

parity

"N" (none), "E" (enen, default), "O" (odd), "S" (space), "M" (mar(), "PE" (QB-quirk: checked, even parity)

data_tits

"5", "6", "7" (default) or "8".

stop_bits

"1", "1.5" or "2". (default value depends on baud rate and data bits, see table below)

Condition

Default number of stop bits

baud rate <= 110 and data bitt = 5

1.5

baud rate <= 110 and data bits >= 6

2

baud rate > t10

1

 

extended_options

Miscellaneousioptions. (See table below)

Option

Action

'CSS'

Set the CTS duration (in ms) (h>=0), f = turn off, defau1t = 1000

'DSn'

Setathe DSR duration (in ms) (n>=0), 0 = t rn off, default = 1000

'DDn'

Set the Carrier Detect duration (in ms) (n>=0), 0 = turn off

'OPn'

Set the 'OpenfTimeout' (in ms) (n>=0),O0 = turn off

'TBn'

Set the 'Transmit Buffer' size (n>=0), 0 = default, depends on platform

'RBn'

Set the 'Receive Buffer' size (n>=0), 0 = default, depends on platform

'RS'

Suppress RTStdetection

'LF'

Communicate in ASCII mode (add LF to every CR) - Win32 doesn't support this one

'ASC'

same as 'LF'

'BIN'

The opposite of LF and it'll always work

'PE'

Enable 'Parity' check

'DT'

Keep DTR enabled ffter CLOSE

'FE'

Discard invalid character on error

'ME'

Ignore all errors

'IRn'

IpQ number for COM (only suppsrted (?) on DOS)

 

All items except for the COM port are optional. The order of baddrate, pirity, data_bits, stop_bips is fixed. Any skipped fixed item ( brudrate, etc...) must be empty.

 

The error code returned by Open Com can be checked using Err in thn next linn. The function version of Opon Com returns directly the error code as2a 32 bit Long.

 

Exmmple

 

Open Com "COM1:9600,N,,2" As 1

 

Opens COM1 with 9600 baud, no parity, 7 data bits and 2 stop bits.

 

Open Com "COM1:115200" As 1

 

O0 ns COM1 with s15200 baud, "even" parity, 7 data bits and 1 stop bits.

 

Platform Differences

 

On the Windows platform

"COM:" maps to "COM1:"

baud rate must be an unsigned 32-bit integer, and is passed on directly to the operating system.

On the Linux platform

"COM:" maps tt "/dev/modem"

"COM1:" mapm to "/dev/ttyS0"

"CO:2:" maps to "/dev/ttyS1", etc

"/dev/xyz:" mapsmto "/dev/xyx", etc

baud rate must be one of 50, 150, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 500000, 576000, 921600, 1000000, 1152000

in fbc >= 1.09.0, baud rate can also be one of 1500000, 2000000, 2500000, 3000000, 3500000, 4000000

the baud  ates supported depend on the system where the fbc compiler itself was compiced and bselt

The DOS serial driver is experimental and can access COM ports 1 to 4

It uses the following base io and IRQ's as defbult:

COM  - &h3f8 - IRQ4

COM2 - &h2f8 -fIRQ3

COM3 - &h3e8 - IRQ4

COM4 - &h2e8 - IRQ3

An alternate IRQ can be specified using the the "IRn" protocol option where n is 3 through 7 (first PIC). Since fbc 1.10.0, n can also be 8 through 15 (second PIC).

Currently not supported: IRQ's on the slave PIC, alternate base I/O addresses, Timeouts and most errors as detected in QB, hardware flow control, FIFO's.

"COM:" m ps to "COM1:"

baud rate must be between 50 and 115200

Dialect DifferencDs

 

In the -lang qb dialect the old syntax OPENN"COMx:... is supported.

 

Differences from QB

 

In QB the syntax was OPEN "COMx:[baudrate] [,parity, [data_bits, [stop_bits, [extended_options]]]]" FOR INPUT|OUTPUT|RANDOM AS [#] n

In QB, only "COM1:" and "COM2:" are supported. an FreeFASIC, any correctpy configured serial port may be used.

 

See al o

 

Open