3
MÊ]WÁ ã @ s: d Z ddlZddlZG dd„ deƒZG dd„ dejƒZdS )zµThe settings for RS485 are stored in a dedicated object that can be applied to
serial ports (where supported).
NOTE: Some implementations may only support a subset of the settings.
é Nc @ s e Zd Zddd„ZdS )Ú
RS485SettingsTFNc C s" || _ || _|| _|| _|| _d S )N)Úrts_level_for_txÚrts_level_for_rxÚloopbackÚdelay_before_txÚdelay_before_rx)Úselfr r r r r © r ú/usr/lib/python3.6/rs485.pyÚ__init__ s
zRS485Settings.__init__)TFFNN)Ú__name__Ú
__module__Ú__qualname__r r r r r
r s
r c sF e Zd ZdZ‡ fdd„Z‡ fdd„Zedd„ ƒZejdd„ ƒZ‡ Z S ) ÚRS485a5 A subclass that replaces the write method with one that toggles RTS
according to the RS485 settings.
NOTE: This may work unreliably on some serial ports (control signals not
synchronized or delayed compared to data). Using delays may be
unreliable (varying times, larger than expected) as the OS may not
support very fine grained delays (no smaller than in the order of
tens of milliseconds).
NOTE: Some implementations support this natively. Better performance
can be expected when the native version is used.
NOTE: The loopback property is ignored by this implementation. The actual
behavior depends on the used hardware.
Usage:
ser = RS485(...)
ser.rs485_mode = RS485Settings(...)
ser.write(b'hello')
c s t t| ƒj||Ž d | _d S )N)Úsuperr r Ú_alternate_rs485_settings)r ÚargsÚkwargs)Ú __class__r r
r ; s zRS485.__init__c sŽ | j dk rz| j| j jƒ | j jdk r2tj| j jƒ tt| ƒj|ƒ tt| ƒj ƒ | j j
dk rjtj| j j
ƒ | j| j jƒ ntt| ƒj|ƒ dS )z=Write to port, controlling RTS before and after transmitting.N)r ZsetRTSr r ÚtimeZsleepr r ÚwriteÚflushr r )r Úb)r r r
r ? s
zRS485.writec C s | j S )z˜ Enable RS485 mode and apply new settings, set to None to disable.
See serial.rs485.RS485Settings for more info about the value.
)r )r r r r
Ú
rs485_modeR s zRS485.rs485_modec C s
|| _ d S )N)r )r Zrs485_settingsr r r
r Z s )
r r
r Ú__doc__r r Úpropertyr ÚsetterÚ
__classcell__r r )r r
r # s
r )r r ÚserialÚobjectr ZSerialr r r r r
Ú