<s> """<STR_LIT>""" <EOL> import time <EOL> import serial <EOL> class RS485Settings ( object ) : <EOL> def __init__ ( <EOL> self , <EOL> rts_level_for_tx = True , <EOL> rts_level_for_rx = False , <EOL> loopback = False , <EOL> delay_before_tx = None , <EOL> delay_before_rx = None ) : <EOL> self . rts_level_for_tx = rts_level_for_tx <EOL> self . rts_level_for_rx = rts_level_for_rx <EOL> self . loopback = loopback <EOL> self . delay_before_tx = delay_before_tx <EOL> self . delay_before_rx = delay_before_rx <EOL> class RS485 ( serial . Serial ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( RS485 , self ) . __init__ ( * args , ** kwargs ) <EOL> self . _alternate_rs485_settings = None <EOL> def write ( self , b ) : <EOL> """<STR_LIT>""" <EOL> if self . _alternate_rs485_settings is not None : <EOL> self . setRTS ( self . _alternate_rs485_settings . rts_level_for_tx ) <EOL> if self . _alternate_rs485_settings . delay_before_tx is not None : <EOL> time . sleep ( self . _alternate_rs485_settings . delay_before_tx ) <EOL> super ( RS485 , self ) . write ( b ) <EOL> super ( RS485 , self ) . flush ( ) <EOL> if self . _alternate_rs485_settings . delay_before_rx is not None : <EOL> time . sleep ( self . _alternate_rs485_settings . delay_before_rx ) <EOL> self . setRTS ( self . _alternate_rs485_settings . rts_level_for_rx ) <EOL> else : <EOL> super ( RS485 , self ) . write ( b ) <EOL> @ property <EOL> def rs485_mode ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _alternate_rs485_settings <EOL> @ rs485_mode . setter <EOL> def rs485_mode ( self , rs485_settings ) : <EOL> self . _alternate_rs485_settings = rs485_settings </s>
