Serial port access (TTY/PTY) on Unix.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | public, | parameter | :: | TTY_RDONLY | = | 1 |
Read-only. |
integer, | public, | parameter | :: | TTY_WRONLY | = | 2 |
Write-only. |
integer, | public, | parameter | :: | TTY_RDWR | = | 3 |
Read/write. |
integer, | public, | parameter | :: | TTY_B0 | = | 0 | |
integer, | public, | parameter | :: | TTY_B50 | = | 50 | |
integer, | public, | parameter | :: | TTY_B75 | = | 75 | |
integer, | public, | parameter | :: | TTY_B110 | = | 110 | |
integer, | public, | parameter | :: | TTY_B134 | = | 134 | |
integer, | public, | parameter | :: | TTY_B150 | = | 150 | |
integer, | public, | parameter | :: | TTY_B200 | = | 200 | |
integer, | public, | parameter | :: | TTY_B300 | = | 300 | |
integer, | public, | parameter | :: | TTY_B600 | = | 600 | |
integer, | public, | parameter | :: | TTY_B1200 | = | 1200 | |
integer, | public, | parameter | :: | TTY_B1800 | = | 1800 | |
integer, | public, | parameter | :: | TTY_B2400 | = | 2400 | |
integer, | public, | parameter | :: | TTY_B4800 | = | 4800 | |
integer, | public, | parameter | :: | TTY_B9600 | = | 9600 | |
integer, | public, | parameter | :: | TTY_B19200 | = | 19200 | |
integer, | public, | parameter | :: | TTY_B38400 | = | 38400 | |
integer, | public, | parameter | :: | TTY_B57600 | = | 57600 | |
integer, | public, | parameter | :: | TTY_B115200 | = | 115200 | |
integer, | public, | parameter | :: | TTY_B230400 | = | 230400 | |
integer, | public, | parameter | :: | TTY_B460800 | = | 460800 | |
integer, | public, | parameter | :: | TTY_B921600 | = | 921600 | |
integer, | public, | parameter | :: | TTY_PARITY_NAME_LEN | = | 4 |
Parity string length. |
integer, | public, | parameter | :: | TTY_PARITY_NONE | = | 1 |
No parity. |
integer, | public, | parameter | :: | TTY_PARITY_EVEN | = | 2 |
Even parity. |
integer, | public, | parameter | :: | TTY_PARITY_ODD | = | 3 |
Odd parity. |
integer, | public, | parameter | :: | TTY_BYTE_SIZE5 | = | 1 |
5 bits. |
integer, | public, | parameter | :: | TTY_BYTE_SIZE6 | = | 2 |
6 bits. |
integer, | public, | parameter | :: | TTY_BYTE_SIZE7 | = | 3 |
7 bits. |
integer, | public, | parameter | :: | TTY_BYTE_SIZE8 | = | 4 |
8 bits. |
integer, | public, | parameter | :: | TTY_STOP_BITS1 | = | 1 |
1 stop bit. |
integer, | public, | parameter | :: | TTY_STOP_BITS2 | = | 2 |
2 stop bits. |
Generic TTY read function.
Reads from TTY into buf
until delimiter del
occurs. The
number of bytes read is returned in n
.
The function returns the following error codes:
E_BOUNDS
if end of buffer is reached.E_READ
if the read operation failed.Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tty_type), | intent(inout) | :: | tty |
TTY type. |
||
character(len=*), | intent(inout) | :: | bytes |
Input buffer. |
||
character(len=*), | intent(in) | :: | del |
Delimiter. |
||
integer(kind=i8), | intent(out), | optional | :: | nbytes |
Number of bytes read. |
Reads TTY response into request. The request delimiter is unescaped. The response is escaped before being stored in the request.
The function returns the following error codes:
E_BOUNDS
if the response is longer than REQUEST_RESPONSE_LEN
.E_READ
if reading from TTY failed.Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tty_type), | intent(inout) | :: | tty |
TTY type. |
||
type(request_type), | intent(inout) | :: | request |
Request type. |
Generic TTY write function.
Writes given string to TTY. Returns E_WRITE
on error. The function
may cause an access violation if nbytes
is greater than the length
of bytes
. Returns E_WRITE
on error.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tty_type), | intent(inout) | :: | tty |
TTY type. |
||
character(len=*), | intent(in), | target | :: | bytes |
Bytes to send. |
|
integer, | intent(in), | optional | :: | nbytes |
Number of bytes to send. |
Writes given request to TTY. The function unescapes the request
string. The function returns E_WRITE
on error.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tty_type), | intent(inout) | :: | tty |
TTY type. |
||
type(request_type), | intent(inout) | :: | request |
Request type |
TTY/PTY data type that stores serial port settings (default: 9600 baud, 8N1).
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character(len=FILE_PATH_LEN), | public | :: | path | = | ' ' |
TTY/PTY path. |
|
integer, | public | :: | access | = | TTY_RDWR |
Access mode (read/write). |
|
integer, | public | :: | baud_rate | = | TTY_B9600 |
Baud rate (9600). |
|
integer, | public | :: | byte_size | = | TTY_BYTE_SIZE8 |
Byte size (8). |
|
integer, | public | :: | stop_bits | = | TTY_STOP_BITS1 |
Stop bits (1). |
|
integer, | public | :: | parity | = | TTY_PARITY_NONE |
Parity (none). |
|
integer, | public | :: | timeout | = | 5 |
Read timeout in seconds. |
|
logical, | public | :: | dtr | = | .false. |
Data Terminal Ready. |
|
logical, | public | :: | rts | = | .false. |
Request To Send. |
|
logical, | public | :: | blocking | = | .true. |
Blocking read. |
Returns baud rate enumerator from numeric value. If the value is
invalid, returns 0 by default and sets optional argument error
to
E_INVALID
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | value |
Numeric baud rate value. |
||
integer, | intent(out), | optional | :: | error |
Error code. |
Returns byte size enumerator from numeric value. If the value is
invalid, returns 0 by default and sets optional argument error
to E_INVALID
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | value |
Numeric byte size value. |
||
integer, | intent(out), | optional | :: | error |
Error code. |
Flushes TTY input and output buffer. Returns E_INVALID
if the
passed tty
type is invalid, or E_SYSTEM
if the system call
failed.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tty_type), | intent(inout) | :: | tty |
TTY type. |
||
logical, | intent(in), | optional | :: | input |
Flush input buffer. |
|
logical, | intent(in), | optional | :: | output |
Flush output buffer. |
Return .true.
if TTY is connected, else .false.
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tty_type), | intent(inout) | :: | tty |
TTY type. |
Returns .true.
if given baud rate value is valid, else .false.
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | baud_rate |
Baud rate. |
Returns .true.
if given byte size value is valid, else .false.
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | byte_size |
Byte size. |
Returns .true.
if given parity value is valid, else .false.
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | parity |
Parity. |
Returns .true.
if given stop bits value is valid, else .false.
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | stop_bits |
Stop bits. |
Returns .true.
if given timeout value is valid, else .false.
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | timeout |
Timeout. |
Opens TTY/PTS device in set access mode and applies serial port
attributes. The arguments baud_rate
, byte_size
, parity
, and
stop_bits
must be valid enumerators.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tty_type), | intent(inout) | :: | tty |
TTY type. |
||
character(len=*), | intent(in), | optional | :: | path |
Device path. |
|
integer, | intent(in), | optional | :: | baud_rate |
Baud rate enumerator ( |
|
integer, | intent(in), | optional | :: | byte_size |
Byte size enumerator ( |
|
integer, | intent(in), | optional | :: | parity |
Parity enumerator ( |
|
integer, | intent(in), | optional | :: | stop_bits |
Stop bits enumerator ( |
Returns parity from character string (none
, even
, odd
). If the
parity is not recognised, returns 0 by default and sets optional
argument error
to E_INVALID
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | name |
Parity name. |
||
integer, | intent(out), | optional | :: | error |
Error code. |
Reads single byte from file descriptor.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tty_type), | intent(inout) | :: | tty |
TTY type. |
||
character(len=1), | intent(out), | target | :: | byte |
Byte read. |
Reads from TTY into buf
until delimiter del
occurs. The
number of bytes read is returned in n
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tty_type), | intent(inout) | :: | tty |
TTY type. |
||
character(len=*), | intent(inout) | :: | bytes |
Input buffer. |
||
character(len=*), | intent(in) | :: | del |
Delimiter. |
||
integer(kind=i8), | intent(out), | optional | :: | nbytes |
Number of bytes read. |
Reads TTY response into request. The request delimiter is unescaped. The response is escaped before being stored in the request.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tty_type), | intent(inout) | :: | tty |
TTY type. |
||
type(request_type), | intent(inout) | :: | request |
Request type. |
Sets terminal attributes.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tty_type), | intent(inout) | :: | tty |
TTY type. |
Sets TTY to blocking or non-blocking.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tty_type), | intent(inout) | :: | tty |
TTY type. |
||
logical, | intent(in) | :: | blocking |
Blocking mode. |
Sets timeout of given TTY. A timeout of 0 results in blocking read without timeout. The minimum timeout is 0 seconds, the maximum is 25 seconds.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tty_type), | intent(inout) | :: | tty |
TTY type. |
||
integer, | intent(in) | :: | timeout |
Timeout in seconds. |
Returns stop bits enumerator from numeric value. If the value is
invalid, returns 0 by default and sets optional argument error
to E_INVALID
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | value |
Numeric byte size value. |
||
integer, | intent(out), | optional | :: | error |
Error code. |
Writes given string to TTY. Returns E_WRITE
on error. The function
may cause an access violation if nbytes
is greater than the length
of bytes
. Returns E_WRITE
on error.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tty_type), | intent(inout) | :: | tty |
TTY type. |
||
character(len=*), | intent(in), | target | :: | bytes |
Bytes to send. |
|
integer, | intent(in), | optional | :: | nbytes |
Number of bytes to send. |
Writes given request to TTY. The function unescapes the request
string. The function returns E_WRITE
on error.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tty_type), | intent(inout) | :: | tty |
TTY type. |
||
type(request_type), | intent(inout) | :: | request |
Request type |
Closes file descriptor.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tty_type), | intent(inout) | :: | tty |
TTY type. |