�
{�QNc0@sddlZddlZddlZddlZddlZddlZddlZddlZddlTej dkr�ddl
Z
neZ
ej dkr�ddlZneZejj
�Zed dkr�d�ZdZd Zd
�Zidd6dd
6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd 6d!d"6d#d$6d%d&6d'd(6d)d*6d+d,6d-d.6d/d06d1d26d3d46d5d66d7d86d9d:6d;d<6d=d>6d?d@6dAdB6dCdD6dEdF6ZnedGkr�dH�ZdI�ZiZn�edJkrdK�ZdL�ZiZn�ed dMkpLed dNkpLed dOkrjdP�ZdQ�ZiZnxed dRkr�ej�djdS�Zeed�dkr�dT�Zn dU�ZdV�ZiZned dWkr�dX�ZdY�ZiZn�ed dZkr&d[�Zd\�ZiZn�ed d]krQd^�Zd_�ZiZn�ed d`kr|da�Zdb�ZiZnfed dckr�dd�Zde�ZiZn;ejjdfejejef�dg�Zdh�ZiZee
di�o�e
jp�djZee
dk�oe
jpdlZee
dm�o3e
jp9dnZee
do�oQe
j pWdpZ ee
dq�ooe
j!pudZ!ee
dr�o�e
j"p�dZ"ee
ds�o�e
j#p�dtZ#ee
du�o�e
j$p�dvZ$ee
dw�o�e
j%p�dxZ%ee
dy�oe
j&pdzZ&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
d��o�e
j/p�d�Z/ee
d��o�e
j0p�d�Z0d�e1fd���YZ2yddl3Z3Wn*e4k
r,d�e2e5fd���YZ6nXd�e2e3j7fd���YZ6d�e6fd���YZ8e9d�kre6dd�d&d�e:d�e;d�e<d�dd�dd�d�Z=e=j>d�e=j?d�e=j@�e=jA�e=jd��ejBjd�e=jCd��ejBjd�e=jD��[=ndS(�i����N(t*i�i�itlinuxcCsd|S(Ns/dev/ttyS%d((tport((s6/usr/lib/python2.7/site-packages/serial/serialposix.pytdevice$si0i0cCs�ddl}|jddgd�}tj|jtj|�|d||d<|dctM<|dctO<ytj|jtj|�}Wn!t k
r�t
d|��nXdS( Ni����tiii iiis"Failed to set custom baud rate: %r(tarraytFCNTLtioctltfdtTERMIOStTIOCGSERIALtASYNC_SPD_MASKtASYNC_SPD_CUSTtTIOCSSERIALtIOErrort
ValueError(RtbaudrateRtbuftres((s6/usr/lib/python2.7/site-packages/serial/serialposix.pytset_special_baudrate*s
iii2iiKiinii�i�ii�ii,iiXi i�i
iii` ii�i
i�%iiKii�ii�ii�ii�iiii �ii�iiii@Bi i�i
i`�ii��ii�%&i
i��-ii�g5ii =tcygwincCsd|dS(Ns
/dev/com%di((R((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyRbscCstd��dS(NsFsorry don't know how to handle non standard baud rate on this platform(R(RR((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyRestopenbsd3cCsd|S(Ns/dev/ttyp%d((R((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyRlscCstd��dS(NsFsorry don't know how to handle non standard baud rate on this platform(R(RR((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyRostbsdtfreebsdtopenbsdcCsd|S(Ns/dev/cuad%d((R((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyRxscCstd��dS(NsFsorry don't know how to handle non standard baud rate on this platform(R(RR((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR{stdarwint.cCsPddl}ddl}|jd|g�}d}|j|j||d�dS(Ni����RIT�i(RtfcntlRR(RRRRRtIOSSIOSPEED((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�scCstd��dS(Nsbaud rate not supported(R(RR((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�scCsd|S(Ns/dev/cuad%d((R((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�stnetbsdcCsd|S(Ns/dev/dty%02d((R((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�scCstd��dS(NsFsorry don't know how to handle non standard baud rate on this platform(R(RR((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�stirixcCsd|dS(Ns/dev/ttyf%di((R((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�scCstd��dS(NsFsorry don't know how to handle non standard baud rate on this platform(R(RR((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�sthpcCsd|dS(Ns/dev/tty%dp0i((R((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�scCstd��dS(NsFsorry don't know how to handle non standard baud rate on this platform(R(RR((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�stsunoscCsdtd�|S(Ns
/dev/tty%cta(tord(R((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�scCstd��dS(NsFsorry don't know how to handle non standard baud rate on this platform(R(RR((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�staixcCsd|S(Ns
/dev/tty%d((R((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�scCstd��dS(NsFsorry don't know how to handle non standard baud rate on this platform(R(RR((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�ss�don'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...
cCsdtS(Ns/dev/ttyS%d(tportnum(tportum((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�scCstd��dS(NsFsorry don't know how to handle non standard baud rate on this platform(tSerialException(RR((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�stTIOCMGETiTtTIOCMBISiTtTIOCMBICiTtTIOCMSETiTt TIOCM_DTRt TIOCM_RTSt TIOCM_CTSi t TIOCM_CARi@t TIOCM_RNGi�t TIOCM_DSRitTIOCM_CDtTIOCM_RItFIONREADiTtItTIOCSBRKi'TtTIOCCBRKi(TtPosixSerialcBs�eZdZd�Zd�Zd�Zd�Zd�Zdd�Zd�Z d �Z
d
�Zd�Zdd
�Z
dd�Zdd�Zdd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZRS(s�Serial port class POSIX implementation. Serial port configuration is
done with termios and fcntl. Runs on Linux and many other Un*x like
systems.cCs�|jdkrtd��n|jr6td��nd|_y-tj|jtjtj Btj
B�|_Wn5tk
r�}d|_td|j|f��nXy|j�Wn1ytj
|j�WnnXd|_�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.sPort is already open.scould not open port %s: %sN(t_porttNoneR&t_isOpenRtostopentportstrtO_RDWRtO_NOCTTYt
O_NONBLOCKt Exceptiont_reconfigurePorttclosetTrue(tselftmsg((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR< s( - cCs�|jdkrtd��nd}d}}|jdk rYd}t|jd�}ny1tj|j�}|\}}}}} }
}Wn&tjk
r�}td|��nX|tj tj
BO}|tjtjBtj
BtjBtjBtjBtjBM}x4dD],}
tt|
�r|tt|
�M}qqW|tjM}|tjtjBtjBtjBM}ttd�r�|tjM}nttd �r�|tjM}nyttd
|j�} }
Wn�tk
rpyt|j} }
Wqqtk
rlttd�} }
yt|j�}Wn$tk
rFtd|j��qmX|dkrmtd|j��qmqqXnX|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)krM|tj(O}n2|j&t*krl|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-��ttd�ro|j3rP|tj4tj5BO}q�|tj4tj5Btj6BM}n5|j3r�|tj4tj5BO}n|tj4tj5BM}ttd�r�|j7r�|tj8O}q|tj8M}n9ttd�r|j7r|tj9O}q|tj9M}n|dks.|dkrAtd|��n||tj:<|dksf|dkrytd|��n||tj;<||||| |
|g|kr�tj<|jtj=||||| |
|g�n|dk r�t>||�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_RTSCTSi�sInvalid vmin: %r sInvalid vtime: %rN(RGRH(?RR9R&t_interCharTimeouttintttermiost tcgetattrterrorR tCLOCALtCREADtICANONtECHOtECHOEtECHOKtECHONLtISIGtIEXTENthasattrtgetattrtOPOSTtINLCRtIGNCRtICRNLtIGNBRKRIRJt _baudratetAttributeErrortbaudrate_constantstKeyErrorRtCSIZEt _bytesizetCS8tCS7tCS6tCS5t _stopbitstSTOPBITS_ONEtCSTOPBtSTOPBITS_ONE_POINT_FIVEtSTOPBITS_TWOtINPCKtISTRIPt_paritytPARITY_NONEtPARENBtPARODDtPARITY_EVENt
PARITY_ODDt_xonxofftIXONtIXOFFRLt_rtsctsRMRNtVMINtVTIMEt tcsetattrtTCSANOWR(REtcustom_baudtvmintvtimet orig_attrtiflagtoflagtcflagtlflagtispeedtospeedtccRFtflag((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyRB)s�
5
#
!1cCsD|jr@|jdk r4tj|j�d|_nt|_ndS(s
Close portN(R:RR9R;RCtFalse(RE((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyRC�s
cCs
t|�S(N(R(RER((s6/usr/lib/python2.7/site-packages/serial/serialposix.pytmakeDeviceName�scCs,tj|jtt�}tjd|�dS(s>Return the number of characters currently in the input buffer.R4i(RRRtTIOCINQtTIOCM_zero_strtstructtunpack(REts((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyt inWaiting�sicCs�|jst�nt�}x�t|�|kr�tj|jggg|j�\}}}|sdPntj|j|t|��}|s�t d��n|j
|�qWt|�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.sLdevice reports readiness to read but returned no data (device disconnected?)(R:tportNotOpenErrort bytearraytlentselectRt_timeoutR;treadR&textendtbytes(REtsizeR�treadyt_R((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR��s *c
CsJ|jst�nt|�}|}|jdk rX|jdkrXtj�|j}nd}x�|dkr?y�tj|j|�}|r�|tj�}|dkr�t �nt
j
g|jgg|�\}}}|s�t �q�n||}||}Wqatk
r;} | jtj
kr<td| f��q<qaXqaWt|�S(s-Output the given string over the serial port.iswrite failed: %sN(R:R�R�t
_writeTimeoutR9ttimeR;twriteRtwriteTimeoutErrorR�tOSErrorterrnotEAGAINR&(
REtdatatttdttimeouttnttimeleftR�R�tv((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR��s. '
cCs|j�dS(sTFlush of file like objects. In this case, wait until all data
is written.N(tdrainOutput(RE((s6/usr/lib/python2.7/site-packages/serial/serialposix.pytflush�scCs,|jst�ntj|jtj�dS(s9Clear input buffer, discarding all that is in the buffer.N(R:R�RQttcflushRR tTCIFLUSH(RE((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyt
flushInput�s cCs,|jst�ntj|jtj�dS(sbClear output buffer, aborting the current output and
discarding all that is in the buffer.N(R:R�RQR�RR tTCOFLUSH(RE((s6/usr/lib/python2.7/site-packages/serial/serialposix.pytflushOutput�s g�?cCs3|jst�ntj|jt|d��dS(sHSend break condition. Timed, returns to idle state after given duration.g�?N(R:R�RQttcsendbreakRRP(REtduration((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyt sendBreak�s cCsK|jdkrt�n|r4tj|jt�ntj|jt�dS(sBSet break: Controls TXD. When active, no transmitting is possible.N(RR9R�RRR5R6(REtlevel((s6/usr/lib/python2.7/site-packages/serial/serialposix.pytsetBreaks
cCsK|jst�n|r1tj|jtt�ntj|jtt�dS(s)Set terminal status line: Request To SendN(R:R�RRRR(t
TIOCM_RTS_strR)(RER�((s6/usr/lib/python2.7/site-packages/serial/serialposix.pytsetRTS s
cCsK|jst�n|r1tj|jtt�ntj|jtt�dS(s-Set terminal status line: Data Terminal ReadyN(R:R�RRRR(t
TIOCM_DTR_strR)(RER�((s6/usr/lib/python2.7/site-packages/serial/serialposix.pytsetDTRs
cCsH|jst�ntj|jtt�}tjd|�dt @dkS(s(Read terminal status line: Clear To SendR4i(
R:R�RRRR'R�R�R�R-(RER�((s6/usr/lib/python2.7/site-packages/serial/serialposix.pytgetCTSs cCsH|jst�ntj|jtt�}tjd|�dt @dkS(s)Read terminal status line: Data Set ReadyR4i(
R:R�RRRR'R�R�R�R0(RER�((s6/usr/lib/python2.7/site-packages/serial/serialposix.pytgetDSRs cCsH|jst�ntj|jtt�}tjd|�dt @dkS(s)Read terminal status line: Ring IndicatorR4i(
R:R�RRRR'R�R�R�R2(RER�((s6/usr/lib/python2.7/site-packages/serial/serialposix.pytgetRI%s cCsH|jst�ntj|jtt�}tjd|�dt @dkS(s)Read terminal status line: Carrier DetectR4i(
R:R�RRRR'R�R�R�R1(RER�((s6/usr/lib/python2.7/site-packages/serial/serialposix.pytgetCD+s cCs&|jst�ntj|j�dS(sinternal - not portable!N(R:R�RQttcdrainR(RE((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�3s cCs2|jst�ntj|jtjtj�dS(sinternal - not portable!N(R:R�RRRtF_SETFLR;R@(RE((s6/usr/lib/python2.7/site-packages/serial/serialposix.pytnonblocking8s cCs|jst�n|jS(s�For easier use of the serial port instance with select.
WARNING: this function is not portable to different platforms!(R:R�R(RE((s6/usr/lib/python2.7/site-packages/serial/serialposix.pytfileno=s cCsK|jst�n|r1tj|jtj�ntj|jtj�dS(sQmanually control flow - when hardware or software flow control is
enabledN(R:R�RQttcflowRR tTCIONtTCIOFF(REtenable((s6/usr/lib/python2.7/site-packages/serial/serialposix.pytflowControlCs
(t__name__t
__module__t__doc__R<RBRCR�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�(((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR7s. z tSerialcBseZRS((R�R�(((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�TscBseZRS((R�R�(((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�XstPosixPollSerialcBseZdZdd�ZRS(s�poll 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|jdkrt�nt�}tj�}|j|jtjtjBtj Btj
B�|dkrDx�t|�|kr@xN|j|jd�D]6\}}|tjtj Btj
B@r�t
d��q�q�Wtj|j|t|��}|j|�|jdk r|jdks2|jdk rg|jdkrg|rgPqgqgWnt|�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.ii�sdevice reports error (poll)N(RR9R�R�R�tpolltregistertPOLLINtPOLLERRtPOLLHUPtPOLLNVALR�R�R&R;R�R�ROR�(RER�R�R�RteventR((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�`s +#
%(R�R�R�R�(((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyR�[st__main__RtbytesizetparitytstopbitsR�txonxofftrtsctsthellos%r
s%s
(EtsysR;RRQR�R�R�R�tserial.serialutilt
hexversionR RtplatformtlowertplatRRRRRftunametsplittversionRPtstderrR�tnametVERSIONR]R'R(R)R*R+R,R-R.R/R0R1R2R3R�tpackR�R�R�R5R6t
SerialBaseR7tiotImportErrortFileLikeR�t RawIOBaseR�R�t EIGHTBITSRyRoR�R�R�R�R�tstdoutR�R�(((s6/usr/lib/python2.7/site-packages/serial/serialposix.pyt<module>s`
�M
|