404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@3.146.105.56: ~ $
3

M�]W�;�@s�dZddlZddlZGdd�dej�Zejdd��Zejdd��Zed	kr�Gd
d�dej	�Z
ej�Zeee
dd
d�Z
eje
�ej�ej�dS)z�Support asyncio with serial ports. EXPERIMENTAL

Posix platforms only, Python 3.4+ only.

Windows event loops can not wait for serial ports with the current
implementation. It should be possible to get that working though.
�Ncs�eZdZdZ�fdd�Zedd��Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zd:dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd;d-d.�Zd<d0d1�Zd2d3�Zd=d4d5�Zd6d7�Zd8d9�Z�Z S)>�SerialTransportugAn asyncio transport model of a serial communication channel.

    A transport class is an abstraction of a communication channel.
    This allows protocol implementations to be developed against the
    transport abstraction without needing to know the details of the
    underlying channel, such as whether it is a pipe, a socket, or
    indeed a serial port.


    You generally won’t instantiate a transport yourself; instead, you
    will call `create_serial_connection` which will create the
    transport and try to initiate the underlying communication channel,
    calling you back when it succeeds.
    csvt�j�||_||_||_d|_d|_d|_g|_|j	�d|_
d|_d|j_d|j_
|j|j|�|j|j�dS)NFir)�super�__init__�_loop�	_protocol�_serial�_closing�_protocol_paused�_max_read_size�
_write_buffer�_set_write_buffer_limits�_has_reader�_has_writerZtimeoutZ
write_timeout�	call_soon�connection_made�_ensure_reader)�self�loop�protocolZserial_instance)�	__class__��/usr/lib/python3.6/aio.pyr%s
zSerialTransport.__init__cCs|jS)zThe underlying Serial instance.)r)rrrr�serial<szSerialTransport.serialcCsdj|d�S)NzH{self.__class__.__name__}({self._loop}, {self._protocol}, {self.serial}))r)�format)rrrr�__repr__AszSerialTransport.__repr__cCs|jS)z2Return True if the transport is closing or closed.)r)rrrr�
is_closingDszSerialTransport.is_closingcCs|js|jd�dS)aDClose the transport gracefully.

        Any buffered data will be written asynchronously. No more data
        will be received and further writes will be silently ignored.
        After all buffered data is flushed, the protocol's
        connection_lost() method will be called with None as its
        argument.
        N)r�_close)rrrr�closeHs	zSerialTransport.closecCsXy|jj|j�}Wn0tjk
rB}z|j|d�WYdd}~XnX|rT|jj|�dS)N)�exc)r�readr
r�SerialExceptionrr�
data_received)r�data�errr�_read_readyTszSerialTransport._read_readycCs�|jr
dS|j�dkrzy|jj|�}Wn.tjk
rT}z|j|d�dSd}~XnX|t|�krfdS||d�}|j�|j	j
|�|j�dS)z�Write some data to the transport.

        This method does not block; it buffers the data and arranges
        for it to be sent out asynchronously.  Writes made after the
        transport has been closed will be ignored.Nrz%Fatal write error on serial transport)r�get_write_buffer_sizer�writerr �_fatal_error�len�_ensure_writerr�append�_maybe_pause_protocol)rr"�nrrrrr&]szSerialTransport.writecCsdS)z_Serial ports do not support the concept of end-of-file.

        Always returns False.
        Fr)rrrr�
can_write_eofvszSerialTransport.can_write_eofcCs|j�dS)u�Pause the receiving end of the transport.

        No data will be passed to the protocol’s data_received() method
        until resume_reading() is called.
        N)�_remove_reader)rrrr�
pause_reading}szSerialTransport.pause_readingcCs|j�dS)z�Resume the receiving end of the transport.

        Incoming data will be passed to the protocol's data_received()
        method until pause_reading() is called.
        N)r)rrrr�resume_reading�szSerialTransport.resume_readingNcCs|j||d�|j�dS)uLSet the high- and low-water limits for write flow control.

        These two values control when call the protocol’s
        pause_writing()and resume_writing() methods are called. If
        specified, the low-water limit must be less than or equal to
        the high-water limit. Neither high nor low can be negative.
        )�high�lowN)rr+)rr1r2rrr�set_write_buffer_limits�sz'SerialTransport.set_write_buffer_limitscCsttt|j��S)z�The number of bytes in the write buffer.

        This buffer is unbounded, so the result may be larger than the
        the high water mark.
        )�sum�mapr(r)rrrrr%�sz%SerialTransport.get_write_buffer_sizecCstd��dS)Nz-Serial connections do not support end-of-file)�NotImplementedError)rrrr�	write_eof�szSerialTransport.write_eofcCs|jd�dS)a.Close the transport immediately.

        Pending operations will not be given opportunity to complete,
        and buffered data will be lost. No more data will be received
        and further writes will be ignored.  The protocol's
        connection_lost() method will eventually be called.
        N)�_abort)rrrr�abort�szSerialTransport.abortcCsl|j�|jkrdS|jshd|_y|jj�Wn:tk
rf}z|jjd|||jd��WYdd}~XnXdS)a
To be called whenever the write-buffer size increases.

        Tests the current write-buffer size against the high water
        mark configured for this transport. If the high water mark is
        exceeded, the protocol is instructed to pause_writing().
        NTzprotocol.pause_writing() failed)�message�	exception�	transportr)r%�_high_waterr	r�
pause_writing�	Exceptionr�call_exception_handler)rrrrrr+�sz%SerialTransport._maybe_pause_protocolcCsh|jrd|j�|jkrdd|_y|jj�Wn:tk
rb}z|jjd|||jd��WYdd}~XnXdS)a-To be called whenever the write-buffer size decreases.

        Tests the current write-buffer size against the low water
        mark configured for this transport. If the write-buffer
        size is below the low water mark, the protocol is
        instructed that is can resume_writing().
        Fz protocol.resume_writing() failed)r:r;r<rN)r	r%�
_low_waterr�resume_writingr?rr@)rrrrr�_maybe_resume_protocol�sz&SerialTransport._maybe_resume_protocolcCs�dj|j�}t|�}|jj�y|jj|�}WnRttfk
rR|jj|�Yn�t	j
k
r�}z|j|d�WYdd}~XnXX|t|�kr�|j�|j
�|jr�|j�r�|j�dS||d�}|jj|�|j
�dS)a�Asynchronously write buffered data.

        This method is called back asynchronously as a writer
        registered with the asyncio event-loop against the
        underlying file descriptor for the serial port.

        Should the write-buffer become empty if this method
        is invoked while the transport is closing, the protocol's
        connection_lost() method will be called with None as its
        argument.
        �z%Fatal write error on serial transportN)�joinrr(�clearrr&�BlockingIOError�InterruptedErrorr*rr r'�_remove_writerrCr�_flushedr)rr"Z	num_bytesr,rrrr�_write_ready�s&
zSerialTransport._write_readycCs.|jr*|jr*|jj|jj|j�d|_dS)NT)r
rrZ
add_readerr�fdr$)rrrrrszSerialTransport._ensure_readercCs |jr|jj|jj�d|_dS)NF)r
rZ
remove_readerrrL)rrrrr.szSerialTransport._remove_readercCs.|jr*|jr*|jj|jj|j�d|_dS)NT)rrrZ
add_writerrrLrK)rrrrr)szSerialTransport._ensure_writercCs |jr|jj|jj�d|_dS)NF)rrZ
remove_writerrrL)rrrrrIszSerialTransport._remove_writercCsd|dkr|dkrdnd|}|dkr,|d}||ko>dknsTtd||f��||_||_dS)z&Ensure consistent write-buffer limits.N�@i�rz*high (%r) must be >= low (%r) must be >= 0i)�
ValueErrorr=rA)rr1r2rrrrsz(SerialTransport._set_write_buffer_limits�Fatal error on serial transportcCs&|jj||||jd��|j|�dS)z?Report a fatal error to the event-loop and abort the transport.)r:r;r<rN)rr@rr8)rrr:rrrr'"szSerialTransport._fatal_errorcCs|j�dkS)z3True if the write buffer is empty, otherwise False.r)r%)rrrrrJ,szSerialTransport._flushedcCs2d|_|j�|j�r.|j�|jj|j|�dS)a�Close the transport gracefully.

        If the write buffer is already empty, writing will be
        stopped immediately and a call to the protocol's
        connection_lost() method scheduled.

        If the write buffer is not already empty, the
        asynchronous writing will continue, and the _write_ready
        method will call this _close method again when the
        buffer has been flushed completely.
        TN)rr.rJrIrr�_call_connection_lost)rrrrrr0s
zSerialTransport._closecCs*d|_|j�|j�|jj|j|�dS)aPClose the transport immediately.

        Pending operations will not be given opportunity to complete,
        and buffered data will be lost. No more data will be received
        and further writes will be ignored.  The protocol's
        connection_lost() method will eventually be called with the
        passed exception.
        TN)rr.rIrrrQ)rrrrrr8Bs	zSerialTransport._abortcCsH|jj�z|jj|�Wd|jj�|jj�d|_d|_d|_XdS)z�Close the connection.

        Informs the protocol through connection_lost() and clears
        pending buffers and closes the serial connection.
        N)r�flushr�connection_lostrrFrr)rrrrrrQPs	


z%SerialTransport._call_connection_lost)NN)NN)rP)N)!�__name__�
__module__�__qualname__�__doc__r�propertyrrrrr$r&r-r/r0r3r%r7r9r+rCrKrr.r)rIrr'rJrr8rQ�
__classcell__rr)rrrs8	

+



rcOs&tj||�}|�}t|||�}||fS)N)rZserial_for_urlr)r�protocol_factory�args�kwargsZserrr<rrr�create_serial_connectiondsr]c+s�|jdtj��}|jdtjj�}tj||d�}tj||d��x2tf|�fdd�d�|��D]\}}||fVqZWtj|�||�}t	||��dS)	a�A wrapper for create_serial_connection() returning a (reader,
    writer) pair.

    The reader returned is a StreamReader instance; the writer is a
    StreamWriter instance.

    The arguments are all the usual arguments to Serial(). Additional
    optional keyword arguments are loop (to set the event loop instance
    to use) and limit (to set the buffer limit passed to the
    StreamReader.

    This function is a coroutine.
    r�limit)r^r)rcs�S)Nrr)rrr�<lambda>�sz(open_serial_connection.<locals>.<lambda>)rrZN)
�get�asyncio�get_event_loopZstreamsZ_DEFAULT_LIMIT�StreamReaderZStreamReaderProtocolr]�StreamWriter�
StopIteration)r\rr^�readerr<�_�writerr)rr�open_serial_connectionlsri�__main__c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�OutputcCs&||_td|�d|j_|jd�dS)Nzport openedFshello world
)r<�printrZrtsr&)rr<rrrr�s
zOutput.connection_madecCs$tdt|��d|kr |jj�dS)Nz
data received�
)rl�reprr<r)rr"rrrr!�szOutput.data_receivedcCstd�tj�j�dS)Nzport closed)rlrarb�stop)rrrrrrS�szOutput.connection_lostcCstd�t|jj��dS)Nz
pause writing)rlr<r%)rrrrr>�szOutput.pause_writingcCst|jj��td�dS)Nzresume writing)rlr<r%)rrrrrB�szOutput.resume_writingN)rTrUrVrr!rSr>rBrrrrrk�s
rkz/dev/ttyUSB0i�)Zbaudrate)rWrarZ	Transportr�	coroutiner]rirTZProtocolrkrbr�coroZrun_until_completeZrun_foreverrrrrr�<module>sQ#


Filemanager

Name Type Size Permission Actions
__init__.cpython-36.opt-1.pyc File 2 KB 0644
__init__.cpython-36.pyc File 2 KB 0644
aio.cpython-36.opt-1.pyc File 14 KB 0644
aio.cpython-36.pyc File 14.18 KB 0644
rfc2217.cpython-36.opt-1.pyc File 31.88 KB 0644
rfc2217.cpython-36.pyc File 31.88 KB 0644
rs485.cpython-36.opt-1.pyc File 2.72 KB 0644
rs485.cpython-36.pyc File 2.72 KB 0644
serialcli.cpython-36.opt-1.pyc File 6.45 KB 0644
serialcli.cpython-36.pyc File 6.45 KB 0644
serialjava.cpython-36.opt-1.pyc File 7.08 KB 0644
serialjava.cpython-36.pyc File 7.08 KB 0644
serialposix.cpython-36.opt-1.pyc File 18.69 KB 0644
serialposix.cpython-36.pyc File 18.72 KB 0644
serialutil.cpython-36.opt-1.pyc File 16.04 KB 0644
serialutil.cpython-36.pyc File 16.04 KB 0644
serialwin32.cpython-36.opt-1.pyc File 12.11 KB 0644
serialwin32.cpython-36.pyc File 12.11 KB 0644
win32.cpython-36.opt-1.pyc File 6.15 KB 0644
win32.cpython-36.pyc File 6.15 KB 0644