
    ^_ !                     V    d dl mZ d dl d Zd Z eddg      Zd Z G d d	e      Zy
)    )absolute_import)*c                 j    t        |       }| j                  d      }|dd  D ]  }t        ||      } |S )N.   )
__import__splitgetattr)namemod
componentscomps       3/usr/lib/python3/dist-packages/serial/serialjava.py	my_importr      s?    
T
CCJ12 !c4 !J    c                     | D ]  }	 t        |      }|j                   |c S  t        d      # t        t        f$ r Y <w xY w)z1try given list of modules and return that importsz/No Java Communications API implementation found)r   
SerialPortImportErrorAttributeError)namesr   r   s      r   detect_java_commr      sR     	D/CNNJ	 G
HH ^, 		s   .A A z
javax.commzgnu.ioc                 B   t         j                  j                         }g }|j                         r]|j	                         }|j                         t         j                  j                  k(  r|j                  |       |j                         r]||    j                         S )z%Turn a port number into a device name)	commCommPortIdentifiergetPortIdentifiershasMoreElementsnextElementgetPortTypePORT_SERIALappendgetName)
portnumberenumportsels       r   devicer&   ,   s    ""557DE



 >>t66BBBLL 


  $$&&r   c                       e Zd ZdZd Zd Zd Zed        ZddZ	d Z
d Zd	 Zdd
Zd Zd Zd Zed        Zed        Zed        Zed        Zy)Serialz    Serial port class, implemented with Java Communications API and
    thus usable with jython and the appropriate java extension.
    c                    | j                   t        d      | j                  rt        d      t        | j                         t        d      k(  r*t        j
                  j                  | j                         }n2t        j
                  j                  t        | j                               }	 |j                  dd      | _	        | j                          | j                  j                         | _        | j                  j                         | _        d| _        y# t        $ r}d| _	        t        d|z        d}~ww xY w)	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.zPort is already open. zpython serial module
   zCould not open port: %sT)_portSerialExceptionis_opentyper   r   getPortIdentifierr&   opensPort	Exception_reconfigurePortgetInputStream	_instreamgetOutputStream
_outstream)selfportIdmsgs      r   r1   zSerial.open=   s    
 ::!"RSS<<!"9::

tBx',,>>tzzJF,,>>vdjj?QRF	C%;R@DJ 	224**446  	CDJ!";c"ABB	Cs   -D 	D=#D88D=c                    | j                   st        d      | j                   j                  d       | j                  t        k(  rt
        j                  j                  }n| j                  t        k(  rt
        j                  j                  }nt| j                  t        k(  rt
        j                  j                  }nF| j                  t        k(  rt
        j                  j                  }nt        d| j                  z        | j                  t         k(  rt
        j                  j"                  }nt| j                  t$        k(  rt
        j                  j&                  }nF| j                  t(        k(  rt
        j                  j*                  }nt        d| j                  z        | j,                  t.        k(  rt
        j                  j.                  }n| j,                  t0        k(  rt
        j                  j0                  }n| j,                  t2        k(  rt
        j                  j2                  }nt| j,                  t4        k(  rt
        j                  j4                  }nF| j,                  t6        k(  rt
        j                  j6                  }nt        d| j,                  z        dx}}| j8                  r:|t
        j                  j:                  z  }|t
        j                  j<                  z  }| j>                  r:|t
        j                  j@                  z  }|t
        j                  jB                  z  }| j                   jE                  | jF                  |||       | j                   jI                  ||z         | jJ                  dk\  r2| j                   j                  tM        | jJ                  dz               y| j                   jO                          y)	z,Set communication parameters on opened port.z'Can only operate on a valid port handle   zunsupported bytesize: %rz"unsupported number of stopbits: %rzunsupported parity type: %rr   i  N)(r2   r-   enableReceiveTimeout	_bytesizeFIVEBITSr   r   
DATABITS_5SIXBITS
DATABITS_6	SEVENBITS
DATABITS_7	EIGHTBITS
DATABITS_8
ValueError	_stopbitsSTOPBITS_ONE
STOPBITS_1STOPBITS_ONE_POINT_FIVESTOPBITS_1_5STOPBITS_TWO
STOPBITS_2_parityPARITY_NONEPARITY_EVEN
PARITY_ODDPARITY_MARKPARITY_SPACE_rtsctsFLOWCONTROL_RTSCTS_INFLOWCONTROL_RTSCTS_OUT_xonxoffFLOWCONTROL_XONXOFF_INFLOWCONTROL_XONXOFF_OUTsetSerialPortParams	_baudratesetFlowControlMode_timeoutintdisableReceiveTimeout)r9   	jdatabits	jstopbitsjparityjflowinjflowouts         r   r4   zSerial._reconfigurePortT   s   zz!"KLL

