HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /proc/1991111/cwd/lib/python3/dist-packages/serial/threaded/__pycache__/
Upload File :
Current File : //proc/1991111/cwd/lib/python3/dist-packages/serial/threaded/__pycache__/__init__.cpython-311.pyc
�

��^g$����dZddlmZddlZddlZGd�de��ZGd�de��ZGd�d	e��ZGd
�de��Z	Gd�d
ej
��Zedkr�ddl
Z
ddlZddlZdZGd�de	��Zejedd���Zeee��5Ze�d��ejd��ddd��n#1swxYwYejedd���Zeee��Ze���e���\ZZe�d��ejd��e���dSdS)z%Support threading with serial ports.
�)�absolute_importNc�$�eZdZdZd�Zd�Zd�ZdS)�Protocolzq    Protocol as used by the ReaderThread. This base class provides empty
    implementations of all methods.
    c��dS)z$Called when reader thread is startedN���self�	transports  �:/usr/lib/python3/dist-packages/serial/threaded/__init__.py�connection_madezProtocol.connection_made�����c��dS)z2Called with snippets received from the serial portNr�r	�datas  r�
data_receivedzProtocol.data_receivedr
rc�4�t|t��r|�dS)zg        Called when the serial port is closed or the reader loop terminated
        otherwise.
        N)�
isinstance�	Exception�r	�excs  r�connection_lostzProtocol.connection_losts%��
�c�9�%�%�	��I�	�	rN)�__name__�
__module__�__qualname__�__doc__rrrrrrrrsN��������
3�3�3�A�A�A�����rrc�>��eZdZdZdZd�Zd�Z�fd�Zd�Zd�Z	�xZ
S)�
Packetizerz�
    Read binary packets from serial port. Packets are expected to be terminated
    with a TERMINATOR byte (null byte by default).

    The class also keeps track of the transport.
    �c�:�t��|_d|_dS�N)�	bytearray�bufferr
�r	s r�__init__zPacketizer.__init__1s���k�k�������rc��||_dS�zStore transportN�r
rs  rrzPacketizer.connection_made5�
��"����rc�f��d|_tt|���|��dS)�Forget transportN)r
�superrr�r	r�	__class__s  �rrzPacketizer.connection_lost9s.������
�j�$���/�/��4�4�4�4�4rc���|j�|��|j|jvrM|j�|jd��\}|_|�|��|j|jv�KdSdS)z9Buffer received data, find TERMINATOR, call handle_packet�N)r#�extend�
TERMINATOR�split�
handle_packet)r	r�packets   rrzPacketizer.data_received>sx������4� � � ��o���,�,�"&�+�"3�"3�D�O�Q�"G�"G��F�D�K����v�&�&�&��o���,�,�,�,�,�,rc� �td����z1Process packets - to be overridden by subclassingz/please implement functionality in handle_packet��NotImplementedError�r	r5s  rr4zPacketizer.handle_packetE���!�"S�T�T�Tr)rrrrr2r%rrrr4�
__classcell__�r.s@rrr's�����������J����#�#�#�5�5�5�5�5�
'�'�'�U�U�U�U�U�U�Urrc�H��eZdZdZdZdZd�Zd�Z�fd�Zd�Z	d�Z
d	�Z�xZS)
�FramedPacketz�
    Read binary packets. Packets are expected to have a start and stop marker.

    The class also keeps track of the transport.
    �(�)c�H�t��|_d|_d|_dS)NF)r"r5�	in_packetr
r$s rr%zFramedPacket.__init__Ts���k�k����������rc��||_dSr'r(rs  rrzFramedPacket.connection_madeYr)rc���d|_d|_|jdd�=tt|���|��dS)r+NF)r
rCr5r,r?rr-s  �rrzFramedPacket.connection_lost]sB����������K����N�
�l�D�!�!�1�1�#�6�6�6�6�6rc�P�tj|��D]�}||jkrd|_�||jkr9d|_|�t
|j����|jdd�=�Y|jr|j�|���{|�	|����dS)z4Find data enclosed in START/STOP, call handle_packetTFN)
�serial�	iterbytes�STARTrC�STOPr4�bytesr5r1�handle_out_of_packet_data)r	r�bytes   rrzFramedPacket.data_receivedds����$�T�*�*�
	5�
	5�D��t�z�!�!�!%�������"�"�!&����"�"�5���#5�#5�6�6�6��K����N�N���
