{QNc@s1ddlZddlmZddlTdZdefdYZyddlZWn*ek rdee fdYZ nXdeej fd YZ e d kr-e d Z ejjd e e Z ejjd e d e _de _e jd e _e jejjd e ndS(iN(twin32(t*cCs d|dS(s%Turn a port number into a device namesCOM%di((tportnum((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pytdevicest Win32SerialcBs eZdZd-ZdZdZdZdZdZdZ ddZ dZ dZ dZ ddZddZdd Zdd!Zd"Zd#Zd$Zd%Zd&Zed'Zd(Zd)Zd*Zeeed+d,ZRS(.s5Serial port implementation for Win32 based on ctypes.i2iKiniiii,iXiii` ii%iKiiicOs)d|_t|_tj|||dS(N(tNonethComPorttFalset _rtsTogglet SerialBaset__init__(tselftargstkwargs((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pyR s  c Cs|jd krtdn|jr6tdn|j}y<|jjdrzt|ddkrzd|}nWntk rnXt j |t j t j Bdd t j t jt jBd|_|jt jkrd |_td|jtjfnt j|jd d t j|_t j|jtj|jt j|_t j|_|jt j|jt jt j Bt j!Bt j"Bt j#|_$t j%d d dd |j$_&t j#|_'t j%d ddd |j'_&t(|_d S( 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.tCOMiis\\.\iscould not open port %s: %siiN()t_portRtSerialExceptiont_isOpentportstrtuppert startswithtintt ValueErrorRt CreateFilet GENERIC_READt GENERIC_WRITEt OPEN_EXISTINGtFILE_ATTRIBUTE_NORMALtFILE_FLAG_OVERLAPPEDRtINVALID_HANDLE_VALUEtctypestWinErrort SetupCommt COMMTIMEOUTSt _orgTimeoutstGetCommTimeoutstbyreftRTS_CONTROL_ENABLEt _rtsStatetDTR_CONTROL_ENABLEt _dtrStatet_reconfigurePortt PurgeCommt PURGE_TXCLEARt PURGE_TXABORTt PURGE_RXCLEARt PURGE_RXABORTt OVERLAPPEDt_overlappedReadt CreateEventthEventt_overlappedWritetTrue(R tport((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pytopen!sB  +      "    cCs^|jstdn|jdkr0d}nL|jdkrZtjddddf}n"ddt|jdddf}|jdkr|jdk rt|jdf|d}n|jdkrnJ|jdkr|d dtjf}n!|d dt|jdf}tj |jt j tj |tj |jtjtj}tj|jt j ||j|_|jtkrd|_nd|jtkrd|_nI|jtkrd|_n.|jtkrd |_ntd |j|jtkr,tj|_d|_n|jtkrStj |_d|_n|jt!krztj"|_d|_na|jt#krtj$|_d|_n:|jt%krtj&|_d|_ntd |j|j't(krtj)|_*nO|j't+krtj,|_*n1|j't-kr5tj.|_*ntd |j'd|_/|j0ritj1|_2n$|j3rtj4|_2n |j5|_2|j6rtj7|_8n |j9|_8|j3rd|_:n |j0|_:|j6|_;|j<|_=|j<|_>d|_?d|_@d|_AtB|_CtD|_EtjF|jt j |sZtd t jGndS(s,Set communication parameters on opened port.s'Can only operate on a valid port handleiiiiiiiis#Unsupported number of data bits: %rsUnsupported parity mode: %rs#Unsupported number of stop bits: %rsCCannot configure port, some setting was wrong. Original message: %sN(iiiii(HRRt_timeoutRRtMAXDWORDRt_interCharTimeoutt _writeTimeouttSetCommTimeoutsRR$R!t SetCommMasktEV_ERRtDCBt GetCommStatet _baudratetBaudRatet _bytesizetFIVEBITStByteSizetSIXBITSt SEVENBITSt EIGHTBITSRt_parityt PARITY_NONEtNOPARITYtParitytfParityt PARITY_EVENt EVENPARITYt PARITY_ODDt ODDPARITYt PARITY_MARKt MARKPARITYt PARITY_SPACEt SPACEPARITYt _stopbitst STOPBITS_ONEt ONESTOPBITtStopBitstSTOPBITS_ONE_POINT_FIVEt ONE5STOPBITSt STOPBITS_TWOt TWOSTOPBITStfBinaryt_rtsctstRTS_CONTROL_HANDSHAKEt fRtsControlRtRTS_CONTROL_TOGGLER&t_dsrdtrtDTR_CONTROL_HANDSHAKEt fDtrControlR(t fOutxCtsFlowt fOutxDsrFlowt_xonxofftfOutXtfInXtfNullt fErrorChart fAbortOnErrortXONtXonChartXOFFtXoffChart SetCommStateR(R ttimeoutstcomDCB((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pyR)Vs  "!!%                                 cCsz|jrv|jrjtj|j|jtj|jtj|jjtj|jjd|_nt |_ndS(s Close portN( RRRR;R"t CloseHandleR0R2R3RR(R ((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pytcloses   cCs t|S(N(R(R R5((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pytmakeDeviceNamescCsXtj}tj}tj|jtj|tj|sQtdn|jS(s>Return the number of characters currently in the input buffer.scall to ClearCommError failed( RtDWORDtCOMSTATtClearCommErrorRRR$RtcbInQue(R tflagstcomstat((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pyt inWaitings   *ic CsE|jstn|dkr2tj|jjtj}tj}tj|jt j |t j |st dn|j dkrlt |j|}|dkr`t j|}tj}tj|j||t j |t j |j}| r2tjtjkr2t dt jntj|jjtj}|j|j }q/t}q;t j|}tj}tj|j||t j |t j |j}| rtjtjkrt dt jntj|jt j |jt j |t}|j|j }n t}t|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.iscall to ClearCommError failedsReadFile failed (%s)(RtportNotOpenErrorRt ResetEventR0R2RwRxRyRR$RttimeouttminRztcreate_string_buffertReadFilet GetLastErrortERROR_IO_PENDINGRtWaitForSingleObjecttINFINITEtrawtvaluetbytestGetOverlappedResultR4( R tsizeR{R|tntbuftrcterrtread((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pyRs8    *  3  30 cCs|jstnt|}|rtj}tj|j|t|tj||j }| rtj tj krt dtj n|jdkrtj|j|j tj|t}|jt|krtqn|jSdSdS(s-Output the given string over the serial port.sWriteFile failed (%s)iN(RR~RRRwt WriteFiletlenRR$R3RRRRR:RR4RtwriteTimeoutError(R tdataRR((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pytwrites   0' cCs3|jstntj|jtjtjBdS(s9Clear input buffer, discarding all that is in the buffer.N(RR~RR*R-R.(R ((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pyt flushInputs cCs3|jstntj|jtjtjBdS(sbClear output buffer, aborting the current output and discarding all that is in the buffer.N(RR~RR*R+R,(R ((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pyt flushOutputs g?cCsO|jstnddl}tj|j|j|tj|jdS(sHSend break condition. Timed, returns to idle state after given duration.iN(RR~ttimeRt SetCommBreaktsleeptClearCommBreak(R tdurationR((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pyt sendBreaks    cCs?|jstn|r+tj|jntj|jdS(sBSet break: Controls TXD. When active, to transmitting is possible.N(RR~RRR(R tlevel((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pytsetBreak's  cCsc|jstn|r=tj|_tj|jtjn"tj|_tj|jtjdS(s)Set terminal status line: Request To SendN( RR~RR%R&tEscapeCommFunctiontSETRTStRTS_CONTROL_DISABLEtCLRRTS(R R((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pytsetRTS/s   cCsc|jstn|r=tj|_tj|jtjn"tj|_tj|jtjdS(s-Set terminal status line: Data Terminal ReadyN( RR~RR'R(RtSETDTRtDTR_CONTROL_DISABLEtCLRDTR(R R((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pytsetDTR9s   cCs/tj}tj|jtj||jS(N(RRwtGetCommModemStatusRRR$R(R tstat((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pyt_GetCommModemStatusCs cCs)|jstntj|j@dkS(s(Read terminal status line: Clear To Sendi(RR~Rt MS_CTS_ONR(R ((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pytgetCTSHs cCs)|jstntj|j@dkS(s)Read terminal status line: Data Set Readyi(RR~Rt MS_DSR_ONR(R ((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pytgetDSRMs cCs)|jstntj|j@dkS(s)Read terminal status line: Ring Indicatori(RR~Rt MS_RING_ONR(R ((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pytgetRIRs cCs)|jstntj|j@dkS(s)Read terminal status line: Carrier Detecti(RR~Rt MS_RLSD_ONR(R ((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pytgetCDWs cCsK|jstn|r1tj|jtjntj|jtjdS(s#Platform specific - set flow state.N(RR~RRtSETXONtSETXOFF(R R((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pytsetXON^s  cCsXtj}tj}tj|jtj|tj|sQtdn|jS(s5return how many characters the in the outgoing bufferscall to ClearCommError failed( RRwRxRyRRR$RtcbOutQue(R R{R|((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pyt outWaitingfs   *cCs#||_|jr|jndS(s"Change RTS toggle control setting.N(RRR)(R t rtsToggle((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pyt setRtsToggleos  cCs|jS(s+Get the current RTS toggle control setting.(R(R ((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pyt getRtsToggletstdocsRTS toggle control setting(i2iKiniiii,iXiii` ii%iKiii(t__name__t __module__t__doc__t BAUDRATESR R6R)RuRvR}RRRRRRRRRRRRRR4RRRRtpropertyR(((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pyRs6  5 i   #             tSerialcBseZRS((RR(((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pyRscBseZRS((RR(((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pyRst__main__is%s iKi(RtserialRtserial.serialutilRR Rtiot ImportErrortFileLikeRt RawIOBaseRtstsyststdoutRtbaudratetdatabitsRuR5R6(((s6/usr/lib/python2.7/site-packages/serial/serialwin32.pyt s*   i