%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/serial/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/serial/__pycache__/serialwin32.cpython-312.pyc

�

+�a_<O��f�ddlmZddlZddlZddlmZddlZddlmZmZm	Z	m
Z
mZGd�de�Zy)�)�absolute_importN)�win32)�
SerialBase�SerialException�to_bytes�PortNotOpenError�SerialTimeoutExceptionc�0��eZdZdZdZ�fd�Zd�Zd�Zd�Zd�Z	e
d��Zdd	�Zd
�Z
d�Zd�Zd
�Zd�Zd�Zd�Zd�Ze
d��Ze
d��Ze
d��Ze
d��Zdd�Zdd�Ze
d��Zd�Zd�Zd�Zej@jBd��Z �xZ"S) �Serialz5Serial port implementation for Win32 based on ctypes.)�2�K�n����i,iXi�ii`	i�i�%iKi�i�i�c�V��d|_d|_d|_tt|�|i|��y�N)�_port_handle�_overlapped_read�_overlapped_write�superr�__init__)�self�args�kwargs�	__class__s   ��4/usr/lib/python3/dist-packages/serial/serialwin32.pyrzSerial.__init__s/��� ��� $���!%���
�f�d�$�d�5�f�5�c	���|j�td��|jrtd��|j}	|j	�jd�rt
|dd�dkDrd|z}tj|tjtjzddtjtjtjzd�|_|jtj k(r>d|_td	j#|j$t'j(����	tj*�|_tj.dd
dd�|j,_tj*�|_tj.dddd�|j2_tj4|jdd�tj6�|_tj:|jt'j<|j8��|j?�tj@|jtjBtjDztjFztjHz�d|_y#t$rY��DwxYw#	|jK�d|_�#Yd|_�xYwxYw)
zx        Open port with current settings. This may throw a SerialException
        if the port cannot be opened.
        Nz.Port must be configured before it can be used.zPort is already open.�COM��z\\.\rzcould not open port {!r}: {!r}��T)&�_portr�is_open�name�upper�
