관리-도구
편집 파일: serialcli.cpython-39.pyc
a z�YW�# � @ s@ d dl Z d dlZ d dlT e je j Zdd� ZG dd� de�ZdS )� N)�*c C s t dd� | D ��S )Nc S s g | ]}t |��qS � )�ord)�.0�xr r �4/usr/lib/python3.9/site-packages/serial/serialcli.py� <listcomp> � z!as_byte_array.<locals>.<listcomp>)�sab)�stringr r r � as_byte_array s r c @ s� e Zd ZdZdZdd� Zdd� Zdd� Zed d � �Z d#dd �Z dd� Zdd� Zdd� Z dd� Zdd� Zdd� Zedd� �Zedd� �Zedd� �Zed d!� �Zd"S )$�Serialz)Serial port implementation for .NET/Mono.)�2 �K �n � � �� i, iX i� i i` i� i�% i K i � i � i � c C s� | j du rtd��| jr td��ztjj�| j�| _W n< t yr } z$d| _td| j|f ��W Y d}~n d}~0 0 | j du r�d| _ | jdu r�d| _| �� | j� � 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.zcould not open port %s: %sT)Z_port�SerialException�is_open�System�IO�Ports� SerialPortZportstr�_port_handle� Exception� _rts_state� _dtr_state�_reconfigure_portZOpenZ_dsrdtr�_update_dtr_state�_rtscts�_update_rts_state�reset_input_buffer)�self�msgr r r �open s* ( zSerial.openc C s� | j std��| jdu r*tjjjj| j _nt | jd �| j _| j du rXtjjjj| j _nt | j d �| j _z| j| j _ W n0 ty� } ztt|���W Y d}~n d}~0 0 | jtkr�d| j _nJ| jtkr�d| j _n6| jtkr�d| j _n"| jtkr�d| j _ntd| j ��| jtk�r*ttjjjd �| j _n�| jtk�rHtjjjj| j _nh| jtk�rftjjjj| j _nJ| jtk�r�tjjjj | j _n,| jt!k�r�tjjjj"| j _ntd | j ��| j#t$k�r�tjjj%j&| j _%nJ| j#t'k�r�tjjj%j(| j _%n,| j#t)k�r tjjj%j*| j _%ntd| j# ��| j+�r:| j,�r:tjjj-j.| j _-nH| j+�rTtjjj-j/| j _-n.| j,�rntjjj-j0| j _-nttjjj-d �| j _-dS )z,Set communication parameters on opened port.z'Can only operate on a valid port handleNi� � � � � z#Unsupported number of data bits: %r�NonezUnsupported parity mode: %rz#Unsupported number of stop bits: %r)1r r �_timeoutr r r r ZInfiniteTimeoutZReadTimeout�intZ_write_timeoutZWriteTimeoutZ _baudrateZBaudRate�IOError� ValueError�strZ _bytesizeZFIVEBITSZDataBitsZSIXBITSZ SEVENBITSZ EIGHTBITSZ_parityZPARITY_NONE�getattrZParityZPARITY_EVENZEvenZ PARITY_ODDZOddZPARITY_MARKZMarkZPARITY_SPACEZSpaceZ _stopbitsZSTOPBITS_ONEZStopBitsZOneZSTOPBITS_ONE_POINT_FIVEZOnePointFiveZSTOPBITS_TWOZTwor Z_xonxoffZ HandshakeZRequestToSendXOnXOffZ RequestToSendZXOnXOff)r# �er r r r ; s\ " zSerial._reconfigure_portc C sD | j r@| jr:z| j�� W n tjjjy2 Y n0 d| _d| _ dS )z Close portNF)r r ZCloser r r ZInvalidOperationException�r# r r r �close� s zSerial.closec C s | j s t�| jjS )z>Return the number of characters currently in the input buffer.)r �portNotOpenErrorr ZBytesToReadr2 r r r � in_waiting� s zSerial.in_waiting� c C sT | j s t�t� }|rLz|�| j�� � W n tjy@ Y qLY q0 |d8 }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. r6 ) r r4 � bytearray�appendr ZReadByter �TimeoutException�bytes)r# �size�datar r r �read� s zSerial.readc C sH | j s t�z| j�t|�dt|�� W n tjy> t�Y n0 t|�S )z-Output the given string over the serial port.r ) r r4 r ZWriter �lenr r9 ZwriteTimeoutError)r# r<