� ���Mc@sXddlTddlZddlZddlZiejd6ejd6ejd6ejd6Zde fd��YZ yddl Z Wn*e k r�d e e fd ��YZnXd e e jfd ��YZed krTddlZed �Zejjde�ejjd�ejd�ej�ejjdejd��ej�ndS(i����(t*Ntdebugtinfotwarningterrort SocketSerialcBs�eZdZd&Zd�Zd�Zd�Zd�Zd�Zd�Z dd�Z d�Z d�Z d�Z dd�Zed�Zed �Zed!�Zd"�Zd#�Zd$�Zd%�ZRS('s-Serial port implementation for plain sockets.i2iKini�i�i�i,iXi�ii` i�i�%iKi�i�i�cCsd|_|jdkr'td��n|jr?td��ny;tjtjtj�|_|jj |j |j ��Wn5t k r�}d|_td|j |f��nX|jj d�|j�t|_|js�|jt�|jt�n|j�|j�dS(sjOpen 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.sPort is already open.sCould not open port %s: %siN(tNonetloggert_porttSerialExceptiont_isOpentsockettAF_INETt SOCK_STREAMt_sockettconnecttfromURLtportstrt Exceptiont settimeoutt_reconfigurePorttTruet_rtsctstsetRTStsetDTRt flushInputt flushOutput(tselftmsg((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pytopen(s&         cCs>|jdkrtd��n|jr:|jjd�ndS(siSet communication parameters on opened port. for the socket:// protocol all settings are ignored!sCan only operate on open portss!ignored port configuration changeN(RRR RR(R((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pyRCs cCsi|jre|jrLy$|jjtj�|jj�WnnXd|_nt|_tj d�ndS(s Close portg333333�?N( R RtshutdownR t SHUT_RDWRtcloseRtFalsettimetsleep(R((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pyR Ks    cCstd��dS(Ns2there is no sensible way to turn numbers into URLs(R (Rtport((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pytmakeDeviceNameZscCsu|j�jd�r"|d}ny#d|kr�|jdd�\}}x�|jd�D]�}d|kr�|jdd�\}}nd}|dkr�tj�tjd�|_|jjt |�|jj d�qYt d |f��qYWn|jd d�\}}t |�}d |ko0d knsDt d ��nWn#t k rj}t d|��nX||fS(s(extract host and port from an URL strings socket://i t/it=tloggingspySerial.socketsenabled loggingsunknown option: %rt:iisport not in range 0...65535sRexpected a string in the form "[rfc2217://]:[/option[/option...]]": %sN(tlowert startswithtsplitRR(t basicConfigt getLoggerRtsetLevelt LOGGER_LEVELSRt ValueErrortintR (RturltoptionstoptiontvaluethostR$te((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pyR]s,      cCs2|jst�n|jr.|jjd�ndS(s>Return the number of characters currently in the input buffer.s&WARNING: inWaiting returns dummy valuei(R tportNotOpenErrorRR(R((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pyt inWaiting|s   icCs�|jst�nt�}tj�|j}x�t|�|kr�tj�|kr�y |jj|t|��}Wq1tj k r�q1q1tj k r�}t d|��q1Xq1Wt |�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.sconnection failed (%s)( R R9t bytearrayR"t_timeouttlenRtrecvR ttimeoutRR tbytes(RtsizetdataR?R8((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pytread�s  ' cCsY|jst�ny|jj|�Wn&tjk rN}td|��nXt|�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.ssocket connection failed: %s(R R9RtsendallR RR R=(RRBR8((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pytwrite�s cCs2|jst�n|jr.|jjd�ndS(s9Clear input buffer, discarding all that is in the buffer.signored flushInputN(R R9RR(R((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pyR�s  cCs2|jst�n|jr.|jjd�ndS(sbClear output buffer, aborting the current output and discarding all that is in the buffer.signored flushOutputN(R R9RR(R((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pyR�s  g�?cCs9|jst�n|jr5|jjd|f�ndS(sPSend break condition. Timed, returns to idle state after given duration.signored sendBreak(%r)N(R R9RR(Rtduration((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pyt sendBreak�s  cCs9|jst�n|jr5|jjd|f�ndS(sJSet break: Controls TXD. When active, to transmitting is possible.signored setBreak(%r)N(R R9RR(Rtlevel((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pytsetBreak�s  cCs9|jst�n|jr5|jjd|f�ndS(s)Set terminal status line: Request To Sendsignored setRTS(%r)N(R R9RR(RRH((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pyR�s  cCs9|jst�n|jr5|jjd|f�ndS(s-Set terminal status line: Data Terminal Readysignored setDTR(%r)N(R R9RR(RRH((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pyR�s  cCs2|jst�n|jr.|jjd�ntS(s(Read terminal status line: Clear To Sendsreturning dummy for getCTS()(R R9RRR(R((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pytgetCTS�s   cCs2|jst�n|jr.|jjd�ntS(s)Read terminal status line: Data Set Readysreturning dummy for getDSR()(R R9RRR(R((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pytgetDSR�s   cCs2|jst�n|jr.|jjd�ntS(s)Read terminal status line: Ring Indicatorsreturning dummy for getRI()(R R9RRR!(R((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pytgetRI�s   cCs2|jst�n|jr.|jjd�ntS(s)Read terminal status line: Carrier Detectsreturning dummy for getCD()(R R9RRR(R((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pytgetCD�s   (i2iKini�i�i�i,iXi�ii` i�i�%iKi�i�i�(t__name__t __module__t__doc__t BAUDRATESRRR R%RR:RCRERRRGRRIRRRJRKRLRM(((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pyR"s*                tSerialcBseZRS((RNRO(((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pyRR�scBseZRS((RNRO(((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pyRR�st__main__ssocket://localhost:7000s%s s write... shello s read: %s i(tserial.serialutilR"R R(tDEBUGtINFOtWARNINGtERRORR0t SerialBaseRtiot ImportErrortFileLikeRRt RawIOBaseRNtsystststdoutREtflushRCR (((sE/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_socket.pyts.        