startswith�int�
ValueErrorr�
CreateFile�GENERIC_READ�
GENERIC_WRITE�
OPEN_EXISTING�FILE_ATTRIBUTE_NORMAL�FILE_FLAG_OVERLAPPEDr�INVALID_HANDLE_VALUE�format�portstr�ctypes�WinError�
OVERLAPPEDr�CreateEvent�hEventr�	SetupComm�COMMTIMEOUTS�_orgTimeouts�GetCommTimeouts�byref�_reconfigure_port�	PurgeComm�
PURGE_TXCLEAR�
PURGE_TXABORT�
PURGE_RXCLEAR�
PURGE_RXABORT�_close)r�ports  r�openzSerial.open#sa��
�:�:��!�"R�S�S��<�<�!�"9�:�:��y�y��	��z�z�|�&�&�u�-�#�d�1�2�h�-�!�2C� �4�'��"�,�,������!4�!4�4�
������'�'�%�*D�*D�D�
�������� :� :�:� $�D��!�"B�"I�"I�$�,�,�X^�Xg�Xg�Xi�"j�k�k� 	 �$)�$4�$4�$6�D�!�+0�+<�+<�T�1�a��+N�D�!�!�(�%*�%5�%5�%7�D�"�,1�,=�,=�d�A�q�$�,O�D�"�"�)�
�O�O�D�-�-�t�T�:�!&� 2� 2� 4�D���!�!�$�"3�"3�V�\�\�$�BS�BS�5T�U��"�"�$�
�O�O��!�!��#�#�e�&9�&9�9��#�#�$�&+�&9�&9�:�
;� �D�L��_�	��	��J	�
����
�
!%�D����
�� $�D���s6�5J)�9E(J9�)	J6�5J6�9K"�<K�K"�K�K"c�F�|jstd��tj�}|j�nL|jdk(rtj
|_n'tt|jdz�d�|_	|jdk7r3|j�'tt|jdz�d�|_|j�nL|jdk(rtj
|_n'tt|jdz�d�|_tj|jtj|��tj |jtj"�tj$�}tj&|jtj|��|j(|_|j,t.j0k(rd|_n�|j,t.j4k(rd|_nn|j,t.j6k(rd|_nI|j,t.j8k(rd	|_n$t;d
j=|j,���|j>t.j@k(rtjB|_"d|_#�n|j>t.jHk(rtjJ|_"d|_#n�|j>t.jLk(rtjN|_"d|_#n�|j>t.jPk(rtjR|_"d|_#n^|j>t.jTk(rtjV|_"d|_#n$t;dj=|j>���|jXt.jZk(rtj\|_/n�|jXt.j`k(rtjb|_/nW|jXt.jdk(rtjf|_/n$t;dj=|jX���d|_4|jj�f|jlrtjn|_8n1|jrrtjtntjv|_8|jl|_<�np|jjjzs.t;d
j=|jjjz���|jjj|r.t;dj=|jjj|���|jjj~�.t;dj=|jjj~���|jjj��.t;dj=|jjj����|jjj�r.t;dj=|jjj����tj�|_8d|_<|j�rtj�|_En1|j�rtj�ntj�|_E|j�|_I|j�|_K|j�|_Ld|_Md|_Nd|_Ot.j�|_Qt.j�|_Stj�|jtj|��s,tdj=tj�����y)z,Set communication parameters on opened port.z'Can only operate on a valid port handleNri�r#���r"z%Unsupported number of data bits: {!r}zUnsupported parity mode: {!r}z%Unsupported number of stop bits: {!r}zQUnsupported value for RS485Settings.rts_level_for_tx: {!r} (only True is allowed)zRUnsupported value for RS485Settings.rts_level_for_rx: {!r} (only False is allowed)zPUnsupported value for RS485Settings.delay_before_tx: {!r} (only None is allowed)zPUnsupported value for RS485Settings.delay_before_rx: {!r} (only None is allowed)zJUnsupported value for RS485Settings.loopback: {!r} (only False is allowed)zCCannot configure port, something went wrong. Original message: {!r})Vrrrr;�_timeout�MAXDWORD�ReadIntervalTimeout�maxr*�ReadTotalTimeoutConstant�_inter_byte_timeout�_write_timeout�WriteTotalTimeoutConstant�SetCommTimeoutsr5r>�SetCommMask�EV_ERR�DCB�GetCommState�	_baudrate�BaudRate�	_bytesize�serial�FIVEBITS�ByteSize�SIXBITS�	SEVENBITS�	EIGHTBITSr+r3�_parity�PARITY_NONE�NOPARITY�Parity�fParity�PARITY_EVEN�
EVENPARITY�
PARITY_ODD�	ODDPARITY�PARITY_MARK�
MARKPARITY�PARITY_SPACE�SPACEPARITY�	_stopbits�STOPBITS_ONE�
ONESTOPBIT�StopBits�STOPBITS_ONE_POINT_FIVE�ONE5STOPBITS�STOPBITS_TWO�TWOSTOPBITS�fBinary�_rs485_mode�_rtscts�RTS_CONTROL_HANDSHAKE�fRtsControl�
_rts_state�RTS_CONTROL_ENABLE�RTS_CONTROL_DISABLE�fOutxCtsFlow�rts_level_for_tx�rts_level_for_rx�delay_before_tx�delay_before_rx�loopback�RTS_CONTROL_TOGGLE�_dsrdtr�DTR_CONTROL_HANDSHAKE�fDtrControl�
_dtr_state�DTR_CONTROL_ENABLE�DTR_CONTROL_DISABLE�fOutxDsrFlow�_xonxoff�fOutX�fInX�fNull�
fErrorChar�
fAbortOnError�XON�XonChar�XOFF�XoffChar�SetCommStater6)r�timeouts�comDCBs   rr?zSerial._reconfigure_portds���� � �!�"K�L�L��%�%�'���=�=� ��
�]�]�a�
�+0�>�>�H�(�03�C��
�
��8L�4M�q�0Q�H�-��=�=�A��$�":�":�"F�+.�s�4�3K�3K�d�3R�/S�UV�+W�H�(����&��
�
 �
 �A�
%�16���H�.�14�S��9L�9L�t�9S�5T�VW�1X�H�.�
���d�/�/����h�1G�H�
���$�+�+�U�\�\�:������
���4�,�,�f�l�l�6�.B�C��.�.����>�>�V�_�_�,��F�O�
�^�^�v�~�~�
-��F�O�
�^�^�v�/�/�
/��F�O�
�^�^�v�/�/�
/��F�O��D�K�K�D�N�N�[�\�\��<�<�6�-�-�-�!�N�N�F�M��F�N�
�\�\�V�/�/�
/�!�,�,�F�M��F�N�
�\�\�V�.�.�
.�!�O�O�F�M��F�N�
�\�\�V�/�/�
/�!�,�,�F�M��F�N�
�\�\�V�0�0�
0�!�-�-�F�M��F�N��<�C�C�D�L�L�Q�R�R��>�>�V�0�0�0�#�.�.�F�O�
�^�^�v�=�=�
=�#�0�0�F�O�
�^�^�v�2�2�
2�#�/�/�F�O��D�K�K�D�N�N�[�\�\�������#��|�|�%*�%@�%@��"�AE���U�%=�%=�V[�Vo�Vo��"�"&�,�,�F���#�#�4�4� �g�n�n��(�(�9�9�<�=�=����0�0� �h�o�o��(�(�9�9�<�=�=����/�/�;� �f�m�m��(�(�8�8�;�<�<����/�/�;� �f�m�m��(�(�8�8�;�<�<����(�(� �`�g�g��(�(�1�1�4�5�5�"'�!9�!9�F��"#�F���<�<�!&�!<�!<�F��=A�_�_��!9�!9�RW�Rk�Rk�F��"�l�l����}�}����m�m��������� �������� �+�+����!�!�$�"3�"3�V�\�\�&�5I�J�!�)�)/�����0A�)B�D�
D�Krc���|j��tj|j|j�|j�@|j�tj|jj�d|_|j�@|j�tj|jj�d|_tj|j�d|_yy)zinternal close port helperN)
rrrTr<r�cancel_read�CloseHandler9r�cancel_write�rs rrEz
Serial._close�s������(��!�!�$�"3�"3�T�5F�5F�G��$�$�0�� � �"��!�!�$�"7�"7�">�">�?�(,��%��%�%�1��!�!�#��!�!�$�"8�"8�"?�"?�@�)-��&����d�/�/�0� $�D��)rc�L�|jr|j�d|_yy)z
Close portFN)r&rEr�s r�closezSerial.close�s���<�<��K�K�M� �D�L�rc�P�tj�}tj�}tj|jtj|�tj|��s,tdjtj����|jS)z9Return the number of bytes currently in the input buffer.�ClearCommError failed ({!r}))r�DWORD�COMSTAT�ClearCommErrorrr5r>rr3r6�cbInQue�r�flags�comstats   r�
in_waitingzSerial.in_waiting�sm�����
���-�-�/���#�#�D�$5�$5�v�|�|�E�7J�F�L�L�Y`�La�b�!�"@�"G�"G����HY�"Z�[�[����rc	��|js
t��|dkD�r�tj|jj
�tj�}tj�}tj|jtj|�tj|��s,tdjtj����|jdk(rt!|j"|�n|}|dkD�r�tj$|�}tj�}tj&|j||tj|�tj|j��}|s`tj(�tj*tj,fvr,tdjtj����tj.|jtj|j�tj|�d�}|sQtj(�tj0k7r,tdjtj����|j2d|j4}	t7|	�St7�}	t7|	�St7�}	t7|	�S)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.
        rr�zReadFile failed ({!r})Tz!GetOverlappedResult failed ({!r})N)r&rr�
