tinyproto
Serial port API
tiny_serial_handle_t tiny_serial_open (const char *name, uint32_t baud)
 Opens serial port. More...
 
void tiny_serial_close (tiny_serial_handle_t port)
 Closes serial connection. More...
 
int tiny_serial_send (tiny_serial_handle_t port, const void *buf, int len)
 Sends data over serial connection. More...
 
int tiny_serial_send_timeout (tiny_serial_handle_t port, const void *buf, int len, uint32_t timeout_ms)
 Sends data over serial connection. More...
 
int tiny_serial_read (tiny_serial_handle_t port, void *buf, int len)
 Receive data from serial connection. More...
 
int tiny_serial_read_timeout (tiny_serial_handle_t port, void *buf, int len, uint32_t timeout_ms)
 Receive data from serial connection. More...
 

Detailed Description

Serial port API

Function Documentation

◆ tiny_serial_close()

void tiny_serial_close ( tiny_serial_handle_t  port)

Closes serial connection.

Closes serial connection

Parameters
porthandle to serial port

◆ tiny_serial_open()

tiny_serial_handle_t tiny_serial_open ( const char *  name,
uint32_t  baud 
)

Opens serial port.

Opens serial port by name

Parameters
namepath to the port to open For linux this can be "/dev/ttyO1", "/dev/ttyS1", "/dev/ttyUSB0", etc. For windows this can be "COM1", "COM2", etc. For ESP32 IDF the line should in format "uart0,tx,rx,rts,cts", where uart0 - uart hardware device number ("uart1", "uart2"); "tx", "rx", "rts", "cts" are optional arguments, specifying integer pin numbers (-1 to use standard pin). For Arduino this is must be pointer to HardwareSerial class
baudbaud rate in bits
Returns
valid serial handle or TINY_SERIAL_INVALID in case of error

◆ tiny_serial_read()

int tiny_serial_read ( tiny_serial_handle_t  port,
void *  buf,
int  len 
)

Receive data from serial connection.

Receive data from serial connection with 100ms timeout.

Parameters
porthandle to serial port
bufpointer to data buffer to read to
lenmaximum size of receive buffer
Returns
negative value in case of error. or number of bytes received

◆ tiny_serial_read_timeout()

int tiny_serial_read_timeout ( tiny_serial_handle_t  port,
void *  buf,
int  len,
uint32_t  timeout_ms 
)

Receive data from serial connection.

Receive data from serial connection.

Parameters
porthandle to serial port
bufpointer to data buffer to read to
lenmaximum size of receive buffer
timeout_mstimeout in milliseconds to wait for incoming data
Returns
negative value in case of error. or number of bytes received

◆ tiny_serial_send()

int tiny_serial_send ( tiny_serial_handle_t  port,
const void *  buf,
int  len 
)

Sends data over serial connection.

Sends data over serial connection with 100 ms timeout.

Parameters
porthandle to serial port
bufpointer to data buffer to send
lenlength of data to send
Returns
negative value in case of error. or number of bytes sent

◆ tiny_serial_send_timeout()

int tiny_serial_send_timeout ( tiny_serial_handle_t  port,
const void *  buf,
int  len,
uint32_t  timeout_ms 
)

Sends data over serial connection.

Sends data over serial connection.

Parameters
porthandle to serial port
bufpointer to data buffer to send
lenlength of data to send
timeout_mstimeout in milliseconds to wait until data are sent
Returns
negative value in case of error. or number of bytes sent