Sc0@sddlZddlZddlZddlZddlZddlZddlZddlZddlTej dkrddl Z neZ ej dkrddl Z neZ ej j Zed dkrdZdZd Zd Zid d 6d 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 dRkrejdjdSZeed dkrdTZn 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&p dzZ&ee d{o#e j'p)e$Z'ee d|oAe j(pGe%Z(ee d}o_e j)ped~Z*ej+dd Z,ej+de"Z-ej+de!Z.ee doe j/pdZ/ee doe j0pdZ0de1fdYZ2yddl3Z3Wn*e4k r,de2e5fdYZ6nXde2e3j7fdYZ6de6fdYZ8e9dkre6d dd&de:de;de<dddd dd Z=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||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: %rtIXANYtCRTSCTSt CNEW_RTSCTSisInvalid vmin: %r sInvalid vtime: %rN(RFRG(?RR8R%t_interCharTimeouttintttermiost tcgetattrterrorR tCLOCALtCREADtICANONtECHOtECHOEtECHOKtECHONLtISIGtIEXTENthasattrtgetattrtOPOSTtINLCRtIGNCRtICRNLtIGNBRKRHRIt _baudratetAttributeErrortbaudrate_constantstKeyErrorRtCSIZEt _bytesizetCS8tCS7tCS6tCS5t _stopbitst STOPBITS_ONEtCSTOPBtSTOPBITS_ONE_POINT_FIVEt STOPBITS_TWOtINPCKtISTRIPt_parityt PARITY_NONEtPARENBtPARODDt PARITY_EVENt PARITY_ODDt_xonxofftIXONtIXOFFRKt_rtsctsRLRMtVMINtVTIMEt tcsetattrtTCSANOWR(RDt custom_baudtvmintvtimet orig_attrtiflagtoflagtcflagtlflagtispeedtospeedtccREtflag((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRA)s 5 #          !1 cCsD|jr@|jdk r4tj|jd|_nt|_ndS(s Close portN(R9RR8R:RBtFalse(RD((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRBs   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|jstnt}xt||krtj|jggg|j\}}}|sdPntj|j|t|}|st dn|j |qWt |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?)( R9tportNotOpenErrort bytearraytlentselectRt_timeoutR:treadR%textendtbytes(RDtsizeRtreadyt_R((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRs  *c CsJ|jstnt|}|}|jdk rX|jdkrXtj|j}nd}x|dkr?ytj|j|}|r|tj}|dkrt nt j g|jgg|\}}}|st qn||}||}Wqat k r;} | j t j kr<td| fq<qaXqaWt|S(s-Output the given string over the serial port.iswrite failed: %sN(R9RRt _writeTimeoutR8ttimeR:twriteRtwriteTimeoutErrorRtOSErrorterrnotEAGAINR%( 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(t drainOutput(RD((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytflushscCs,|jstntj|jtjdS(s9Clear input buffer, discarding all that is in the buffer.N(R9RRPttcflushRR tTCIFLUSH(RD((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyt flushInputs cCs,|jstntj|jtjdS(sbClear output buffer, aborting the current output and discarding all that is in the buffer.N(R9RRPRRR tTCOFLUSH(RD((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyt flushOutputs g?cCs3|jstntj|jt|ddS(sHSend break condition. Timed, returns to idle state after given duration.g?N(R9RRPt tcsendbreakRRO(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(RR8RRRR4R5(RDtlevel((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytsetBreaks  cCsK|jstn|r1tj|jttntj|jttdS(s)Set terminal status line: Request To SendN(R9RRRRR't TIOCM_RTS_strR((RDR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytsetRTS s  cCsK|jstn|r1tj|jttntj|jttdS(s-Set terminal status line: Data Terminal ReadyN(R9RRRRR't TIOCM_DTR_strR((RDR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytsetDTRs  cCsH|jstntj|jtt}tjd|dt @dkS(s(Read terminal status line: Clear To SendR3i( R9RRRRR&RRRR,(RDR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytgetCTSs cCsH|jstntj|jtt}tjd|dt @dkS(s)Read terminal status line: Data Set ReadyR3i( R9RRRRR&RRRR/(RDR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytgetDSRs cCsH|jstntj|jtt}tjd|dt @dkS(s)Read terminal status line: Ring IndicatorR3i( R9RRRRR&RRRR1(RDR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytgetRI%s cCsH|jstntj|jtt}tjd|dt @dkS(s)Read terminal status line: Carrier DetectR3i( R9RRRRR&RRRR0(RDR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytgetCD+s cCs&|jstntj|jdS(sinternal - not portable!N(R9RRPttcdrainR(RD((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyR3s cCs2|jstntj|jtjtjdS(sinternal - not portable!N(R9RRRRtF_SETFLR:R?(RD((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyt nonblocking8s cCs|jstn|jS(sFor easier use of the serial port instance with select. WARNING: this function is not portable to different platforms!(R9RR(RD((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pytfileno=s cCsK|jstn|r1tj|jtjntj|jtjdS(sQmanually control flow - when hardware or software flow control is enabledN(R9RRPttcflowRR tTCIONtTCIOFF(RDtenable((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyt flowControlCs  (t__name__t __module__t__doc__R;RARBRRRRRRRRRRRRRRRRRRR(((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyR6s. z                   tSerialcBseZRS((RR(((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRTscBseZRS((RR(((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyRXstPosixPollSerialcBseZdZddZRS(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(RR8RRRtpolltregistertPOLLINtPOLLERRtPOLLHUPtPOLLNVALRRR%R:RRRNR(RDRRRRteventR((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyR`s    + # % (RRRR(((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyR[st__main__RtbytesizetparitytstopbitsRtxonxofftrtsctsthellos%r s%s (EtsysR:RRPRRRRtserial.serialutilt hexversionR RtplatformtlowertplatRR R RRetunametsplittversionROtstderrRtnametVERSIONR\R&R'R(R)R*R+R,R-R.R/R0R1R2RtpackRRRR4R5t SerialBaseR6tiot ImportErrortFileLikeRt RawIOBaseRRt EIGHTBITSRxRnRRRRRtstdoutRR(((s6/usr/lib/python2.7/dist-packages/serial/serialposix.pyts `                                      M