ó ¯ÁMNc@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*NtdebugtinfotwarningterrortLoopbackSerialcBsÅ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('sSSerial port implementation that simulates a loop back connection in plain software.i2iKini†i–iÈi,iXi°ii` iÀi€%iKi–iáiÂcCsÍ|jrtdƒ‚nd|_tjƒ|_tƒ|_t |_ t |_ |j dkrltdƒ‚n|j |jƒ|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.sPort is already open.s.Port must be configured before it can be used.N(t_isOpentSerialExceptiontNonetloggert threadingtLockt buffer_lockt bytearrayt loop_buffertFalsetctstdsrt_porttfromURLtportt_reconfigurePorttTruet_rtsctstsetRTStsetDTRt flushInputt flushOutput(tself((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pytopen&s"          cCsot|jttfƒ s9d|jko3dkn rOtd|jƒ‚n|jrk|jjdƒndS(sgSet communication parameters on opened port. for the loop:// protocol all settings are ignored!iii sinvalid baudrate: %rs_reconfigurePort()NI(t isinstancet _baudratetinttlongt ValueErrorR R(R((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pyRAs9 cCs&|jr"t|_tjdƒndS(s Close portg333333Ó?N(RRttimetsleep(R((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pytcloseJs  cCstdƒ‚dS(Ns2there is no sensible way to turn numbers into URLs(R(RR((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pytmakeDeviceNameQscCs|jƒjdƒr"|d}ny¶x¯|jdƒD]ž}d|krb|jddƒ\}}nd }|sqq5|dkrÀtjƒtjdƒ|_|jjt |ƒ|jj dƒq5t d |fƒ‚q5WWn#t k rý}t d |ƒ‚nXd S( s(extract host and port from an URL stringsloop://it/t=itloggings pySerial.loopsenabled loggingsunknown option: %rsAexpected a string in the form "[loop://][option[/option...]]": %sN( tlowert startswithtsplitRR)t basicConfigt getLoggerR tsetLevelt LOGGER_LEVELSRR"R(Rturltoptiontvaluete((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pyRTs"    cCsK|jst‚n|jr>|jjdt|jƒfƒnt|jƒS(s>Return the number of characters currently in the input buffer.sinWaiting() -> %d(RtportNotOpenErrorR RtlenR(R((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pyt inWaitingls   #icCsØ|jst‚n|jdk r7tjƒ|j}nd}tƒ}x…|dkrÍ|jjƒz!t|j | ƒ}|j |4Wd|jj ƒX||7}|t |ƒ8}|rItjƒ|krIPqIqIWt |ƒ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.iN( RR5t_timeoutRR#R R tacquiretto_bytesRtreleaseR6tbytes(Rtsizettimeouttdatatblock((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pytreadus"    cCs§|jst‚nt|ƒ}dt|ƒ|j}|jdk rl||jkrltj|jƒt ‚n|j j ƒz|j |7_ Wd|j j ƒ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.g$@N(RR5R<R6Rt _writeTimeoutRR#R$twriteTimeoutErrorR R9RR;(RR?ttime_used_to_send((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pytwriteŽs    cCs[|jst‚n|jr.|jjdƒn|jjƒz |j2Wd|jjƒXdS(s9Clear input buffer, discarding all that is in the buffer.s flushInput()N(RR5R RR R9RR;(R((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pyR£s    cCs2|jst‚n|jr.|jjdƒndS(sbClear output buffer, aborting the current output and discarding all that is in the buffer.s flushOutput()N(RR5R R(R((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pyR®s  gÐ?cCs|jst‚ndS(sPSend break condition. Timed, returns to idle state after given duration.N(RR5(Rtduration((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pyt sendBreakµs cCs9|jst‚n|jr5|jjd|fƒndS(sJSet break: Controls TXD. When active, to transmitting is possible.s setBreak(%r)N(RR5R R(Rtlevel((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pytsetBreakºs  cCsB|jst‚n|jr5|jjd|fƒn||_dS(s)Set terminal status line: Request To SendssetRTS(%r) -> state of CTSN(RR5R RR(RRH((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pyRÁs   cCsB|jst‚n|jr5|jjd|fƒn||_dS(s-Set terminal status line: Data Terminal ReadyssetDTR(%r) -> state of DSRN(RR5R RR(RRH((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pyRÈs   cCs?|jst‚n|jr8|jjd|jfƒn|jS(s(Read terminal status line: Clear To SendsgetCTS() -> state of RTS (%r)(RR5R RR(R((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pytgetCTSÏs   cCs?|jst‚n|jr8|jjd|jfƒn|jS(s)Read terminal status line: Data Set ReadysgetDSR() -> state of DTR (%r)(RR5R RR(R((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pytgetDSRÖs   cCs2|jst‚n|jr.|jjdƒntS(s)Read terminal status line: Ring Indicatorsreturning dummy for getRI()(RR5R RR(R((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pytgetRIÝs   cCs2|jst‚n|jr.|jjdƒntS(s)Read terminal status line: Carrier Detectsreturning dummy for getCD()(RR5R RR(R((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pytgetCDäs   (i2iKini†i–iÈi,iXi°ii` iÀi€%iKi–iáiÂ(t__name__t __module__t__doc__t BAUDRATESRRR%R&RR7RARERRRGRRIRRRJRKRLRM(((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pyR s*              tSerialcBseZRS((RNRO(((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pyRRöscBseZRS((RNRO(((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pyRRúst__main__sloop://s%s s write... shello s read: %s i(tserial.serialutilR R#R)tDEBUGtINFOtWARNINGtERRORR0t SerialBaseRtiot ImportErrortFileLikeRRt RawIOBaseRNtsystststdoutREtflushRAR%(((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pyts.        Ò