U
    
W[                     @   sl   d Z ddlmZmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZmZ G dd	 d	e	ejZd
S )z
Serial Port Protocol
    )divisionabsolute_import)PARITY_NONE)STOPBITS_ONE)	EIGHTBITS)BaseSerialPort)abstractfdescc                   @   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   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   fileno.   s    zSerialPort.filenoc                 C   s   t |  |S )z7
        Write some data to the serial device.
        )r	   Z	writeToFDr   )r   datar   r   r   writeSomeData2   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   doRead9   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!   @   s    
zSerialPort.connectionLostN)__name__
__module____qualname____doc__Z	connectedr   r   r   r   r   r   r    r!   r   r   r   r   r
      s        
r
   N)r'   Z
__future__r   r   serialr   r   r   Ztwisted.internet.serialportr   Ztwisted.internetr   r	   r   r
   r   r   r   r   <module>   s   