O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
serial.h File Reference

Configure and read from serial ports as buffered input streams. More...

#include "o2s/file_input_stream.h"
#include "o2s/serial_options.h"
#include <stdbool.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  serial_port_t
 Serial port handler, includes a buffer. More...

Macros

#define Serial
 Use the RAII with serial ports.

Functions

Contructor and destructor
serial_port_t serial_open_readonly (const char *port_name)
 Open the port in read-only, and allocate the buffer.
serial_port_t serial_open_readwrite (const char *port_name)
 Open the port in read and write, and allocate the buffer.
void serial_close (serial_port_t *port)
 Closes the specified serial port.
serial_port_t * serial_new_readwrite (const char *port_name)
 Allocates a serial port and opens it.
void serial_free (serial_port_t **port)
 Close and free a serial port created with serial_new_readwrite.
Modifiers
bool serial_get_options (serial_port_t *port)
 Ask the port for its configuration.
bool serial_apply_options (serial_port_t *port)
 Apply the options immediatly.
bool serial_set_options_raw (serial_port_t *port)
 Modify the copy of the options, but do not apply them.
bool serial_set_options_speed (serial_port_t *port, int64_t speed_bps)
 Modify the copy of the options about speed, but do not apply them.
bool serial_make_raw (serial_port_t *port, int64_t speed_bps)
 General configuration for non-canonical mode.
Utilities
int64_t serial_decode_baudrate (speed_t flag)
 Convert the baudrate from termios to bits per second.
speed_t serial_encode_baudrate (int64_t speed_in_bps)
 Convert the baudrate to a system specific enum.

Detailed Description

Configure and read from serial ports as buffered input streams.

Author
Antoine GAGNIERE

Definition in file serial.h.

Macro Definition Documentation

◆ Serial

#define Serial

Use the RAII with serial ports.

In a situation where one wants to declare a serial port variable on the stack in the local scope, this "typedef" can be used for the port to be closed automatically when the variable goes out of scope.

It means this "typedef" can only be used like this :

{
Serial port = serial_open(...);
...
} // <- The port will be closed at that point
#define Serial
Use the RAII with serial ports.
Definition serial.h:76

Definition at line 76 of file serial.h.

Function Documentation

◆ serial_close()

void serial_close ( serial_port_t * port)

Closes the specified serial port.

See also
file_close

Definition at line 21 of file close.c.

◆ serial_decode_baudrate()

int64_t serial_decode_baudrate ( speed_t flag)

Convert the baudrate from termios to bits per second.

Returns
  • A line speed in bits per second
  • -1 if the value isn't part of the possible values

Definition at line 28 of file baudrate.c.

◆ serial_encode_baudrate()

speed_t serial_encode_baudrate ( int64_t speed_in_bps)

Convert the baudrate to a system specific enum.

Returns
  • A system specific value, as define in termios.h
  • 0 if the value wasn't an accepted value.

Definition at line 74 of file baudrate.c.

◆ serial_make_raw()

bool serial_make_raw ( serial_port_t * port,
int64_t speed_bps )

General configuration for non-canonical mode.

Sets the terminal to something like the "raw" mode of the old Version 7 terminal driver: input is available character by character, echoing is disabled, and all special processing of terminal input and output characters is disabled.

Definition at line 88 of file make_raw.c.

◆ serial_set_options_raw()

bool serial_set_options_raw ( serial_port_t * port)

Modify the copy of the options, but do not apply them.

See also
serial_make_raw

Definition at line 29 of file make_raw.c.