관리-도구
편집 파일: protocol_socket.cpython-39.opt-1.pyc
a ����=Y27����������������������@���s��d�dl�Z�d�dlZd�dlZd�dlZd�dlZzd�dlZW�n�eyR���d�dlmZ�Y�n0�d�dl m Z mZmZm Z mZmZ�ejejejejd�ZdZG�dd��de �Zedk�rd�dlZed�Zej�d �e���ej�d ��e�d��e����ej�d�e�d����e����dS�) �����N)� SerialBase�SerialException�to_bytes�portNotOpenError�writeTimeoutError�Timeout)�debug�infoZwarning�error����c�������������������@���s����e�Zd�ZdZdZdd��Zdd��Zdd��Zd d ��Ze dd���Z d*dd�Zdd��Zdd��Z dd��Zd+dd�Zdd��Zdd��Zdd��Ze dd ���Ze d!d"���Ze d#d$���Ze d%d&���Zd'd(��Zd)S�),�Serialz-Serial port implementation for plain sockets.)�2����K����n����������������i,��iX��i���i��i` ��i���i�%��i�K��i����i����i���c�������������� ���C���s����d|�_�|�jdu�rtd��|�jr&td��ztj|��|�j�td�|�_ W�n<�t y~�}�z$d|�_ td�|�j|���W�Y�d}~n d}~0�0�|�j �d��|�� ���d|�_|�js�|�����|�js�|�����|�����|�����dS�)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.)�timeoutzCould not open port {}: {}FT)�loggerZ_portr����is_open�socketZcreate_connection�from_urlZportstr�POLL_TIMEOUT�_socket� Exception�formatZsetblocking�_reconfigure_portZ_dsrdtr�_update_dtr_stateZ_rtscts�_update_rts_state�reset_input_buffer�reset_output_buffer)�self�msg��r#����E/usr/lib/python3.9/site-packages/serial/urlhandler/protocol_socket.py�open1���s&���� (zSerial.openc�����������������C���s(���|�j�du�rtd��|�jr$|�j�d��dS�)zz Set communication parameters on opened port. For the socket:// protocol all settings are ignored! NzCan only operate on open portsz!ignored port configuration change)r���r���r���r ����r!���r#���r#���r$���r���O���s���� zSerial._reconfigure_portc�����������������C���sP���|�j�rL|�jr<z|�j�tj��|�j����W�n���Y�n0�d|�_d|�_�t�d��dS�)z Close portNFg333333�?)r���r���Zshutdownr���Z SHUT_RDWR�close�time�sleepr&���r#���r#���r$���r'���Y���s����zSerial.closec�������������� ���C���s����t��|�}|jdkr$td�|j���z�t��|jd����D�]T\}}|dkr~t� ���t� d�|�_|�j�t |d����|�j�d��q8td�|���q8d|j��kr�d k�s�n�td ��W�n2�ty��}�ztd�|���W�Y�d}~n d}~0�0�|j|jfS�) z(extract host and port from an URL stringr���zexpected a string in the form "socket://<host>:<port>[?logging={debug|info|warning|error}]": not starting with socket:// ({!r})T�loggingzpySerial.socketr���zenabled loggingzunknown option: {!r}i���zport not in range 0...65535z_expected a string in the form "socket://<host>:<port>[?logging={debug|info|warning|error}]": {}N)�urlparse�urlsplit�schemer���r����parse_qs�query�itemsr*���ZbasicConfigZ getLoggerr���ZsetLevel� LOGGER_LEVELSr���� ValueError�port�hostname)r!����url�parts�option�values�er#���r#���r$���r���h���s0���� ����zSerial.from_urlc�����������������C���s,���|�j�s t�t�|�jgg�g�d�\}}}t|�S�)z9Return the number of bytes currently in the input buffer.r���)r���r����selectr����len)r!���ZlrZlwZlxr#���r#���r$���� in_waiting����s����zSerial.in_waiting����c�������������� ���C���sB��|�j�s t�t��}t|�j�}t|�|k��r:zVt�|�jgg�g�|����\}}}|sRW��q:|�j� |t|���}|srt d��|�|��W�n��ty��}�z8|j t jt jt jt jt jfvr�t d�|���W�Y�d}~nfd}~0��tjtjf�y*�}�z<|d�t jt jt jt jt jfv�rt d�|���W�Y�d}~n d}~0�0�|���r�q:qt|�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. zsocket disconnected�read failed: {}Nr���)r���r���� bytearrayr����_timeoutr;���r:���r���� time_left�recvr����extend�OSError�errno�EAGAIN�EALREADY�EWOULDBLOCK�EINPROGRESS�EINTRr���r ���r����expired�bytes)r!����size�readr����ready�_�bufr9���r#���r#���r$���rN�������s,���� ""$zSerial.readc����������� ��� ���C���s���|�j�s t�t|�}t|��}}t|�j�}|dk�r�z�|�j�|�}|jrL|W�S�|j s�|� ��r^t�t�g�|�jgg�|� ���\}}}|s�t�n&t�g�|�jgg�d�\}}}|s�td��||d��}||8�}W�n��ty������Y�n��t�y(�} �z:| jtjtjtjtjtjfv�rtd�| ���W�Y�d} ~ n`d} ~ 0��tj�y~�} �z<| d�tjtjtjtjtjfv�rjtd�| ���W�Y�d} ~ n d} ~ 0�0�|js(|� ��r(t�q(|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. r���Nzwrite failed (select)zwrite failed: {})r���r���r���r;���r���Z_write_timeoutr����sendZis_non_blockingZis_infiniterK���r���r:���rA���r���rD���rE���rF���rG���rH���rI���rJ���r���r ���) r!����data�dZtx_len�lengthr����nrP���rO���r9���r#���r#���r$����write����s@���� ""$zSerial.writec�������������� ���C���s����|�j�s t�d}|r�t�|�jgg�g�d�\}}}z|�j�d��W�q�ty��}�z8|jtjtjtj tj tjfvrxtd� |���W�Y�d}~qd}~0��tjtjfy��}�z:|d�tjtjtj tj tjfvr�td� |���W�Y�d}~qd}~0�0�qdS�)z9Clear input buffer, discarding all that is in the buffer.Tr���i���r>���N)r���r���r:���r���rB���rD���rE���rF���rG���rH���rI���rJ���r���r���r ���r���)r!���rO���rP���r9���r#���r#���r$���r�������s����" zSerial.reset_input_bufferc�����������������C���s ���|�j�s t�|�jr|�j�d��dS�)zs Clear output buffer, aborting the current output and discarding all that is in the buffer. zignored reset_output_bufferN�r���r���r���r ���r&���r#���r#���r$���r �����s����zSerial.reset_output_buffer��������?c�����������������C���s&���|�j�s t�|�jr"|�j�d�|���dS�)za Send break condition. Timed, returns to idle state after given duration. zignored send_break({!r})N)r���r���r���r ���r���)r!���Zdurationr#���r#���r$���� send_break��s����zSerial.send_breakc�����������������C���s���|�j�r|�j��d�|�j���dS�)zJSet break: Controls TXD. When active, to transmitting is possible.z!ignored _update_break_state({!r})N)r���r ���r���Z_break_stater&���r#���r#���r$����_update_break_state��s����zSerial._update_break_statec�����������������C���s���|�j�r|�j��d�|�j���dS�)z)Set terminal status line: Request To Sendzignored _update_rts_state({!r})N)r���r ���r���Z _rts_stater&���r#���r#���r$���r���"��s����zSerial._update_rts_statec�����������������C���s���|�j�r|�j��d�|�j���dS�)z-Set terminal status line: Data Terminal Readyzignored _update_dtr_state({!r})N)r���r ���r���Z _dtr_stater&���r#���r#���r$���r���'��s����zSerial._update_dtr_statec�����������������C���s ���|�j�s t�|�jr|�j�d��dS�)z(Read terminal status line: Clear To Sendzreturning dummy for ctsTrX���r&���r#���r#���r$����cts,��s ����z Serial.ctsc�����������������C���s ���|�j�s t�|�jr|�j�d��dS�)z)Read terminal status line: Data Set Readyzreturning dummy for dsrTrX���r&���r#���r#���r$����dsr5��s ����z Serial.dsrc�����������������C���s ���|�j�s t�|�jr|�j�d��dS�)z)Read terminal status line: Ring Indicatorzreturning dummy for riFrX���r&���r#���r#���r$����ri>��s ����z Serial.ric�����������������C���s ���|�j�s t�|�jr|�j�d��dS�)z)Read terminal status line: Carrier Detectzreturning dummy for cd)TrX���r&���r#���r#���r$����cdG��s ����z Serial.cdc�����������������C���s ���|�j����S�)z@Get the file handle of the underlying socket for use with select)r����filenor&���r#���r#���r$���r`���S��s����z Serial.filenoN)r=���)rY���)�__name__� __module__�__qualname__�__doc__Z BAUDRATESr%���r���r'���r����propertyr<���rN���rW���r���r ���rZ���r[���r���r���r\���r]���r^���r_���r`���r#���r#���r#���r$���r���+���s2��� )5 r����__main__zsocket://localhost:7000z{} z write... s���hello z read: {} ) rE���r*���r:���r���r(���r+����ImportError�urllib.parse�parseZserial.serialutilr���r���r���r���r���r����DEBUG�INFOZWARNINGZERRORr1���r���r���ra����sys�s�stdoutrW���r����flushrN���r'���r#���r#���r#���r$����<module>���s6��� ���1