�
��^� � �h � d Z ddlmZ ddlZddlZ G d� de� � Z G d� 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.
� )�absolute_importNc � � e Zd Z dd�ZdS )�
RS485SettingsTFNc �L � || _ || _ || _ || _ || _ d S �N)�rts_level_for_tx�rts_level_for_rx�loopback�delay_before_tx�delay_before_rx)�selfr r r
r r s �./usr/lib/python3/dist-packages/serial/rs485.py�__init__zRS485Settings.__init__ s1 � � !1��� 0��� ��
�.���.����� )TFFNN)�__name__�
__module__�__qualname__r � r r r r s9 � � � � � � "�"�� � �
/� /� /� /� /� /r r c �b � � e Zd ZdZ� fd�Z� fd�Zed� � � Zej d� � � Z� xZ 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 �V �� t t | � � j |i |�� d | _ d S r )�superr r �_alternate_rs485_settings)r
�args�kwargs� __class__s �r r zRS485.__init__= s3 �� �#��e�T���#�T�4�V�4�4�4�)-��&�&�&r c �, �� | j ��| � | j j � � | j j �t j | j j � � t
t | � � � |� � t
t | � � � � � | j j
�t j | j j
� � | � | j j � � dS t
t | � � � |� � dS )z=Write to port, controlling RTS before and after transmitting.N)r �setRTSr r �time�sleepr r �write�flushr r )r
�br s �r r! zRS485.writeA s� �� ��)�5��K�K��6�G�H�H�H��-�=�I��
�4�9�I�J�J�J��%����$�$�Q�'�'�'��%����$�$�&�&�&��-�=�I��
�4�9�I�J�J�J��K�K��6�G�H�H�H�H�H��%����$�$�Q�'�'�'�'�'r c � � | 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
s r �
rs485_modezRS485.rs485_modeT s
� � �-�-r c � � || _ d S r r% )r
�rs485_settingss r r& |