Advertisement
zmatt

rs485.c

Dec 12th, 2018 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <sys/ioctl.h>
  2. #include <linux/serial.h>
  3. #include <stdbool.h>
  4.  
  5. int uart_get_rs485_config( int fd, struct serial_rs485 *config )
  6. {
  7.     return ioctl( fd, TIOCGRS485, config );
  8. }
  9.  
  10. int uart_set_rs485_config( int fd, struct serial_rs485 const *config )
  11. {
  12.     return ioctl( fd, TIOCSRS485, config );
  13. }
  14.  
  15. int uart_enable_rs485( int fd, bool active_low )
  16. {
  17.     struct serial_rs485 config;
  18.     int res = uart_get_rs485_config( fd, &config );
  19.     if( res < 0 )
  20.         return res;
  21.     if( active_low ) {
  22.         config.flags &= ~SER_RS485_RTS_ON_SEND;
  23.         config.flags |= SER_RS485_RTS_AFTER_SEND;
  24.     } else {
  25.         config.flags |= SER_RS485_RTS_ON_SEND;
  26.         config.flags &= ~SER_RS485_RTS_AFTER_SEND;
  27.     }
  28.     config.flags |= SER_RS485_ENABLED;
  29.     return uart_set_rs485_config( fd, &config );
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement