ó
*­„Jc           @   s^  d  d l  Z  d  d l Z d  d l Z d  d l Td „  Z e j e j Z d „  Z d e	 f d „  ƒ  YZ
 y d  d l Z Wn* e k
 r¢ d e
 e f d „  ƒ  YZ n Xd e
 e j f d	 „  ƒ  YZ e d
 k rZd  d l Z e d ƒ Z e j j d e ƒ e ƒ  Z e j j d e ƒ d e _ d e _ e j ƒ  d e _ e j ƒ  e j j d e ƒ n  d S(   iÿÿÿÿN(   t   *c         C   s   t  j j j j ƒ  |  S(   s%   Turn a port number into a device name(   t   Systemt   IOt   Portst
   SerialPortt   GetPortNames(   t   portnum(    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyt   device   s    c         C   s#   t  g  |  D] } t | ƒ ^ q
 ƒ S(   N(   t   sabt   ord(   t   stringt   x(    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyt   as_byte_array   s    t
   IronSerialc           B   s¼   e  Z d  Z d% Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z	 d „  Z
 d „  Z d „  Z d d „ Z e d „ Z e d „ Z e d  „ Z d! „  Z d" „  Z d# „  Z d$ „  Z RS(&   s(   Serial port implemenation for .NET/Mono.i2   iK   in   i†   i–   iÈ   i,  iX  i°  i  i`	  iÀ  i€%  i K  i –  i á  i Â c         C   sÓ   |  j  d k r t d ƒ ‚ n  y t j j j |  j ƒ |  _ Wn5 t	 k
 rt } d |  _ t d |  j | f ƒ ‚ n X|  j
 ƒ  |  j j ƒ  t |  _ |  j s» |  j t ƒ |  j t ƒ n  |  j ƒ  |  j ƒ  d S(   sj   Open port with current settings. This may throw a SerialException
           if the port cannot be opened.s.   Port must be configured before it can be used.s   could not open port %s: %sN(   t   _portt   Nonet   SerialExceptionR   R   R   R   t   portstrt   _port_handlet	   Exceptiont   _reconfigurePortt   Opent   Truet   _isOpent   _rtsctst   setRTSt   setDTRt
   flushInputt   flushOutput(   t   selft   msg(    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyt   open    s    	
		
c         C   sw  |  j  s t d ƒ ‚ n  |  j d k rB t j j j j |  j  _	 n t
 |  j d ƒ |  j  _	 |  j d k r… t j j j j |  j  _ n t
 |  j d ƒ |  j  _ y |  j |  j  _ Wn% t k
 rØ } t t | ƒ ƒ ‚ n X|  j t k r÷ d |  j  _ nm |  j t k rd |  j  _ nO |  j t k r3d |  j  _ n1 |  j t k rQd |  j  _ n t d |  j ƒ ‚ |  j t k r”t t j j j d ƒ |  j  _ n» |  j t k r¾t j j j j |  j  _ n‘ |  j t k rèt j j j j |  j  _ ng |  j t  k rt j j j j! |  j  _ n= |  j t" k r<t j j j j# |  j  _ n t d	 |  j ƒ ‚ |  j$ t% k ryt j j j& j' |  j  _& ng |  j$ t( k r£t j j j& j) |  j  _& n= |  j$ t* k rÍt j j j& j+ |  j  _& n t d
 |  j$ ƒ ‚ |  j, r|  j- rt j j j. j/ |  j  _. nf |  j, r1t j j j. j0 |  j  _. nB |  j- rUt j j j. j1 |  j  _. n t t j j j. d ƒ |  j  _. d S(   s,   Set communication parameters on opened port.s'   Can only operate on a valid port handleiè  i   i   i   i   s#   Unsupported number of data bits: %rR   s   Unsupported parity mode: %rs#   Unsupported number of stop bits: %rN(2   R   R   t   _timeoutR   R   R   R   R   t   InfiniteTimeoutt   ReadTimeoutt   intt   _writeTimeoutt   WriteTimeoutt	   _baudratet   BaudRatet   IOErrort
   ValueErrort   strt	   _bytesizet   FIVEBITSt   DataBitst   SIXBITSt	   SEVENBITSt	   EIGHTBITSt   _parityt   PARITY_NONEt   getattrt   Parityt   PARITY_EVENt   Event
   PARITY_ODDt   Oddt   PARITY_MARKt   Markt   PARITY_SPACEt   Spacet	   _stopbitst   STOPBITS_ONEt   StopBitst   Onet   STOPBITS_ONE_POINT_FIVEt   OnePointFivet   STOPBITS_TWOt   TwoR   t   _xonxofft	   Handshaket   RequestToSendXOnXOfft   RequestToSendt   XOnXOff(   R   t   e(    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyR   4   s\    	!		c         C   s\   |  j  rX |  j rL y |  j j ƒ  Wn t j j j k
 r? n Xd |  _ n  t |  _  n  d S(   s
   Close portN(	   R   R   t   CloseR   R   R   t   InvalidOperationExceptionR   t   False(   R   (    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyt   close}   s    		c         C   s:   y t  | ƒ SWn% t k
 r5 } t t | ƒ ƒ ‚ n Xd  S(   N(   R   t	   TypeErrorR   R*   (   R   t   portRJ   (    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyt   makeDeviceName‰   s    c         C   s   |  j  s t ‚ n  |  j  j S(   s>   Return the number of characters currently in the input buffer.(   R   t   portNotOpenErrort   BytesToRead(   R   (    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyt	   inWaiting‘   s    	 	i   c         C   sp   |  j  s t ‚ n  t ƒ  } xH | re y | j |  j  j ƒ  ƒ Wn t j k
 rW } Pq X| d 8} q Wt | ƒ S(   sÆ   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.i   (   R   RR   t	   bytearrayt   appendt   ReadByteR   t   TimeoutExceptiont   bytes(   R   t   sizet   dataRJ   (    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyt   read–   s    	 			c         C   s•   |  j  s t ‚ n  t | t t f ƒ sF t d t t | ƒ f ƒ ‚ n  y& |  j  j t | ƒ d t	 | ƒ ƒ Wn t
 j k
 rŠ } t ‚ n Xt	 | ƒ S(   s-   Output the given string over the serial port.s    expected %s or bytearray, got %si    (   R   RR   t
   isinstanceRY   RU   RO   t   typet   WriteR   t   lenR   RX   t   writeTimeoutError(   R   R[   RJ   (    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyt   write§   s    	 	&
c         C   s#   |  j  s t ‚ n  |  j  j ƒ  d S(   s9   Clear input buffer, discarding all that is in the buffer.N(   R   RR   t   DiscardInBuffer(   R   (    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyR   ´   s    	 	c         C   s#   |  j  s t ‚ n  |  j  j ƒ  d S(   sb   Clear output buffer, aborting the current output and
        discarding all that is in the buffer.N(   R   RR   t   DiscardOutBuffer(   R   (    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyR   ¹   s    	 	g      Ð?c         C   sG   |  j  s t ‚ n  d d l } t |  j  _ | j | ƒ t |  j  _ d S(   sH   Send break condition. Timed, returns to idle state after given duration.iÿÿÿÿN(   R   RR   t   timeR   t
   BreakStatet   sleepRM   (   R   t   durationRe   (    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyt	   sendBreak¿   s    	 	c         C   s(   |  j  s t ‚ n  t | ƒ |  j  _ d S(   sB   Set break: Controls TXD. When active, to transmitting is possible.N(   R   RR   t   boolRf   (   R   t   level(    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyt   setBreakÇ   s    	 	c         C   s(   |  j  s t ‚ n  t | ƒ |  j  _ d S(   s)   Set terminal status line: Request To SendN(   R   RR   Rj   t	   RtsEnable(   R   Rk   (    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyR   Ì   s    	 	c         C   s(   |  j  s t ‚ n  t | ƒ |  j  _ d S(   s-   Set terminal status line: Data Terminal ReadyN(   R   RR   Rj   t	   DtrEnable(   R   Rk   (    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyR   Ñ   s    	 	c         C   s   |  j  s t ‚ n  |  j  j S(   s(   Read terminal status line: Clear To Send(   R   RR   t
   CtsHolding(   R   (    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyt   getCTSÖ   s    	 	c         C   s   |  j  s t ‚ n  |  j  j S(   s)   Read terminal status line: Data Set Ready(   R   RR   t
   DsrHolding(   R   (    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyt   getDSRÛ   s    	 	c         C   s   |  j  s t ‚ n  t S(   s)   Read terminal status line: Ring Indicator(   R   RR   RM   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyt   getRIà   s    	 	c         C   s   |  j  s t ‚ n  |  j  j S(   s)   Read terminal status line: Carrier Detect(   R   RR   t	   CDHolding(   R   (    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyt   getCDæ   s    	 	(   i2   iK   in   i†   i–   iÈ   i,  iX  i°  i  i`	  iÀ  i€%  i K  i –  i á  i Â (   t   __name__t
   __module__t   __doc__t	   BAUDRATESR   R   RN   RQ   RT   R\   Rb   R   R   Ri   R   Rl   R   R   Rp   Rr   Rs   Ru   (    (    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyR      s(    		I									t   Serialc           B   s   e  Z RS(    (   Rv   Rw   (    (    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyRz   ö   s   c           B   s   e  Z RS(    (   Rv   Rw   (    (    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyRz   ú   s   t   __main__i    s   %s
i K  i   (   t   clrR   t   System.IO.Portst
   serialutilR   t   Arrayt   ByteR   R   t
   SerialBaseR   t   iot   ImportErrort   FileLikeRz   t	   RawIOBaseRv   t   syst   st   stdioRb   t   baudratet   databitsRN   RP   R   (    (    (    s4   /usr/lib/python2.7/dist-packages/serial/serialcli.pyt   <module>	   s0   
		Ø			
	