5���"�"�4�(�(�(�(��.�.�t�4�4�4�4�
	5�
	5rc� �td���r7r8r:s  rr4zFramedPacket.handle_packetrr;rc��dS)z0Process data that is received outside of packetsNrrs  rrLz&FramedPacket.handle_out_of_packet_datavs���r)
rrrrrIrJr%rrrr4rLr<r=s@rr?r?Js����������
�E��D����
#�#�#�7�7�7�7�7�5�5�5�U�U�U�
�
�
�
�
�
�
rr?c�0�eZdZdZdZdZdZd�Zd�Zd�Z	dS)	�
LineReaderzZ
    Read and write (Unicode) lines from/to serial port.
    The encoding is applied.
    s
zutf-8�replacec�l�|�|�|j|j����dSr!)�handle_line�decode�ENCODING�UNICODE_HANDLINGr:s  rr4zLineReader.handle_packet�s/��������t�}�d�6K�L�L�M�M�M�M�Mrc� �td���)z2Process one line - to be overridden by subclassingz-please implement functionality in handle_liner8)r	�lines  rrTzLineReader.handle_line�s��!�"Q�R�R�Rrc��|j�|�|j|j��|jz��dS)z�
        Write text to the transport. ``text`` is a Unicode string and the encoding
        is applied before sending ans also the newline is append.
        N)r
�write�encoderVrWr2)r	�texts  r�
write_linezLineReader.write_line�s<��	
����T�[�[����8M�N�N�QU�Q`�`�a�a�a�a�arN)
rrrrr2rVrWr4rTr^rrrrQrQ{sh��������
�J��H� ��N�N�N�S�S�S�b�b�b�b�brrQc�L��eZdZdZ�fd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Z�xZS)
�ReaderThreada    Implement a serial port read loop and dispatch to a Protocol instance (like
    the asyncio.Protocol) but do it with threads.

    Calls to close() will close the serial port but it is also possible to just
    stop() this thread and continue the serial port instance otherwise.
    c���tt|�����d|_||_||_d|_tj��|_	tj
��|_d|_dS)z�        Initialize thread.

        Note that the serial_instance' timeout is set to one second!
        Other settings are not changed.
        TN)
