Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/serial/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/serial/serialposix.pyc


VyNc0@sddlZddlZddlZddlZddlZddlZddlZddlZddlTej	dkrddl
Z
neZ
ej	dkrddlZneZejj
Zed dkrdZdZd	Zd
Zidd6dd
6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd 6d!d"6d#d$6d%d&6d'd(6d)d*6d+d,6d-d.6d/d06d1d26d3d46d5d66d7d86d9d:6d;d<6d=d>6d?d@6dAdB6dCdD6dEdF6ZnedGkrdHZdIZiZnedJkrdKZdLZiZned dMkpLed dNkpLed dOkrjdPZdQZiZnxed dRkrejdjdSZeeddkrdTZn	dUZdVZiZned dWkrdXZdYZiZned dZkr&d[Zd\ZiZned d]krQd^Zd_ZiZned d`kr|daZdbZiZnfed dckrddZdeZiZn;ejjdfejejefdgZdhZiZee
dioe
jpdjZee
dkoe
jpdlZee
dmo3e
jp9dnZee
dooQe
j pWdpZ ee
dqooe
j!pudZ!ee
droe
j"pdZ"ee
dsoe
j#pdtZ#ee
duoe
j$pdvZ$ee
dwoe
j%pdxZ%ee
dyoe
j&pdzZ&ee
d{o#e
j'p)e$Z'ee
d|oAe
j(pGe%Z(ee
d}o_e
j)ped~Z*ej+ddZ,ej+de"Z-ej+de!Z.ee
doe
j/pdZ/ee
doe
j0pdZ0de1fdYZ2yddl3Z3Wn*e4k
r,de2e5fdYZ6nXde2e3j7fdYZ6de6fdYZ8e9dkre6ddd&de:de;de<ddddddZ=e=j>de=j?de=j@e=jAe=jdejBjde=jCdejBjde=jD[=ndS(iN(t*iiitlinuxcCsd|S(Ns/dev/ttyS%d((tport((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytdevice$si0i0cCsddl}|jddgd}tj|jtj||d||d<|dctM<|dctO<ytj|jtj|}Wn!t	k
rt
d|nXdS(	Nitiii iiis"Failed to set custom baud rate: %r(tarraytFCNTLtioctltfdtTERMIOStTIOCGSERIALtASYNC_SPD_MASKtASYNC_SPD_CUSTtTIOCSSERIALtIOErrort
ValueError(RtbaudrateRtbuftres((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytset_special_baudrate*s
iii2iiKiiniiiiiii,iiXi	ii
iii`	iii
i%iiKiiiiiiiiiiii iiiiii@Bi	ii
i`iiii%&i
i-iig5ii	=tcygwincCsd|dS(Ns
/dev/com%di((R((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRbscCstddS(NsFsorry don't know how to handle non standard baud rate on this platform(R(RR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRestopenbsd3cCsd|S(Ns/dev/ttyp%d((R((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRlscCstddS(NsFsorry don't know how to handle non standard baud rate on this platform(R(RR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRostbsdtfreebsdtopenbsdcCsd|S(Ns/dev/cuad%d((R((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRxscCstddS(NsFsorry don't know how to handle non standard baud rate on this platform(R(RR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyR{stdarwint.cCsPddl}ddl}|jd|g}d}|j|j||ddS(NiRITi(RtfcntlRR(RRRRRtIOSSIOSPEED((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRscCstddS(Nsbaud rate not supported(R(RR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRscCsd|S(Ns/dev/cuad%d((R((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRstnetbsdcCsd|S(Ns/dev/dty%02d((R((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRscCstddS(NsFsorry don't know how to handle non standard baud rate on this platform(R(RR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRstirixcCsd|dS(Ns/dev/ttyf%di((R((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRscCstddS(NsFsorry don't know how to handle non standard baud rate on this platform(R(RR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRsthpcCsd|dS(Ns/dev/tty%dp0i((R((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRscCstddS(NsFsorry don't know how to handle non standard baud rate on this platform(R(RR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRstsunoscCsdtd|S(Ns
/dev/tty%cta(tord(R((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRscCstddS(NsFsorry don't know how to handle non standard baud rate on this platform(R(RR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRstaixcCsd|S(Ns
/dev/tty%d((R((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRscCstddS(NsFsorry don't know how to handle non standard baud rate on this platform(R(RR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRssdon't know how to number ttys on this system.
! Use an explicit path (eg /dev/ttyS1) or send this information to
! the author of this module:

sys.platform = %r
os.name = %r
serialposix.py version = %s

also add the device name of the serial port and where the
counting starts for the first serial port.
e.g. 'first serial port: /dev/ttyS0'
and with a bit luck you can get this module running...
cCsd|S(Ns/dev/ttyS%d((tportnum((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRscCstddS(NsFsorry don't know how to handle non standard baud rate on this platform(tSerialException(RR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRstTIOCMGETiTtTIOCMBISiTtTIOCMBICiTtTIOCMSETiTt	TIOCM_DTRt	TIOCM_RTSt	TIOCM_CTSi t	TIOCM_CARi@t	TIOCM_RNGit	TIOCM_DSRitTIOCM_CDtTIOCM_RItFIONREADiTtItTIOCSBRKi'TtTIOCCBRKi(TtPosixSerialcBseZdZdZdZdZdZdZddZdZ	d	Z
d
ZdZdd
Z
ddZddZddZdZdZdZdZdZdZdZdZRS(sSerial port class POSIX implementation. Serial port configuration is 
    done with termios and fcntl. Runs on Linux and many other Un*x like
    systems.cCsd|_|jdkr'tdny-tj|jtjtjBtj	B|_Wn5t
k
r}d|_td|j|fnXy|jWn1ytj|jWnnXd|_n
Xt
|_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.scould not open port %s: %sN(tNoneRt_portR%tostopentportstrtO_RDWRtO_NOCTTYt
O_NONBLOCKt	Exceptiont_reconfigurePorttclosetTruet_isOpen(tselftmsg((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyR:	s$	-		c
Cs|jdkrtdnd}d}}|jdk	rYd}t|jd}ny+tj|j\}}}}}}	}
Wn&tjk
r}td|nX|tj	tj
BO}|tjtjBtj
BtjBtjBtjBtjBM}x4dD],}tt|r|tt|M}qqW|tjM}|tjtjBtjBtjBM}ttdr|tjM}nttd	r|tjM}nyttd
|j}}	Wntk
rjyt|j}}	Wqktk
rfttd}}	yt|j}Wn$tk
r@td|jqgX|dkrgtd|jqgqkXnX|tj M}|j!d
kr|tj"O}np|j!dkr|tj#O}nQ|j!dkr|tj$O}n2|j!dkr|tj%O}ntd|j!|j&t'kr(|tj(M}nQ|j&t)krG|tj(O}n2|j&t*krf|tj(O}ntd|j&|tj+tj,BM}|j-t.kr|tj/tj0BM}nf|j-t1kr|tj0M}|tj/O}n9|j-t2kr|tj/tj0BO}ntd|j-ttdri|j3rJ|tj4tj5BO}q|tj4tj5Btj6BM}n5|j3r|tj4tj5BO}n|tj4tj5BM}ttdr|j7r|tj8O}q|tj8M}n9ttdr|j7r|tj9O}q|tj9M}n|dks(|dkr;td|n||
tj:<|dks`|dkrstd|n||
tj;<tj<|jtj=||||||	|
g|dk	rt>||ndS(s,Set communication parameters on opened port.s+Can only operate on a valid file descriptoriii
sCould not configure port: %stECHOCTLtECHOKEtIUCLCtPARMRKsB%stB38400sInvalid baud rate: %riiiisInvalid char len: %rs"Invalid stop bit specification: %rsInvalid parity: %rtIXANYtCRTSCTStCNEW_RTSCTSisInvalid vmin: %r sInvalid vtime: %rN(RFRG(?RR7R%t_interCharTimeouttintttermiost	tcgetattrterrorR	tCLOCALtCREADtICANONtECHOtECHOEtECHOKtECHONLtISIGtIEXTENthasattrtgetattrtOPOSTtINLCRtIGNCRtICRNLtIGNBRKRHRIt	_baudratetAttributeErrortbaudrate_constantstKeyErrorRtCSIZEt	_bytesizetCS8tCS7tCS6tCS5t	_stopbitstSTOPBITS_ONEtCSTOPBtSTOPBITS_ONE_POINT_FIVEtSTOPBITS_TWOtINPCKtISTRIPt_paritytPARITY_NONEtPARENBtPARODDtPARITY_EVENt
PARITY_ODDt_xonxofftIXONtIXOFFRKt_rtsctsRLRMtVMINtVTIMEt	tcsetattrtTCSANOWR(
RDtcustom_baudtvmintvtimetiflagtoflagtcflagtlflagtispeedtospeedtccREtflag((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyR@'s
+5
#


				

.cCsD|jr@|jdk	r4tj|jd|_nt|_ndS(s
Close portN(RCRR7R9RAtFalse(RD((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRAs
	cCs
t|S(N(R(RDR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytmakeDeviceNamescCs,tj|jtt}tjd|dS(s>Return the number of characters currently in the input buffer.R3i(RRRtTIOCINQtTIOCM_zero_strtstructtunpack(RDts((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyt	inWaitingsicCs|jdkrtnt}xt||krtj|jggg|j\}}}|sjPntj|j|t|}|st	dn|j
|q$Wt|S(sRead 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.sLdevice reports readiness to read but returned no data (device disconnected?)N(RR7tportNotOpenErrort	bytearraytlentselectt_timeoutR9treadR%textendtbytes(RDtsizeRtreadyt_R((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRs		*c
CsP|jdkrtnt|}|}|jdk	r^|jdkr^tj|j}nd}x|dkrEytj|j|}|r|tj}|dkrtnt	j	g|jgg|\}}}|stqn||}||}Wqgt
k
rA}	|	jtjkrBt
d|	fqBqgXqgWt|S(s-Output the given string over the serial port.iswrite failed: %sN(RR7RRt
_writeTimeoutttimeR9twritetwriteTimeoutErrorRtOSErrorterrnotEAGAINR%(
RDtdatatttdttimeouttnttimeleftRRtv((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRs.		'
cCs|jdS(sTFlush of file like objects. In this case, wait until all data
           is written.N(tdrainOutput(RD((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytflushscCs2|jdkrtntj|jtjdS(s9Clear input buffer, discarding all that is in the buffer.N(RR7RRPttcflushR	tTCIFLUSH(RD((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyt
flushInputs	cCs2|jdkrtntj|jtjdS(sbClear output buffer, aborting the current output and
        discarding all that is in the buffer.N(RR7RRPRR	tTCOFLUSH(RD((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytflushOutputs	g?cCs9|jdkrtntj|jt|ddS(sHSend break condition. Timed, returns to idle state after given duration.g?N(RR7RRPttcsendbreakRO(RDtduration((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyt	sendBreaks	cCsK|jdkrtn|r4tj|jtntj|jtdS(sBSet break: Controls TXD. When active, no transmitting is possible.N(RR7RRRR4R5(RDtlevel((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytsetBreaks
	cCsQ|jdkrtn|r7tj|jttntj|jttdS(s)Set terminal status line: Request To SendN(RR7RRRR't
TIOCM_RTS_strR((RDR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytsetRTSs
	cCsQ|jdkrtn|r7tj|jttntj|jttdS(s-Set terminal status line: Data Terminal ReadyN(RR7RRRR't
TIOCM_DTR_strR((RDR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytsetDTRs
	cCsN|jdkrtntj|jtt}tjd|dt	@dkS(s(Read terminal status line: Clear To SendR3iN(
RR7RRRR&RRRR,(RDR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytgetCTSs	cCsN|jdkrtntj|jtt}tjd|dt	@dkS(s)Read terminal status line: Data Set ReadyR3iN(
RR7RRRR&RRRR/(RDR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytgetDSRs	cCsN|jdkrtntj|jtt}tjd|dt	@dkS(s)Read terminal status line: Ring IndicatorR3iN(
RR7RRRR&RRRR1(RDR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytgetRI$s	cCsN|jdkrtntj|jtt}tjd|dt	@dkS(s)Read terminal status line: Carrier DetectR3iN(
RR7RRRR&RRRR0(RDR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytgetCD*s	cCs,|jdkrtntj|jdS(sinternal - not portable!N(RR7RRPttcdrain(RD((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyR2s	cCs8|jdkrtntj|jtjtjdS(sinternal - not portable!N(RR7RRRtF_SETFLR9R>(RD((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytnonblocking7s	cCs|jdkrtn|jS(sFor easier use of the serial port instance with select.
           WARNING: this function is not portable to different platforms!N(RR7R(RD((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytfileno=s	cCs9|rtj|jtjntj|jtjdS(sQmanually control flow - when hardware or software flow control is
        enabledN(RPttcflowRR	tTCIONtTCIOFF(RDtenable((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytflowControlCs(t__name__t
__module__t__doc__R:R@RARRRRRRRRRRRRRRRRRRR(((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyR6s.		x														tSerialcBseZRS((RR(((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRSscBseZRS((RR(((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRWstPosixPollSerialcBseZdZddZRS(spoll based read implementation. not all systems support poll properly.
    however this one has better handling of errors, such as a device
    disconnecting while it's in use (e.g. USB-serial unplugged)icCsN|jdkrtnt}tj}|j|jtjtjBtj	Btj
B|dkrDxt||kr@xN|j|jdD]6\}}|tjtj	Btj
B@rt
dqqWtj|j|t|}|j||jdk	r|jdks2|jdk	rg|jdkrg|rgPqgqgWnt|S(sRead 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.iisdevice reports error (poll)N(RR7RRRtpolltregistertPOLLINtPOLLERRtPOLLHUPtPOLLNVALRRR%R9RRRNR(RDRRRRteventR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyR_s 		+#
%(RRRR(((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRZst__main__RtbytesizetparitytstopbitsRtxonxofftrtsctsthellos%r
s%s
(EtsysR9RRPRRRRt
serialutilt
hexversionR	RtplatformtlowertplatRRRRRetunametsplittversionROtstderrRtnametVERSIONR\R&R'R(R)R*R+R,R-R.R/R0R1R2RtpackRRRR4R5t
SerialBaseR6tiotImportErrortFileLikeRt	RawIOBaseRRt	EIGHTBITSRxRnRRRRRtstdoutRR(((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyt<module>s`
		
																												
			L