TwiceAsNice  2019-02-18
Functions
TTY Functions: Functions to perform common terminal access routines.

Functions

int tty_read (int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
 read buffer from terminal More...
 
int tty_read_section (int fd, char *buf, char stop_char, int timeout, int *nbytes_read)
 read buffer from terminal with a delimiter More...
 
int tty_nread_section (int fd, char *buf, int nsize, char stop_char, int timeout, int *nbytes_read)
 read buffer from terminal with a delimiter More...
 
int tty_write (int fd, const char *buffer, int nbytes, int *nbytes_written)
 Writes a buffer to fd. More...
 
int tty_write_string (int fd, const char *buffer, int *nbytes_written)
 Writes a null terminated string to fd. More...
 
int tty_connect (const char *device, int bit_rate, int word_size, int parity, int stop_bits, int *fd)
 Establishes a tty connection to a terminal device. More...
 
int tty_disconnect (int fd)
 Closes a tty connection and flushes the bus. More...
 
void tty_error_msg (int err_code, char *err_msg, int err_msg_len)
 Retrieve the tty error message. More...
 
void tty_set_debug (int debug)
 tty_set_debug Enable or disable debug which prints verbose information. More...
 
void tty_set_gemini_udp_format (int enabled)
 
void tty_clr_trailing_read_lf (int enabled)
 
int tty_timeout (int fd, int timeout)
 

Detailed Description

Function Documentation

◆ tty_clr_trailing_read_lf()

void tty_clr_trailing_read_lf ( int  enabled)

◆ tty_connect()

int tty_connect ( const char *  device,
int  bit_rate,
int  word_size,
int  parity,
int  stop_bits,
int *  fd 
)

Establishes a tty connection to a terminal device.

Parameters
devicethe device node. e.g. /dev/ttyS0
bit_ratebit rate
word_sizenumber of data bits, 7 or 8, USE 8 DATA BITS with modbus
parity0=no parity, 1=parity EVEN, 2=parity ODD
stop_bitsnumber of stop bits : 1 or 2
fdfd is set to the file descriptor value on success.
Returns
On success, it returns TTY_OK, otherwise, a TTY_ERROR code.
Author
Wildi Markus

◆ tty_disconnect()

int tty_disconnect ( int  fd)

Closes a tty connection and flushes the bus.

Parameters
fdthe file descriptor to close.
Returns
On success, it returns TTY_OK, otherwise, a TTY_ERROR code.

◆ tty_error_msg()

void tty_error_msg ( int  err_code,
char *  err_msg,
int  err_msg_len 
)

Retrieve the tty error message.

Parameters
err_codethe error code return by any TTY function.
err_msgan initialized buffer to hold the error message.
err_msg_lenlength in bytes of err_msg

◆ tty_nread_section()

int tty_nread_section ( int  fd,
char *  buf,
int  nsize,
char  stop_char,
int  timeout,
int *  nbytes_read 
)

read buffer from terminal with a delimiter

Parameters
fdfile descriptor
bufpointer to store data. Must be initilized and big enough to hold data.
stop_charif the function encounters stop_char then it stops reading and returns the buffer.
nsizesize of buf. If stop character is not encountered before nsize, the function aborts.
timeoutnumber of seconds to wait for terminal before a timeout error is issued.
nbytes_readthe number of bytes read.
Returns
On success, it returns TTY_OK, otherwise, a TTY_ERROR code.

◆ tty_read()

int tty_read ( int  fd,
char *  buf,
int  nbytes,
int  timeout,
int *  nbytes_read 
)

read buffer from terminal

Parameters
fdfile descriptor
bufpointer to store data. Must be initilized and big enough to hold data.
nbytesnumber of bytes to read.
timeoutnumber of seconds to wait for terminal before a timeout error is issued.
nbytes_readthe number of bytes read.
Returns
On success, it returns TTY_OK, otherwise, a TTY_ERROR code.

◆ tty_read_section()

int tty_read_section ( int  fd,
char *  buf,
char  stop_char,
int  timeout,
int *  nbytes_read 
)

read buffer from terminal with a delimiter

Parameters
fdfile descriptor
bufpointer to store data. Must be initilized and big enough to hold data.
stop_charif the function encounters stop_char then it stops reading and returns the buffer.
timeoutnumber of seconds to wait for terminal before a timeout error is issued.
nbytes_readthe number of bytes read.
Returns
On success, it returns TTY_OK, otherwise, a TTY_ERROR code.

◆ tty_set_debug()

void tty_set_debug ( int  debug)

tty_set_debug Enable or disable debug which prints verbose information.

Parameters
debug1 to enable, 0 to disable

◆ tty_set_gemini_udp_format()

void tty_set_gemini_udp_format ( int  enabled)

◆ tty_timeout()

int tty_timeout ( int  fd,
int  timeout 
)

◆ tty_write()

int tty_write ( int  fd,
const char *  buffer,
int  nbytes,
int *  nbytes_written 
)

Writes a buffer to fd.

Parameters
fdfile descriptor
buffera null-terminated buffer to write to fd.
nbytesnumber of bytes to write from buffer
nbytes_writtenthe number of bytes written
Returns
On success, it returns TTY_OK, otherwise, a TTY_ERROR code.

◆ tty_write_string()

int tty_write_string ( int  fd,
const char *  buffer,
int *  nbytes_written 
)

Writes a null terminated string to fd.

Parameters
fdfile descriptor
bufferthe buffer to write to fd.
nbytes_writtenthe number of bytes written
Returns
On success, it returns TTY_OK, otherwise, a TTY_ERROR code.