''+>>X%22I^^w&22I^^y(22I^^y(22I7$..HII>>\)22I^^6644I^^|+22IADNNRSS<<;&oo11G\\[(oo11G\\Z'oo00G\\[(oo11G\\\)oo22G:T\\IJJ(<<t<<<G>>>H==t===G???H

&&t~~y)WU

%%g&89==AJJ++Cd0B,CDJJ,,.r   c                     | j                   ri| j                  rU| j                  j                          | j                  j                          | j                  j                          d| _        d| _         yy)z
Close portNF)r.   r2   r6   closer8   r9   s    r   rh   zSerial.close   sS    <<zz$$&%%'

  "!
 DL r   c                 b    | j                   s
t               | j                  j                         S )z>Return the number of characters currently in the input buffer.)r2   PortNotOpenErrorr6   	availableri   s    r   
in_waitingzSerial.in_waiting   s'     zz"$$~~''))r   c                 2   | j                   s
t               t               }|dkD  rht        |      |k  rZ| j                  j                         }|dk(  r| j                  dk\  r	 t        |      S |j                  |       t        |      |k  rZt        |      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.
        r   )	r2   rk   	bytearraylenr6   readtimeoutr    bytes)r9   sizerr   xs       r   rr   zSerial.read   s     zz"$${!8d)d"NN'')7||q( T{ KKN d)d" T{r   c                     | j                   s
t               t        |t        t        f      st        dt        dt        |            | j                  j                  |       t        |      S )z-Output the given string over the serial port.z	expected z or bytearray, got )
r2   rk   
isinstancert   rp   	TypeErrorr/   r8   writerq   )r9   datas     r   rz   zSerial.write   sQ    zz"$$$	 23%dTUUd#4yr   c                     | j                   s
t               | j                  j                  | j                  j	                                y)z9Clear input buffer, discarding all that is in the buffer.N)r2   rk   r6   skiprl   ri   s    r   reset_input_bufferzSerial.reset_input_buffer   s1    zz"$$DNN4467r   c                 d    | j                   s
t               | j                  j                          y)zs        Clear output buffer, aborting the current output and
        discarding all that is in the buffer.
        N)r2   rk   r8   flushri   s    r   reset_output_bufferzSerial.reset_output_buffer   s$    
 zz"$$r   c                 l    | j                   s
t               | j                   j                  |dz         y)zHSend break condition. Timed, returns to idle state after given duration.g     @@N)r2   rk   	sendBreak)r9   durations     r   
send_breakzSerial.send_break   s(    zz"$$

Xf_-r   c                 D    | j                   
t               t        d      )zBSet break: Controls TXD. When active, to transmitting is possible.z<The _update_break_state function is not implemented in java.)fdrk   r-   ri   s    r   _update_break_statezSerial._update_break_state   s     77?"$$\]]r   c                 z    | j                   s
t               | j                   j                  | j                         y)z)Set terminal status line: Request To SendN)r2   rk   setRTS
_rts_stateri   s    r   _update_rts_statezSerial._update_rts_state   (    zz"$$

$//*r   c                 z    | j                   s
t               | j                   j                  | j                         y)z-Set terminal status line: Data Terminal ReadyN)r2   rk   setDTR
_dtr_stateri   s    r   _update_dtr_statezSerial._update_dtr_state   r   r   c                 d    | j                   s
t               | j                   j                          y)z(Read terminal status line: Clear To SendN)r2   rk   isCTSri   s    r   ctsz
Serial.cts   $     zz"$$

r   c                 d    | j                   s
t               | j                   j                          y)z)Read terminal status line: Data Set ReadyN)r2   rk   isDSRri   s    r   dsrz
Serial.dsr   r   r   c                 d    | j                   s
t               | j                   j                          y)z)Read terminal status line: Ring IndicatorN)r2   rk   isRIri   s    r   riz	Serial.ri   "     zz"$$

r   c                 d    | j                   s
t               | j                   j                          y)z)Read terminal status line: Carrier DetectN)r2   rk   isCDri   s    r   cdz	Serial.cd   r   r   N)r   )g      ?)__name__
__module____qualname____doc__r1   r4   rh   propertyrm   rr   rz   r~   r   r   r   r   r   r   r   r   r    r   r   r(   r(   7   s    
.5/n! * *&8 .^++        r   r(   N)	
__future__r   serial.serialutilr   r   r   r&   
SerialBaser(   r   r   r   <module>r      sB    ' 	I  'DZ Dr   