Current File : //usr/lib/python3/dist-packages/serial/urlhandler/__pycache__/protocol_loop.cpython-312.pyc
�

��a_)���ddlmZddlZddlZddlZ	ddlZ	ddl	Z	ddlmZm
Z
mZmZmZmZej$ej&ej(ej*d�ZGd�de�Zedk(r�ddlZed�Zej6j9d	j;e��ej6j9d
�ej9d�ej=�ej6j9dj;ej?d
���ejA�yy#e$r
ddlmZY��wxYw#e$rddl
Z	Y��*wxYw)�)�absolute_importN)�
SerialBase�SerialException�to_bytes�	iterbytes�SerialTimeoutException�PortNotOpenError)�debug�info�warning�errorc����eZdZdZdZ�fd�Zd�Z�fd�Zd�Zd�Z	e
d��Zdd	�Zd
�Z
d�Zd�Zd
�Zd�Ze
d��Zd�Zd�Zd�Ze
d��Ze
d��Ze
d��Ze
d��Z�xZS)�SerialzSSerial port implementation that simulates a loop back connection in plain software.)�2�K�n����i,iXi�ii`	i�i�%iKi�i�i�c�d��d|_d|_d|_d|_t	t
|�|i|��y)NiF)�buffer_size�queue�logger�
_cancel_write�superr�__init__)�self�args�kwargs�	__class__s   ��A/usr/lib/python3/dist-packages/serial/urlhandler/protocol_loop.pyrzSerial.__init__/s5��������
����"���
�f�d�$�d�5�f�5�c���|jrtd��d|_tj|j
�|_|j�td��|j|j�|j�d|_|js|j�|js|j�|j�|j�y)zx        Open port with current settings. This may throw a SerialException
        if the port cannot be opened.
        zPort is already open.Nz.Port must be configured before it can be used.T)�is_openrrr�Queuer�_port�from_url�port�_reconfigure_port�_dsrdtr�_update_dtr_state�_rtscts�_update_rts_state�reset_input_buffer�reset_output_buffer�rs r!�openzSerial.open6s���
�<�<�!�"9�:�:�����[�[��!1�!1�2��
��:�:��!�"R�S�S�	
�
�
�d�i�i� �	
��� �����|�|��"�"�$��|�|��"�"�$����!�� � �"r"c���|jr#d|_	|jjd�tt
|��y#tj$rY�(wxYw)NF)r$r�
put_nowait�Fullrr�close)rr s �r!r5zSerial.closeQsO����<�<� �D�L�
��
�
�%�%�d�+�	�f�d�!�#���:�:�
��
�s�A�A�Ac��t|jtj�rd|jcxkrdks&nt	dj|j���|jr|jjd�yy)zx        Set communication parameters on opened port. For the loop://
        protocol all settings are ignored!
        rlzinvalid baudrate: {!r}z_reconfigure_port()N)�
isinstance�	_baudrate�numbers�Integral�
ValueError�formatrrr0s r!r)zSerial._reconfigure_portZsc���$�.�.�'�*:�*:�;�1�t�~�~�C_�X_�C_��5�<�<�T�^�^�L�M�M��;�;��K�K���2�3�r"c�r�tj|�}|jdk7r$tdj	|j���	tj
|jd�j�D]�\}}|dk(rotj�tjd�|_|jjt|d�|jjd��ztdj	|���y
#t$r}td	j	|���d
}~wwxYw)z(extract host and port from an URL string�loopznexpected a string in the form "loop://[?logging={debug|info|warning|error}]": not starting with loop:// ({!r})T�loggingz
pySerial.looprzenabled loggingzunknown option: {!r}zPexpected a string in the form "loop://[?logging={debug|info|warning|error}]": {}N)�urlparse�urlsplit�schemerr<�parse_qs�query�itemsr?�basicConfig�	getLoggerr�setLevel�
LOGGER_LEVELSr
r;)r�url�parts�option�values�es      r!r'zSerial.from_urles���!�!�#�&���<�<�6�!�!�&�&,�f�U�\�\�&:�<�
<�
	P�"*�"3�"3�E�K�K��"F�"L�"L�"N�
L�����Y�&��'�'�)�")�"3�"3�O�"D�D�K��K�K�(�(��v�a�y�)A�B��K�K�%�%�&7�8�$�%;�%B�%B�6�%J�K�K�
L���	P�!�E�EK�V�A�Y�P�
P��	P�s�
CD�	D6�D1�1D6c��|js
t��|jrB|jjdj	|j
j
���|j
j
�S)z9Return the number of bytes currently in the input buffer.zin_waiting -> {:d}�r$r	rr
r<r�qsizer0s r!�
in_waitingzSerial.in_waiting~s[���|�|�"�$�$��;�;�
�K�K���2�9�9�$�*�*�:J�:J�:L�M�N��z�z���!�!r"c��|js
t��|j�1|jdk7r"tj�|jz}nd}t	�}|dkDr�|jr�	|j
j
|j��}|�||z
}|dz}n	t|�S|rJtj�|kDr3|jr|jjd�	t|�S|dkDr
|jr��t|�S#t
j$r|jdk(rYt|�SY��wxYw)z�        Read size bytes from the serial port. If a timeout is set it may
        return less characters as requested. With no timeout it will block
        until the requested number of bytes is read.
        Nr��timeout�zread timeout)r$r	�_timeout�time�	bytearrayr�get�Emptyrr�bytes)r�sizerU�data�bs     r!�readzSerial.read�s#���|�|�"�$�$��=�=�$����!�);��i�i�k�D�M�M�1�G��G��{���Q�h�4�<�<�

��J�J�N�N�4�=�=�N�9��
�=��A�I�D��A�I�D���T�{��	�4�9�9�;��0��;�;��K�K�$�$�^�4���T�{��%�Q�h�4�<�<�$�T�{����;�;�
��=�=�A�%���T�{��&�
�s�2&D�"E�
Ec�:�|jjd�y)N)rr3r0s r!�cancel_readzSerial.cancel_read�s���
�
���d�#r"c��d|_y)NT)rr0s r!�cancel_writezSerial.cancel_write�s
��!��r"c��d|_|js
t��t|�}dt	|�z|j
z}|j�z||jkDrk|j}|dkDrB|js6tjt|d��|dz}|dkDr
|js�6|jrytd��t|�D])}|jj||j���+t	|�S)z�        Output the given byte string over the serial port. Can block if the
        connection is blocked. May raise SerialException if the connection is
        closed.
        Fg$@rg�?z
Write timeoutrT)rr$r	r�lenr8�_write_timeoutrX�sleep�minrrr�put)rr^�time_used_to_send�	time_left�bytes     r!�writezSerial.write�s���#����|�|�"�$�$���~�� �3�t�9�,�t�~�~�=�����*�/@�4�CV�CV�/V��+�+�I��a�-��(:�(:��
�
�3�y�#�.�/��S� �	��a�-��(:�(:��!�!��(��9�9��d�O�	>�D��J�J�N�N�4��)<�)<�N�=�	>��4�y�r"c�R�|js
t��|jr|jjd�	|jj�r6|jj
�|jj�r�5yy#tj$rYywxYw)z9Clear input buffer, discarding all that is in the buffer.zreset_input_buffer()N�r$r	rrrrQ�
get_nowaitr[r0s r!r.zSerial.reset_input_buffer�sy���|�|�"�$�$��;�;��K�K���3�4�	��*�*�"�"�$��
�
�%�%�'��*�*�"�"�$���{�{�	��	���AB�B&�%B&c�R�|js
t��|jr|jjd�	|jj�r6|jj
�|jj�r�5yy#tj$rYywxYw)zs        Clear output buffer, aborting the current output and
        discarding all that is in the buffer.
        zreset_output_buffer()Nrpr0s r!r/zSerial.reset_output_buffer�s{��
�|�|�"�$�$��;�;��K�K���4�5�	��*�*�"�"�$��
�
�%�%�'��*�*�"�"�$���{�{�	��	�rrc��|js
t��|jrB|jjdj	|j
j
���|j
j
�S)z0Return how many bytes the in the outgoing bufferzout_waiting -> {:d}rPr0s r!�out_waitingzSerial.out_waiting�s[���|�|�"�$�$��;�;�
�K�K���3�:�:�4�:�:�;K�;K�;M�N�O��z�z���!�!r"c��|jr5|jjdj|j��yy)z[        Set break: Controls TXD. When active, to transmitting is
        possible.
        z_update_break_state({!r})N)rrr<�_break_stater0s r!�_update_break_statezSerial._update_break_state�s4��
�;�;��K�K���8�?�?��@Q�@Q�R�S�r"c��|jr5|jjdj|j��yy)z)Set terminal status line: Request To Sendz'_update_rts_state({!r}) -> state of CTSN)rrr<�
_rts_stater0s r!r-zSerial._update_rts_state��0���;�;��K�K���F�M�M�d�o�o�^�_�r"c��|jr5|jjdj|j��yy)z-Set terminal status line: Data Terminal Readyz'_update_dtr_state({!r}) -> state of DSRN�rrr<�
_dtr_stater0s r!r+zSerial._update_dtr_state�r{r"c���|js
t��|jr4|jjdj	|j
��|j
S)z(Read terminal status line: Clear To SendzCTS -> state of RTS ({!r}))r$r	rrr<rzr0s r!�ctsz
Serial.ctssG���|�|�"�$�$��;�;��K�K���9�@�@����Q�R����r"c��|jr4|jjdj|j��|jS)z)Read terminal status line: Data Set ReadyzDSR -> state of DTR ({!r})r}r0s r!�dsrz
Serial.dsrs7���;�;��K�K���9�@�@����Q�R����r"c�~�|js
t��|jr|jjd�y)z)Read terminal status line: Ring Indicatorzreturning dummy for RIF�r$r	rrr0s r!�riz	Serial.ris1���|�|�"�$�$��;�;��K�K���5�6�r"c�~�|js
t��|jr|jjd�y)z)Read terminal status line: Carrier Detectzreturning dummy for CDTr�r0s r!�cdz	Serial.cds1���|�|�"�$�$��;�;��K�K���5�6�r")rV)�__name__�
__module__�__qualname__�__doc__�	BAUDRATESrr1r5r)r'�propertyrRr`rbrdrnr.r/rurxr-r+r�r�r�r��
__classcell__)r s@r!rr)s����]�4�I�6�#�6$�	4�P�2�"��"��B$�"��6
�
��"��"�T�`�
`�
���������������r"r�__main__zloop://z{}
z	write...
zhello
zread: {!r}
�)!�
__future__rr?r9rXr@�ImportError�urllib.parse�parserr%�serial.serialutilrrrrrr	�DEBUG�INFO�WARNING�ERRORrIrr��sys�s�stdoutrnr<�flushr`r5�r"r!�<module>r�s�� '����$����y�x��]�]��L�L����
�]�]�	�
�z�Z�z�B�z����y��A��J�J���V�]�]�1�%�&��J�J���\�"��G�G�I���G�G�I��J�J���^�*�*�1�6�6�!�9�5�6��G�G�I���g�$�#�#�$������s"�D)�D;�)D8�7D8�;	E�E