o
    ¯b!  ã                   @   sT   d Z ddlmZ ddl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
é    )ÚPARITY_NONE)Ú	EIGHTBITSÚ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__Ú_serialFactoryÚ_serialÚreactorÚ
flushInputÚflushOutputÚprotocolÚmakeConnectionÚstartReading)Úselfr   ÚdeviceNameOrPortNumberr   r
   r   r   r   r   r   r   © r   úC/usr/lib/python3/dist-packages/twisted/internet/_posixserialport.pyr      s"   ø
zSerialPort.__init__c                 C   s   | j jS )N)r   Úfd©r   r   r   r   Úfileno9   s   zSerialPort.filenoc                 C   s   t  |  ¡ |¡S )z7
        Write some data to the serial device.
        )r   Ú	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   Ú
readFromFDr!   r   ÚdataReceivedr    r   r   r   ÚdoReadB   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(   H   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   Útwisted.internetr   r   Útwisted.internet.serialportr   r   r   r   r   r   r   Ú<module>   s   