Current File : //usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pyo
�
��MNc@sXddlTddlZddlZddlZiejd6ejd6ejd6ejd6Zde	fd��YZ
yddlZWn*ek
r�d	e
e
fd
��YZnXd	e
ejfd��YZedkrTddlZed
�Zejjde�ejjd�ejd�ej�ejjdejd��ej�ndS(i����(t*NtdebugtinfotwarningterrortLoopbackSerialcBs�eZdZd&Zd�Zd�Zd�Zd�Zd�Zd�Z	dd�Z
d�Zd�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	threadingtLocktbuffer_lockt	bytearraytloop_buffertFalsetctstdsrt_porttfromURLtportt_reconfigurePorttTruet_rtsctstsetRTStsetDTRt
flushInputtflushOutput(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�q5td	|f��q5WWn#tk
r�}td
|��nXdS(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)tbasicConfigt	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
SerialBaseRtiotImportErrortFileLikeRRt	RawIOBaseRNtsystststdoutREtflushRAR%(((sC/usr/lib/python2.7/site-packages/serial/urlhandler/protocol_loop.pyt<module>s.