ResetEventrr9r�r�r�rr5r>rr3r6�timeout�minr��create_string_buffer�ReadFile�GetLastError�
ERROR_SUCCESS�ERROR_IO_PENDING�GetOverlappedResult�ERROR_OPERATION_ABORTED�raw�value�bytes)
r�sizer�r��n�buf�rc�read_ok�	result_ok�reads
          rr�zSerial.reads���|�|�"�$�$��!�8����T�2�2�9�9�:��K�K�M�E��m�m�o�G��'�'��(9�(9�6�<�<��;N�PV�P\�P\�]d�Pe�f�%�&D�&K�&K�F�O�O�L]�&^�_�_�.2�l�l�a�.?��G�O�O�T�*�T�A��1�u��1�1�!�4���[�[�]���.�.��%�%����L�L��$��L�L��!6�!6�7�9���5�#5�#5�#7��@S�@S�UZ�Uk�Uk�?l�#l�)�*B�*I�*I�&�/�/�J[�*\�]�]�!�5�5��%�%��L�L��!6�!6�7��L�L��$��	�	�
!��)�)�+�u�/L�/L�L�-�.Q�.X�.X�Y_�Yh�Yh�Yj�.k�l�l��w�w�y����)��
�T�{���w���T�{���7�D��T�{�rc��|js
t��t|�}|�rtj�}tj
|j|t|�tj|�|j�}|jdk7�r|s`tj�tjtjfvr,tdj!tj"����tj$|j|jtj|�d�tj�tj&k(r|j(S|j(t|�k7rt+d��|j(S|rtjntj�}|tj,tj.tj&fvry|tjtjfvrt|�Stdj!tj"����y)z2Output the given byte string over the serial port.rzWriteFile failed ({!r})Tz
Write timeout)r&rrrr��	WriteFiler�lenr5r>rrRr�r�r�rr3r6r�r�r�r	�ERROR_INVALID_USER_BUFFER�ERROR_NOT_ENOUGH_MEMORY)r�datar��success�	errorcodes     r�writezSerial.write/s����|�|�"�$�$���~������
�A��o�o�d�&7�&7��s�4�y�&�,�,�WX�/�[_�[q�[q�r�G��"�"�a�'��5�#5�#5�#7��@S�@S�UZ�Uk�Uk�?l�#l�)�*C�*J�*J�6�?�?�K\�*]�^�^��)�)�$�*;�*;�T�=S�=S�U[�Ua�Ua�bc�Ud�fj�k��%�%�'�5�+H�+H�H��7�7�N��7�7�c�$�i�'�0��A�A��w�w��3:�E�/�/��@R�@R�@T�	���!@�!@�%�B_�B_�!&�!>�!>�!@�@���5�#6�#6��8N�8N�"O�O��t�9�$�)�*C�*J�*J�6�?�?�K\�*]�^�^�rc�b�|jr#tjd�|jr�"yy)zb        Flush of file like objects. In this case, wait until all data
        is written.
        g�������?N)�out_waiting�time�sleepr�s r�flushzSerial.flushTs$��
����J�J�t����rc��|js
t��tj|jtj
tjz�y)z9Clear input buffer, discarding all that is in the buffer.N)r&rrr@rrCrDr�s r�reset_input_bufferzSerial.reset_input_buffer_s7���|�|�"�$�$�
����)�)�5�+>�+>��AT�AT�+T�Urc��|js
t��tj|jtj
tjz�y)zs        Clear output buffer, aborting the current output and discarding all
        that is in the buffer.
        N)r&rrr@rrArBr�s r�reset_output_bufferzSerial.reset_output_bufferes9��
�|�|�"�$�$�
����)�)�5�+>�+>��AT�AT�+T�Urc���|js
t��|jr tj|j
�ytj|j
�y)zBSet break: Controls TXD. When active, to transmitting is possible.N)r&r�_break_stater�SetCommBreakr�ClearCommBreakr�s r�_update_break_statezSerial._update_break_statensC���|�|�"�$�$�������t�0�0�1�� � ��!2�!2�3rc���|jr/tj|jtj�ytj|jtj
�y)z)Set terminal status line: Request To SendN)r|r�EscapeCommFunctionr�SETRTS�CLRRTSr�s r�_update_rts_statezSerial._update_rts_statew�=���?�?��$�$�T�%6�%6����E��$�$�T�%6�%6����Erc���|jr/tj|jtj�ytj|jtj
�y)z-Set terminal status line: Data Terminal ReadyN)r�rr�r�SETDTR�CLRDTRr�s r�_update_dtr_statezSerial._update_dtr_state~r�rc���|js
t��tj�}tj|j
t
j|��|jSr)	r&rrr��GetCommModemStatusrr5r>r�)r�stats  r�_GetCommModemStatuszSerial._GetCommModemStatus�sF���|�|�"�$�$��{�{�}��
� � ��!2�!2�F�L�L��4F�G��z�z�rc�J�tj|j�zdk7S)z(Read terminal status line: Clear To Sendr)r�	MS_CTS_ONr�r�s r�ctsz
Serial.cts��!������!9�!9�!;�;�q�@�@rc�J�tj|j�zdk7S)z)Read terminal status line: Data Set Readyr)r�	MS_DSR_ONr�r�s r�dsrz
Serial.dsr�r�rc�J�tj|j�zdk7S)z)Read terminal status line: Ring Indicatorr)r�
MS_RING_ONr�r�s r�riz	Serial.ri��#�����$�":�":�"<�<��A�Arc�J�tj|j�zdk7S)z)Read terminal status line: Carrier Detectr)r�
MS_RLSD_ONr�r�s r�cdz	Serial.cd�r�rc�N�|�|}tj|j||�y)z�        Recommend a buffer size to the driver (device driver can ignore this
        value). Must be called after the port is opened.
        N)rr:r)r�rx_size�tx_sizes   r�set_buffer_sizezSerial.set_buffer_size�s$��
�?��G�
����)�)�7�G�<rc���|js
t��|r/tj|jtj
�ytj|jtj�y)a*        Manually control flow - when software flow control is enabled.
        This will do the same as if XON (true) or XOFF (false) are received
        from the other device and control the transmission accordingly.
        WARNING: this function is not portable to different platforms!
        N)r&rrr�r�SETXON�SETXOFF)r�enables  r�set_output_flow_controlzSerial.set_output_flow_control�sK���|�|�"�$�$���$�$�T�%6�%6����E��$�$�T�%6�%6��
�
�Frc�P�tj�}tj�}tj|jtj|�tj|��s,tdjtj����|jS)z0Return how many bytes the in the outgoing bufferr�)rr�r�r�rr5r>rr3r6�cbOutQuer�s   rr�zSerial.out_waiting�so�����
���-�-�/���#�#�D�$5�$5�v�|�|�E�7J�F�L�L�Y`�La�b�!�"@�"G�"G����HY�"Z�[�[����rc�l�tj�}tj|jt	j
|�t	j
|�d�}|sVtj�tjtjfvr!tj|j|�yyy)�ACancel a blocking read operation, may be called from other threadFN)
rr�r�rr5r>r�r��ERROR_IO_INCOMPLETE�
CancelIoEx)r�
overlappedr��errs    r�_cancel_overlapped_iozSerial._cancel_overlapped_io�s����[�[�]���'�'�����L�L��$��L�L����	��
�u�)�)�+��0F�0F��Ha�Ha�/b�b����T�.�.�
�;�c�src�:�|j|j�y)r�N)rrr�s rr�zSerial.cancel_read�s���"�"�4�#8�#8�9rc�:�|j|j�y)zBCancel a blocking write operation, may be called from other threadN)rrr�s rr�zSerial.cancel_write�s���"�"�4�#9�#9�:rc��|�|stdj|���tjjj||�y)z$Change the exclusive access setting.Nz.win32 only supports exclusive access (not: {}))r+r3r\r�	exclusive�__set__)rrs  rrzSerial.exclusive�s@��� ���M�T�T�U^�_�`�`����'�'�/�/��i�@r)r#)r$N)T)#�__name__�
__module__�__qualname__�__doc__�	BAUDRATESrrGr?rEr��propertyr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�rr�setter�
__classcell__)rs@rrrs���?�4�I�6�? �B|D�B%� !�����'�R#�J�V�V�4�F�F���A��A��A��A��B��B��B��B�=�G�� �� �<�:�;���� � �A�!�Arr)
�
__future__rr5r�r\r�serial.serialutilrrrrr	r�rr�<module>rs.��'����
�m�m�FA�Z�FAr

Zerion Mini Shell 1.0