Mbed OS Reference
Loading...
Searching...
No Matches
UnbufferedSerial class

Data Structures

class  UnbufferedSerial
 Class implementation for unbuffered I/O for an interrupt driven application or one that needs to have more control. More...
 

Functions

 UnbufferedSerial (PinName tx, PinName rx, int baud=MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
 Create a serial port instance connected to the specified transmit and receive pins, with the specified baud rate. More...
 
 UnbufferedSerial (const serial_pinmap_t &static_pinmap, int baud=MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
 Create a UnbufferedSerial port, connected to the specified transmit and receive pins, with a particular baud rate. More...
 
ssize_t write (const void *buffer, size_t size) override
 Write the contents of a buffer to a file. More...
 
ssize_t read (void *buffer, size_t size) override
 Read the contents of a file into a buffer. More...
 
off_t seek (off_t offset, int whence=SEEK_SET) override
 Move the file position to a given offset from from a given location. More...
 
off_t size () override
 Get the size of the file. More...
 
int isatty () override
 Check if the file in an interactive terminal device. More...
 
int close () override
 Close a file. More...
 
int enable_input (bool enabled) override
 Enable or disable input. More...
 
int enable_output (bool enabled) override
 Enable or disable output. More...
 
short poll (short events) const override
 Check for poll event flags Check the events listed in events to see if data can be read or written without blocking. More...
 
void set_flow_control (Flow type, PinName flow1=NC, PinName flow2=NC)
 Set the flow control type on the serial port. More...
 

Detailed Description

Function Documentation

◆ UnbufferedSerial() [1/2]

UnbufferedSerial ( PinName  tx,
PinName  rx,
int  baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE 
)

Create a serial port instance connected to the specified transmit and receive pins, with the specified baud rate.

Parameters
txTransmit pin
rxReceive pin
baudThe baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE, which is set via platform.default-serial-baud-rate in mbed_app.json)
Note
Either tx or rx may be specified as NC if unused

◆ UnbufferedSerial() [2/2]

UnbufferedSerial ( const serial_pinmap_t static_pinmap,
int  baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE 
)

Create a UnbufferedSerial port, connected to the specified transmit and receive pins, with a particular baud rate.

Parameters
static_pinmapreference to structure which holds static pinmap
baudThe baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE, which is set via platform.default-serial-baud-rate in mbed_app.json)

◆ write()

ssize_t write ( const void *  buffer,
size_t  size 
)
overridevirtual

Write the contents of a buffer to a file.

Blocks until all data is written

Parameters
bufferThe buffer to write from
sizeThe number of bytes to write
Returns
The number of bytes written

Implements FileHandle.

◆ read()

ssize_t read ( void *  buffer,
size_t  size 
)
overridevirtual

Read the contents of a file into a buffer.

Blocks and reads exactly one character

Parameters
bufferThe buffer to read in to
sizeThe number of bytes to read
Returns
The number of bytes read

Implements FileHandle.

◆ seek()

off_t seek ( off_t  offset,
int  whence = SEEK_SET 
)
overridevirtual

Move the file position to a given offset from from a given location.

Not valid for a device type FileHandle like UnbufferedSerial. In case of UnbufferedSerial, returns ESPIPE

Parameters
offsetThe offset from whence to move to
whenceThe start of where to seek SEEK_SET to start from beginning of file, SEEK_CUR to start from current position in file, SEEK_END to start from end of file
Returns
The new offset of the file, negative error code on failure

Implements FileHandle.

Definition at line 114 of file UnbufferedSerial.h.

◆ size()

off_t size ( )
overridevirtual

Get the size of the file.

Returns
Size of the file in bytes

Reimplemented from FileHandle.

Definition at line 123 of file UnbufferedSerial.h.

◆ isatty()

int isatty ( )
overridevirtual

Check if the file in an interactive terminal device.

Returns
True if the file is a terminal
False if the file is not a terminal
Negative error code on failure

Reimplemented from FileHandle.

Definition at line 134 of file UnbufferedSerial.h.

◆ close()

int close ( )
overridevirtual

Close a file.

Returns
0 on success, negative error code on failure

Implements FileHandle.

Definition at line 143 of file UnbufferedSerial.h.

◆ enable_input()

int enable_input ( bool  enabled)
overridevirtual

Enable or disable input.

Control enabling of device for input. This is primarily intended for temporary power-saving; the overall ability of the device to operate for input and/or output may be fixed at creation time, but this call can allow input to be temporarily disabled to permit power saving without losing device state.

Parameters
enabledtrue to enable input, false to disable.
Returns
0 on success
Negative error code on failure

Reimplemented from FileHandle.

◆ enable_output()

int enable_output ( bool  enabled)
overridevirtual

Enable or disable output.

Control enabling of device for output. This is primarily intended for temporary power-saving; the overall ability of the device to operate for input and/or output may be fixed at creation time, but this call can allow output to be temporarily disabled to permit power saving without losing device state.

Parameters
enabledtrue to enable output, false to disable.
Returns
0 on success
Negative error code on failure

Reimplemented from FileHandle.

◆ poll()

short poll ( short  events) const
overridevirtual

Check for poll event flags Check the events listed in events to see if data can be read or written without blocking.

Call is nonblocking - returns state of events.

Parameters
eventsbitmask of poll events we're interested in - POLLIN/POLLOUT etc.
Returns
bitmask of poll events that have occurred.

Reimplemented from FileHandle.

◆ set_flow_control()

void set_flow_control ( Flow  type,
PinName  flow1 = NC,
PinName  flow2 = NC 
)

Set the flow control type on the serial port.

Parameters
typethe flow control type (Disabled, RTS, CTS, RTSCTS)
flow1the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS)
flow2the second flow control pin (CTS for RTSCTS)