#NEWLINE# def _set_rs485_mode( self , rs485_settings ) : #NEWLINE# #INDENT# buf = array . array ( 'i' , ( [ 0 ] * 8 ) ) #NEWLINE# try : #NEWLINE# #INDENT# fcntl . ioctl ( self . fd , TIOCGRS485 , buf ) #NEWLINE# buf [ 0 ] |= SER_RS485_ENABLED #NEWLINE# if ( rs485_settings is not None ) : #NEWLINE# #INDENT# if rs485_settings . loopback : #NEWLINE# #INDENT# buf [ 0 ] |= SER_RS485_RX_DURING_TX #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# buf [ 0 ] &= ( ~ SER_RS485_RX_DURING_TX ) #NEWLINE# #UNINDENT# if rs485_settings . rts_level_for_tx : #NEWLINE# #INDENT# buf [ 0 ] |= SER_RS485_RTS_ON_SEND #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# buf [ 0 ] &= ( ~ SER_RS485_RTS_ON_SEND ) #NEWLINE# #UNINDENT# if rs485_settings . rts_level_for_rx : #NEWLINE# #INDENT# buf [ 0 ] |= SER_RS485_RTS_AFTER_SEND #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# buf [ 0 ] &= ( ~ SER_RS485_RTS_AFTER_SEND ) #NEWLINE# #UNINDENT# buf [ 1 ] = int ( ( rs485_settings . delay_before_tx * 1000 ) ) #NEWLINE# buf [ 2 ] = int ( ( rs485_settings . delay_before_rx * 1000 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# buf [ 0 ] = 0 #NEWLINE# #UNINDENT# fcntl . ioctl ( self . fd , TIOCSRS485 , buf ) #NEWLINE# #UNINDENT# except IOError as e : #NEWLINE# #INDENT# raise ValueError ( 'Failed to set RS485 mode: {}' . format ( e ) )