Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/ioctl.h>
- #include <linux/serial.h>
- #include <stdbool.h>
- int uart_get_rs485_config( int fd, struct serial_rs485 *config )
- {
- return ioctl( fd, TIOCGRS485, config );
- }
- int uart_set_rs485_config( int fd, struct serial_rs485 const *config )
- {
- return ioctl( fd, TIOCSRS485, config );
- }
- int uart_enable_rs485( int fd, bool active_low )
- {
- struct serial_rs485 config;
- int res = uart_get_rs485_config( fd, &config );
- if( res < 0 )
- return res;
- if( active_low ) {
- config.flags &= ~SER_RS485_RTS_ON_SEND;
- config.flags |= SER_RS485_RTS_AFTER_SEND;
- } else {
- config.flags |= SER_RS485_RTS_ON_SEND;
- config.flags &= ~SER_RS485_RTS_AFTER_SEND;
- }
- config.flags |= SER_RS485_ENABLED;
- return uart_set_rs485_config( fd, &config );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement