U
    P|j÷  ã                   @   sL   d Z ddlmZmZmZ ddlmZmZ ddlm	Z	 G dd„ de	ej
ƒZdS )z
Serial Port Protocol
é    )Ú	EIGHTBITSÚPARITY_NONEÚSTOPBITS_ONE)ÚabstractÚfdesc)ÚBaseSerialPortc                   @   sL   e Zd ZdZdZdeeedddfdd„Zdd„ Z	d	d
„ Z
dd„ Zdd„ ZdS )Ú
SerialPortz>
    A select()able serial device, acting as a transport.
    é   i€%  r   c              
   C   s^   t j | |¡ | j|||||||	|
d�| _|| _|  ¡  |  ¡  || _| j 	| ¡ |  
¡  d S )N)ÚbaudrateÚbytesizeÚparityÚstopbitsÚtimeoutÚxonxoffÚrtscts)r   ÚFileDescriptorÚ__init__Z_serialFactoryÚ_serialÚreactorZ
flushInputZflushOutputÚprotocolZmakeConnectionZstartReading)Úselfr   ZdeviceNameOrPortNumberr   r
   r   r   r   r   r   r   © r   úE/tmp/pip-unpacked-wheel-audpp6lv/twisted/internet/_posixserialport.pyr      s"    ø
zSerialPort.__init__c                 C   s   | j jS )N)r   Úfd©r   r   r   r   Úfileno8   s    zSerialPort.filenoc                 C   s   t  |  ¡ |¡S )z7
        Write some data to the serial device.
        )r   Z	writeToFDr   )r   Údatar   r   r   ÚwriteSomeData;   s    zSerialPort.writeSomeDatac                 C   s   t  |  ¡ | jj¡S )z:
        Some data's readable from serial device.
        )r   Z
readFromFDr   r   ZdataReceivedr   r   r   r   ÚdoReadA   s    zSerialPort.doReadc                 C   s(   t j | |¡ | j ¡  | j |¡ dS )z™
        Called when the serial port disconnects.

        Will call C{connectionLost} on the protocol that is handling the
        serial data.
        N)r   r   ÚconnectionLostr   Úcloser   )r   Úreasonr   r   r   r   G   s    
zSerialPort.connectionLostN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	connectedr   r   r   r   r   r   r   r   r   r   r   r   r      s   õ
r   N)r%   Úserialr   r   r   Ztwisted.internetr   r   Ztwisted.internet.serialportr   r   r   r   r   r   r   Ú<module>   s   