Open Com
 
Opens a serial port for input and output

Syntax

Declare Function Open Com ( byref options As String, As filenum As Integer ) As Integer

Usage

result = Open Com( options, As[#] filenum )

Parameters

options
A String containing options used in controlling the port.
filenum
The file number to bind to the port.

Return Value

Returns zero (0) on success and a non-zero error code otherwise.

Description

This command opens a serial port of the PC, allowing to send and receive data by using the normal file commands as PRINT #, INPUT#, 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_options ]]]]]"

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 not given, "COM:" will map to "COM1:", except on Linux where "COM:" maps to "/dev/modem"
baudrate
"300" (default), "1200", ..., etc.
parity
"N" (none), "E" (even, default), "O" (odd), "S" (space), "M" (mark), "PE" (QB-quirk: checked, even parity)
data_bits
"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)

ConditionDefault number of stop bits
baud rate <= 110 and data bits = 51.5
baud rate <= 110 and data bits >= 62
baud rate > 1101

extended_options
Miscellaneous options. (See table below)

OptionAction
'CSn'Set the CTS duration (in ms) (n>=0), 0 = turn off, default = 1000
'DSn'Set the DSR duration (in ms) (n>=0), 0 = turn off, default = 1000
'CDn'Set the Carrier Detect duration (in ms) (n>=0), 0 = turn off
'OPn'Set the 'Open Timeout' (in ms) (n>=0), 0 = 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 RTS detection
'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 after CLOSE
'FE'Discard invalid character on error
'ME'Ignore all errors
'IRn'IRQ number for COM (only supported (?) on DOS)


All items except for the COM port are optional. The order of baudrate, parity, data_bits, stop_bits is fixed. Any skipped fixed item ( baudrate, etc...) must be empty.

Example

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

Opens COM1 with 115200 baud, "even" parity, 7 data bits and 1 stop bits.

Platform Differences

  • On the Windows platform "COM:" maps to "COM1:"
  • On the Linux platform
"COM:" maps to "/dev/modem"
"COM1:" maps to "/dev/ttyS0"
"COM2:" maps to "/dev/ttyS1", etc
"/dev/xyz:" maps to "/dev/xyz", etc
  • The DOS serial driver is experimental and can access COM ports 1 to 4
It uses the following base io and IRQ's as default:
COM1 - &h3f8 - IRQ4
COM2 - &h2f8 - IRQ3
COM3 - &h3e8 - IRQ4
COM4 - &h2e8 - IRQ3
Since fbc-0.18.4, an alternate IRQ can be specified using the the "IRn" protocol option where "n" is 3 through 7.
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:" maps to "COM1:"
Dialect Differences

  • In the -lang qb dialect the old syntax OPEN "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. In FreeBASIC, any correctly configured serial port may be used.

See also

Сайт ПДСНПСР. Если ты патриот России - жми сюда!


Знаете ли Вы, низкочастотные электромагнитные волны частотой менее 100 КГц коренным образом отличаются от более высоких частот падением скорости электромагнитных волн пропорционально корню квадратному их частоты от 300 тыс. км/с при 100 кГц до примерно 7 тыс км/с при 50 Гц.

НОВОСТИ ФОРУМАФорум Рыцари теории эфира
Рыцари теории эфира
 10.11.2021 - 12:37: ПЕРСОНАЛИИ - Personalias -> WHO IS WHO - КТО ЕСТЬ КТО - Карим_Хайдаров.
10.11.2021 - 12:36: СОВЕСТЬ - Conscience -> РАСЧЕЛОВЕЧИВАНИЕ ЧЕЛОВЕКА. КОМУ ЭТО НАДО? - Карим_Хайдаров.
10.11.2021 - 12:36: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от д.м.н. Александра Алексеевича Редько - Карим_Хайдаров.
10.11.2021 - 12:35: ЭКОЛОГИЯ - Ecology -> Биологическая безопасность населения - Карим_Хайдаров.
10.11.2021 - 12:34: ВОЙНА, ПОЛИТИКА И НАУКА - War, Politics and Science -> Проблема государственного терроризма - Карим_Хайдаров.
10.11.2021 - 12:34: ВОЙНА, ПОЛИТИКА И НАУКА - War, Politics and Science -> ПРАВОСУДИЯ.НЕТ - Карим_Хайдаров.
10.11.2021 - 12:34: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от Вадима Глогера, США - Карим_Хайдаров.
10.11.2021 - 09:18: НОВЫЕ ТЕХНОЛОГИИ - New Technologies -> Волновая генетика Петра Гаряева, 5G-контроль и управление - Карим_Хайдаров.
10.11.2021 - 09:18: ЭКОЛОГИЯ - Ecology -> ЭКОЛОГИЯ ДЛЯ ВСЕХ - Карим_Хайдаров.
10.11.2021 - 09:16: ЭКОЛОГИЯ - Ecology -> ПРОБЛЕМЫ МЕДИЦИНЫ - Карим_Хайдаров.
10.11.2021 - 09:15: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от Екатерины Коваленко - Карим_Хайдаров.
10.11.2021 - 09:13: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от Вильгельма Варкентина - Карим_Хайдаров.
Bourabai Research Institution home page

Боровское исследовательское учреждение - Bourabai Research Bourabai Research Institution