ó
*­„Jc           @   sX  d  d l  Td  d l Z d  d l Z d  d l Z i e j d 6e j d 6e j d 6e j d 6Z 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 rTd  d l Z e d ƒ Z e j j d e ƒ e j j d ƒ e j d ƒ e j ƒ  e j j d e j d ƒ ƒ e j ƒ  n  d S(   iÿÿÿÿ(   t   *Nt   debugt   infot   warningt   errort   SocketSerialc           B   sÅ   e  Z d  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 implementation for plain sockets.i2   iK   in   i†   i–   iÈ   i,  iX  i°  i  i`	  iÀ  i€%  i K  i –  i á  i Â c         C   sû   d |  _ |  j d k r' t d ƒ ‚ n  y; t j t j t j ƒ |  _ |  j j |  j	 |  j
 ƒ ƒ Wn5 t k
 r™ } d |  _ t d |  j
 | f ƒ ‚ n X|  j j d ƒ |  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: %si   N(   t   Nonet   loggert   _portt   SerialExceptiont   sockett   AF_INETt   SOCK_STREAMt   _sockett   connectt   fromURLt   portstrt	   Exceptiont
   settimeoutt   _reconfigurePortt   Truet   _isOpent   _rtsctst   setRTSt   setDTRt
   flushInputt   flushOutput(   t   selft   msg(    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyt   open(   s"    	 	
		
c         C   s>   |  j  d k r t d ƒ ‚ n  |  j r: |  j j d ƒ n  d S(   si   Set communication parameters on opened port. for the socket://
        protocol all settings are ignored!s   Can only operate on open portss!   ignored port configuration changeN(   R   R   R	   R   R   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyR   A   s    	c         C   si   |  j  re |  j rL y$ |  j j t j ƒ |  j j ƒ  Wn n Xd |  _ n  t |  _  t j	 d ƒ n  d S(   s
   Close portg333333Ó?N(
   R   R   t   shutdownR
   t	   SHUT_RDWRt   closeR   t   Falset   timet   sleep(   R   (    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyR    I   s    			c         C   s   t  d ƒ ‚ d  S(   Ns2   there is no sensible way to turn numbers into URLs(   R	   (   R   t   port(    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyt   makeDeviceNameX   s    c         C   su  | j  ƒ  j d ƒ r" | d } n  y#d | k rõ | j d d ƒ \ } } x© | j d ƒ D]• } d | k r† | j d d ƒ \ } } n d } | d k rÛ t j ƒ  t j d ƒ |  _ |  j j t	 | ƒ |  j j
 d ƒ qY t d	 | f ƒ ‚ qY Wn  | j d
 d ƒ \ } } t | ƒ } d | k o0d k  n sDt d ƒ ‚ n  Wn# t k
 rj} t d | ƒ ‚ n X| | f S(   s(   extract host and port from an URL strings	   socket://i	   t   /i   t   =t   loggings   pySerial.sockets   enabled loggings   unknown option: %rt   :i    i   s   port not in range 0...65535sR   expected a string in the form "[rfc2217://]<host>:<port>[/option[/option...]]": %sN(   t   lowert
   startswitht   splitR   R(   t   basicConfigt	   getLoggerR   t   setLevelt   LOGGER_LEVELSR   t
   ValueErrort   intR	   (   R   t   urlt   optionst   optiont   valuet   hostR$   t   e(    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyR   [   s,     
 c         C   s2   |  j  s t ‚ n  |  j r. |  j j d ƒ n  d S(   s>   Return the number of characters currently in the input buffer.s&   WARNING: inWaiting returns dummy valuei    (   R   t   portNotOpenErrorR   R   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyt	   inWaitingz   s
    	 		i   c         C   sÂ   |  j  s t ‚ n  t ƒ  } t j ƒ  |  j } x‡ t | ƒ | k  r· t j ƒ  | k  r· y  |  j j | t | ƒ ƒ } Wq1 t j	 k
 rŽ q1 q1 t j
 k
 r³ } t d | ƒ ‚ q1 Xq1 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.s   connection failed (%s)(   R   R9   t	   bytearrayR"   t   _timeoutt   lenR   t   recvR
   t   timeoutR   R	   t   bytes(   R   t   sizet   dataR?   R8   (    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyt   read‚   s    	 		' c         C   sY   |  j  s t ‚ n  y |  j j | ƒ Wn& t j k
 rN } t d | ƒ ‚ n Xt | ƒ S(   sœ   Output the given string over the serial port. Can block if the
        connection is blocked. May raise SerialException if the connection is
        closed.s   socket connection failed: %s(   R   R9   R   t   sendallR
   R   R	   R=   (   R   RB   R8   (    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyt   write—   s    	 	c         C   s2   |  j  s t ‚ n  |  j r. |  j j d ƒ n  d S(   s9   Clear input buffer, discarding all that is in the buffer.s   ignored flushInputN(   R   R9   R   R   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyR   ¢   s    	 		c         C   s2   |  j  s t ‚ n  |  j r. |  j j d ƒ n  d S(   sb   Clear output buffer, aborting the current output and
        discarding all that is in the buffer.s   ignored flushOutputN(   R   R9   R   R   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyR   ¨   s    	 		g      Ð?c         C   s9   |  j  s t ‚ n  |  j r5 |  j j d | f ƒ n  d S(   sP   Send break condition. Timed, returns to idle state after given
        duration.s   ignored sendBreak(%r)N(   R   R9   R   R   (   R   t   duration(    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyt	   sendBreak¯   s    	 		c         C   s9   |  j  s t ‚ n  |  j r5 |  j j d | f ƒ n  d S(   sJ   Set break: Controls TXD. When active, to transmitting is
        possible.s   ignored setBreak(%r)N(   R   R9   R   R   (   R   t   level(    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyt   setBreak¶   s    	 		c         C   s9   |  j  s t ‚ n  |  j r5 |  j j d | f ƒ n  d S(   s)   Set terminal status line: Request To Sends   ignored setRTS(%r)N(   R   R9   R   R   (   R   RH   (    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyR   ½   s    	 		c         C   s9   |  j  s t ‚ n  |  j r5 |  j j d | f ƒ n  d S(   s-   Set terminal status line: Data Terminal Readys   ignored setDTR(%r)N(   R   R9   R   R   (   R   RH   (    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyR   Ã   s    	 		c         C   s2   |  j  s t ‚ n  |  j r. |  j j d ƒ n  t S(   s(   Read terminal status line: Clear To Sends   returning dummy for getCTS()(   R   R9   R   R   R   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyt   getCTSÉ   s
    	 		c         C   s2   |  j  s t ‚ n  |  j r. |  j j d ƒ n  t S(   s)   Read terminal status line: Data Set Readys   returning dummy for getDSR()(   R   R9   R   R   R   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyt   getDSRÐ   s
    	 		c         C   s2   |  j  s t ‚ n  |  j r. |  j j d ƒ n  t S(   s)   Read terminal status line: Ring Indicators   returning dummy for getRI()(   R   R9   R   R   R!   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyt   getRI×   s
    	 		c         C   s2   |  j  s t ‚ n  |  j r. |  j j d ƒ n  t S(   s)   Read terminal status line: Carrier Detects   returning dummy for getCD()(   R   R9   R   R   R   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.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   R    R%   R   R:   RC   RE   R   R   RG   R   RI   R   R   RJ   RK   RL   RM   (    (    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyR   "   s*    												t   Serialc           B   s   e  Z RS(    (   RN   RO   (    (    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyRR   ð   s   c           B   s   e  Z RS(    (   RN   RO   (    (    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyRR   ô   s   t   __main__s   socket://localhost:7000s   %s
s	   write...
s   hello
s	   read: %s
i   (   t
   serialutilR"   R
   R(   t   DEBUGt   INFOt   WARNINGt   ERRORR0   t
   SerialBaseR   t   iot   ImportErrort   FileLikeRR   t	   RawIOBaseRN   t   syst   st   stdoutRE   t   flushRC   R    (    (    (    s<   /usr/lib/python2.7/dist-packages/serial/socket_connection.pyt   <module>   s.   



Ê