r,r`r%�daemonrG�protocol_factory�alive�	threading�Lock�_lock�Event�_connection_made�protocol)r	�serial_instancercr.s   �rr%zReaderThread.__init__�sh���	�l�D�!�!�*�*�,�,�,����%��� 0�����
��^�%�%��
� )�� 1� 1�����
�
�
rc��d|_t|jd��r|j���|�d��dS)zStop the reader threadF�cancel_read�N)rd�hasattrrGrm�joinr$s r�stopzReaderThread.stop�sD����
��4�;�
�.�.�	&��K�#�#�%�%�%��	�	�!�����rc�"�t|jd��sd|j_|���|_	|j�|��nR#t$rE}d|_|j�|��|j	�
��Yd}~dSd}~wwxYwd}|j	�
��|jr�|jjr�	|j�|jj
pd��}|r5	|j�|��n8#t$r}|}Yd}~n:d}~wwxYwn#tj$r}|}Yd}~nd}~wwxYw|jr|jj��d|_|j�|��d|_dS)zReader looprmr0FN)rorG�timeoutrcrjrrrdrri�set�is_open�read�
in_waitingr�SerialException)r	�e�errorrs    r�runzReaderThread.run�s����t�{�M�2�2�	$�"#�D�K���-�-�/�/��
�	��M�)�)�$�/�/�/�/���	�	�	��D�J��M�)�)�!�,�,�,��!�%�%�'�'�'��F�F�F�F�F�����		����
����!�!�#�#�#��j�	�T�[�0�	�
��{�'�'���(>�(C�!�D�D������
�3�3�D�9�9�9�9��$���� !���������������	��
�)�
�
�
������������	
����	�j�	�T�[�0�	�"��
��
�%�%�e�,�,�,���
�
�
sG�A�
B&�!:B!�!B&�&D6�D�
D2�&D-�-D2�6E�E�Ec�x�|j5|j�|��cddd��S#1swxYwYdS)zThread safe writing (uses lock)N)rgrGr[rs  rr[zReaderThread.write�s���
�Z�	+�	+��;�$�$�T�*�*�	+�	+�	+�	+�	+�	+�	+�	+�	+�	+�	+�	+����	+�	+�	+�	+�	+�	+s�/�3�3c��|j5|���|j���ddd��dS#1swxYwYdS)z8Close the serial port and exit reader thread (uses lock)N)rgrqrG�closer$s rr~zReaderThread.close�s����Z�	 �	 ��I�I�K�K�K��K������	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 �	 �	 s�.A�A�
Ac��|jr8|j���|jstd���||jfStd���)zj
        Wait until connection is set up and return the transport and protocol
        instances.
        �connection_lost already calledzalready stopped)rdri�wait�RuntimeErrorrjr$s r�connectzReaderThread.connect�sY��
�:�	2��!�&�&�(�(�(��:�
E�"�#C�D�D�D��$�-�(�(��0�1�1�1rc��|���|j���|jst	d���|jS)zs        Enter context handler. May raise RuntimeError in case the connection
        could not be created.
        r�)�startrir�rdr�rjr$s r�	__enter__zReaderThread.__enter__�sH��
	
�
�
������"�"�$�$�$��z�	A��?�@�@�@��}�rc�.�|���dS)zLeave context: close portN)r~)r	�exc_type�exc_val�exc_tbs    r�__exit__zReaderThread.__exit__�s���
�
�����r)
rrrrr%rqr{r[r~r�r�r�r<r=s@rr`r`�s��������������� ���!�!�!�F+�+�+�
 � � �2�2�2�	�	�	�������rr`�__main__zloop://c�*��eZdZ�fd�Zd�Zd�Z�xZS)�
PrintLinesc���tt|���|��tj�d��|�d��dS)Nzport opened
zhello world)r,r�r�sys�stdoutr[r^)r	r
r.s  �rrzPrintLines.connection_madesO����*�d�#�#�3�3�I�>�>�>��J���_�-�-�-��O�O�M�*�*�*�*�*rc�j�tj�d�|����dS)Nzline received: {!r}
)r�r�r[�formatrs  rrTzPrintLines.handle_lines-���J���4�;�;�D�A�A�B�B�B�B�Brc�p�|rtj|��tj�d��dS)Nzport closed
)�	traceback�	print_excr�r�r[rs  rrzPrintLines.connection_losts7���
)��#�C�(�(�(��J���_�-�-�-�-�-r)rrrrrTrr<r=s@rr�r�sY�������	+�	+�	+�	+�	+�
	C�	C�	C�	.�	.�	.�	.�	.�	.�	.rr�i�r0)�baudraters�hellorn)r�
__future__rrGre�objectrrr?rQ�Threadr`rr��timer��PORTr��serial_for_url�serrjr^�sleep�tr�r�r
r~rrr�<module>r�s�����'�&�&�&�&�&�
�
�
�
����������v����* U� U� U� U� U�� U� U� U�F.
�.
�.
�.
�.
�8�.
�.
�.
�bb�b�b�b�b��b�b�b�4l�l�l�l�l�9�#�l�l�l�b�z����J�J�J��K�K�K������D�.�.�.�.�.�Z�.�.�.� �&�
��v�q�
A�
A�
A�C�	��c�:�	&�	&��(����G�$�$�$���
�1�
�
�
�������������������
 �&�
��v�q�
A�
A�
A�C���S�*�%�%�A��G�G�I�I�I��)�)�+�+��I�x����� � � ��D�J�q�M�M�M��G�G�I�I�I�I�I�G�s�&C�C�C