kstars
TTY Functions: Functions to perform common terminal access routines.
Functions | |
| int | tty_connect (const char *device, int bit_rate, int word_size, int parity, int stop_bits, int *fd) |
| int | tty_disconnect (int fd) |
| void | tty_error_msg (int err_code, char *err_msg, int err_msg_len) |
| int | tty_read (int fd, char *buf, int nbytes, int timeout, int *nbytes_read) |
| int | tty_read_section (int fd, char *buf, char stop_char, int timeout, int *nbytes_read) |
| int | tty_timeout (int fd, int timeout) |
| int | tty_write (int fd, const char *buffer, int nbytes, int *nbytes_written) |
| int | tty_write_string (int fd, const char *buffer, int *nbytes_written) |
Function Documentation
| 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:
-
device the device node. e.g. /dev/ttyS0 bit_rate bit rate word_size number of data bits, 7 or 8, USE 8 DATA BITS with modbus parity 0=no parity, 1=parity EVEN, 2=parity ODD stop_bits number of stop bits : 1 or 2 fd fd is set to the file descriptor value on success.
- Returns:
- On success, it returns TTY_OK, otherwise, a TTY_ERROR code.
| int tty_disconnect | ( | int | fd | ) |
Closes a tty connection and flushes the bus.
- Parameters:
-
fd the file descriptor to close.
- Returns:
- On success, it returns TTY_OK, otherwise, a TTY_ERROR code.
| void tty_error_msg | ( | int | err_code, | |
| char * | err_msg, | |||
| int | err_msg_len | |||
| ) |
Retrieve the tty error message.
- Parameters:
-
err_code the error code return by any TTY function. err_msg an initialized buffer to hold the error message. err_msg_len length in bytes of err_msg
| int tty_read | ( | int | fd, | |
| char * | buf, | |||
| int | nbytes, | |||
| int | timeout, | |||
| int * | nbytes_read | |||
| ) |
read buffer from terminal
- Parameters:
-
fd file descriptor buf pointer to store data. Must be initilized and big enough to hold data. nbytes number of bytes to read. timeout number of seconds to wait for terminal before a timeout error is issued. nbytes_read the number of bytes read.
- Returns:
- On success, it returns TTY_OK, otherwise, a TTY_ERROR code.
| int tty_read_section | ( | int | fd, | |
| char * | buf, | |||
| char | stop_char, | |||
| int | timeout, | |||
| int * | nbytes_read | |||
| ) |
read buffer from terminal with a delimiter
- Parameters:
-
fd file descriptor buf pointer to store data. Must be initilized and big enough to hold data. stop_char if the function encounters stop_char then it stops reading and returns the buffer. timeout number of seconds to wait for terminal before a timeout error is issued. nbytes_read the number of bytes read.
- Returns:
- On success, it returns TTY_OK, otherwise, a TTY_ERROR code.
| int tty_timeout | ( | int | fd, | |
| int | timeout | |||
| ) |
| int tty_write | ( | int | fd, | |
| const char * | buffer, | |||
| int | nbytes, | |||
| int * | nbytes_written | |||
| ) |
Writes a buffer to fd.
- Parameters:
-
fd file descriptor buffer a null-terminated buffer to write to fd. nbytes number of bytes to write from buffer nbytes_written the number of bytes written
- Returns:
- On success, it returns TTY_OK, otherwise, a TTY_ERROR code.
| int tty_write_string | ( | int | fd, | |
| const char * | buffer, | |||
| int * | nbytes_written | |||
| ) |
Writes a null terminated string to fd.
- Parameters:
-
fd file descriptor buffer the buffer to write to fd. nbytes_written the number of bytes written
- Returns:
- On success, it returns TTY_OK, otherwise, a TTY_ERROR code.
KDE 4.2 API Reference