+
    +a_<O                     h    ^ RI Ht ^ RIt^ RIt^ RIHt ^ RIt^ RIHtHtH	t	H
t
Ht  ! R R]4      tR# )    )absolute_importN)win32)
SerialBaseSerialExceptionto_bytesPortNotOpenErrorSerialTimeoutExceptionc                   J  a a ] tR t^t oRtRtV 3R ltR tR tR t	R t
]R 4       tRR ltR	 tR
 tR tR tR tR tR tR t]R 4       t]R 4       t]R 4       t]R 4       tRR ltR R lt]R 4       tR tR tR t] PB                  PD                  R 4       t!Rt#Vt$V ;t%# )!Serialz5Serial port implementation for Win32 based on ctypes.c                Z   < R V n         R V n        R V n        \        \        V `  ! V/ VB  R # N)_port_handle_overlapped_read_overlapped_writesuperr   __init__)selfargskwargs	__class__s   &*,4/usr/lib/python3/dist-packages/serial/serialwin32.pyr   Serial.__init__   s/      $!%fd$d5f5    c           	     B   V P                   f   \        R4      hV P                  '       d   \        R4      hV P                  p VP	                  4       P                  R4      '       d!   \        VR,          4      ^8  d
   RV,           p\        P                  ! T\        P                  \        P                  ,          ^ R\        P                  \        P                  \        P                  ,          ^ 4      T n        T P                  \        P                   8X  d@   RT n        \        RP#                  T P$                  \&        P(                  ! 4       4      4      h \        P*                  ! 4       T n        \        P.                  ! R^^ R4      T P,                  n        \        P*                  ! 4       T n        \        P.                  ! R^ ^ R4      T P2                  n        \        P4                  ! T P                  RR4       \        P6                  ! 4       T n        \        P:                  ! T P                  \&        P<                  ! T P8                  4      4       T P?                  4        \        P@                  ! T P                  \        PB                  \        PD                  ,          \        PF                  ,          \        PH                  ,          4       R	T n        R#   \         d     ELhi ; i    T PK                  4        RT n        h     RT n        h ; i; i)
z`Open port with current settings. This may throw a SerialException
if the port cannot be opened.
Nz.Port must be configured before it can be used.zPort is already open.COM:   NNz\\.\zcould not open port {!r}: {!r}   T)&_portr   is_opennameupper
startswithint
ValueErrorr   
CreateFileGENERIC_READGENERIC_WRITEOPEN_EXISTINGFILE_ATTRIBUTE_NORMALFILE_FLAG_OVERLAPPEDr   INVALID_HANDLE_VALUEformatportstrctypesWinError
OVERLAPPEDr   CreateEventhEventr   	SetupCommCOMMTIMEOUTS_orgTimeoutsGetCommTimeoutsbyref_reconfigure_port	PurgeCommPURGE_TXCLEARPURGE_TXABORTPURGE_RXCLEARPURGE_RXABORT_close)r   ports   & r   openSerial.open#   sd   
 ::!"RSS<<<!"9:: yy	zz|&&u--#d2h-!2C 4' ",,!4!44''%*D*DD  : :: $D!"B"I"I$,,X^XgXgXi"jkk 	 $)$4$4$6D!+0+<+<T1a+ND!!(%*%5%5%7D",1,=,=dAq$,OD"") OOD--tT: !& 2 2 4D!!$"3"3V\\$BSBS5TU""$ OO!!##e&9&99##$&+&9&9:;  DL_  		J	
 !%D  $Ds=   $K# ) K# E=K5 #K21K25L8LLLLc                4   V P                   '       g   \        R4      h\        P                  ! 4       pV P                  f   MRV P                  ^ 8X  d   \        P
                  Vn        M+\        \        V P                  R,          4      ^4      Vn	        V P                  ^ 8w  d:   V P                  e,   \        \        V P                  R,          4      ^4      Vn        V P                  f   MRV P                  ^ 8X  d   \        P
                  Vn        M+\        \        V P                  R,          4      ^4      Vn        \        P                  ! V P                   \        P                  ! V4      4       \        P                   ! V P                   \        P"                  4       \        P$                  ! 4       p\        P&                  ! V P                   \        P                  ! V4      4       V P(                  Vn        V P,                  \.        P0                  8X  d	   ^Vn        MV P,                  \.        P4                  8X  d	   ^Vn        MrV P,                  \.        P6                  8X  d	   ^Vn        MKV P,                  \.        P8                  8X  d	   ^Vn        M$\;        RP=                  V P,                  4      4      hV P>                  \.        P@                  8X  d   \        PB                  Vn"        ^ Vn#        EMV P>                  \.        PH                  8X  d   \        PJ                  Vn"        ^Vn#        MV P>                  \.        PL                  8X  d   \        PN                  Vn"        ^Vn#        MV P>                  \.        PP                  8X  d   \        PR                  Vn"        ^Vn#        M`V P>                  \.        PT                  8X  d   \        PV                  Vn"        ^Vn#        M$\;        RP=                  V P>                  4      4      hV PX                  \.        PZ                  8X  d   \        P\                  Vn/        MV PX                  \.        P`                  8X  d   \        Pb                  Vn/        MYV PX                  \.        Pd                  8X  d   \        Pf                  Vn/        M$\;        RP=                  V PX                  4      4      h^Vn4        V Pj                  fs   V Pl                  '       d   \        Pn                  Vn8        M7V Pr                  '       d   \        Pt                  M\        Pv                  Vn8        V Pl                  Vn<        EMV Pj                  Pz                  '       g/   \;        RP=                  V Pj                  Pz                  4      4      hV Pj                  P|                  '       d/   \;        RP=                  V Pj                  P|                  4      4      hV Pj                  P~                  e/   \;        R	P=                  V Pj                  P~                  4      4      hV Pj                  P                  e/   \;        R
P=                  V Pj                  P                  4      4      hV Pj                  P                  '       d/   \;        RP=                  V Pj                  P                  4      4      h\        P                  Vn8        ^ Vn<        V P                  '       d   \        P                  VnE        M7V P                  '       d   \        P                  M\        P                  VnE        V P                  VnI        V P                  VnK        V P                  VnL        ^ VnM        ^ VnN        ^ VnO        \.        P                  VnQ        \.        P                  VnS        \        P                  ! V P                   \        P                  ! V4      4      '       g.   \        RP=                  \        P                  ! 4       4      4      hR# )z,Set communication parameters on opened port.z'Can only operate on a valid port handleNi  z%Unsupported number of data bits: {!r}zUnsupported parity mode: {!r}z%Unsupported number of stop bits: {!r}zQUnsupported value for RS485Settings.rts_level_for_tx: {!r} (only True is allowed)zRUnsupported value for RS485Settings.rts_level_for_rx: {!r} (only False is allowed)zPUnsupported value for RS485Settings.delay_before_tx: {!r} (only None is allowed)zPUnsupported value for RS485Settings.delay_before_rx: {!r} (only None is allowed)zJUnsupported value for RS485Settings.loopback: {!r} (only False is allowed)zCCannot configure port, something went wrong. Original message: {!r})Vr   r   r   r4   _timeoutMAXDWORDReadIntervalTimeoutmaxr#   ReadTotalTimeoutConstant_inter_byte_timeout_write_timeoutWriteTotalTimeoutConstantSetCommTimeoutsr.   r7   SetCommMaskEV_ERRDCBGetCommState	_baudrateBaudRate	_bytesizeserialFIVEBITSByteSizeSIXBITS	SEVENBITS	EIGHTBITSr$   r,   _parityPARITY_NONENOPARITYParityfParityPARITY_EVEN
EVENPARITY
PARITY_ODD	ODDPARITYPARITY_MARK
MARKPARITYPARITY_SPACESPACEPARITY	_stopbitsSTOPBITS_ONE
ONESTOPBITStopBitsSTOPBITS_ONE_POINT_FIVEONE5STOPBITSSTOPBITS_TWOTWOSTOPBITSfBinary_rs485_mode_rtsctsRTS_CONTROL_HANDSHAKEfRtsControl
_rts_stateRTS_CONTROL_ENABLERTS_CONTROL_DISABLEfOutxCtsFlowrts_level_for_txrts_level_for_rxdelay_before_txdelay_before_rxloopbackRTS_CONTROL_TOGGLE_dsrdtrDTR_CONTROL_HANDSHAKEfDtrControl
_dtr_stateDTR_CONTROL_ENABLEDTR_CONTROL_DISABLEfOutxDsrFlow_xonxofffOutXfInXfNull
fErrorCharfAbortOnErrorXONXonCharXOFFXoffCharSetCommStater/   )r   timeoutscomDCBs   &  r   r8   Serial._reconfigure_portd   s      !"KLL %%'== ]]a+0>>H(03C8L4Mq0QH-==A$":":"F+.s43K3Kd3R/SUV+WH(&  A%16H.14S9L9Lt9S5TVW1XH.d//h1GH$++U\\: 4,,fll6.BC..>>V__,FO^^v~~-FO^^v///FO^^v///FODKKDNN[\\<<6---!NNFMFN\\V///!,,FMFN\\V...!OOFMFN\\V///!,,FMFN\\V000!--FMFN<CCDLLQRR>>V000#..FO^^v===#00FO^^v222#//FODKKDNN[\\#|||%*%@%@"AEU%=%=V[VoVo""&,,F ##444 gnn((99<= = 000 hoo((99<= = //; fmm((88;< < //; fmm((88;< < ((( `gg((1145 5 "'!9!9F"#F<<<!&!<!<F=A___!9!9RWRkRkF"ll}}mm  ++!!$"3"3V\\&5IJJ!))/0A)BD D Kr   c                   V P                   e   \        P                  ! V P                   V P                  4       V P                  eB   V P                  4        \        P                  ! V P                  P                  4       RV n        V P                  eB   V P                  4        \        P                  ! V P                  P                  4       RV n        \        P                  ! V P                   4       RV n         R# R# )zinternal close port helperN)
r   r   rK   r5   r   cancel_readCloseHandler2   r   cancel_writer   s   &r   r>   Serial._close   s    (!!$"3"3T5F5FG$$0  "!!$"7"7">">?(,%%%1!!#!!$"8"8"?"?@)-&d//0 $D )r   c                \    V P                   '       d   V P                  4        RV n         R# R# )z
Close portFN)r   r>   r   s   &r   closeSerial.close   s     <<<KKM DL r   c                h   \         P                  ! 4       p\         P                  ! 4       p\         P                  ! V P                  \
        P                  ! V4      \
        P                  ! V4      4      '       g.   \        RP                  \
        P                  ! 4       4      4      hVP                  # )z9Return the number of bytes currently in the input buffer.ClearCommError failed ({!r}))r   DWORDCOMSTATClearCommErrorr   r.   r7   r   r,   r/   cbInQuer   flagscomstats   &  r   
in_waitingSerial.in_waiting   sp     --/##D$5$5v||E7JFLLY`Labb!"@"G"GHY"Z[[r   c           	        V P                   '       g   \        4       hV^ 8  Ed   \        P                  ! V P                  P
                  4       \        P                  ! 4       p\        P                  ! 4       p\        P                  ! V P                  \        P                  ! V4      \        P                  ! V4      4      '       g.   \        RP                  \        P                  ! 4       4      4      hV P                  ^ 8X  d   \!        VP"                  V4      MTpV^ 8  Ed   \        P$                  ! V4      p\        P                  ! 4       p\        P&                  ! V P                  VV\        P                  ! V4      \        P                  ! V P                  4      4      pV'       gf   \        P(                  ! 4       \        P*                  \        P,                  39  d.   \        RP                  \        P                  ! 4       4      4      h\        P.                  ! V P                  \        P                  ! V P                  4      \        P                  ! V4      R4      pV'       gV   \        P(                  ! 4       \        P0                  8w  d.   \        RP                  \        P                  ! 4       4      4      hVP2                  RVP4                   p	M\7        4       p	M
\7        4       p	\7        V	4      # )zRead 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.
r   zReadFile failed ({!r})Tz!GetOverlappedResult failed ({!r})N)r   r   r   
ResetEventr   r2   r   r   r   r   r.   r7   r   r,   r/   timeoutminr   create_string_bufferReadFileGetLastErrorERROR_SUCCESSERROR_IO_PENDINGGetOverlappedResultERROR_OPERATION_ABORTEDrawvaluebytes)
r   sizer   r   nbufrcread_ok	result_okreads
   &&        r   r   Serial.read  s    |||"$$!8T2299:KKMEmmoG''(9(96<<;NPVP\P\]dPeff%&D&K&KFOOL]&^__.2lla.?GOOT*TA1u11!4[[]..%%LL$LL!6!679 5#5#5#7@S@SUZUkUk?l#l)*B*I*I&//J[*\]]!55%%LL!6!67LL$		
 !))+u/L/LL-.Q.X.XY_YhYhYj.kllwwy)w7DT{r   c                   V P                   '       g   \        4       h\        V4      pV'       EdF   \        P                  ! 4       p\        P
                  ! V P                  V\        V4      \        P                  ! V4      V P                  4      pV P                  ^ 8w  Ed   V'       gf   \        P                  ! 4       \        P                  \        P                  39  d.   \        RP!                  \        P"                  ! 4       4      4      h\        P$                  ! V P                  V P                  \        P                  ! V4      R4       \        P                  ! 4       \        P&                  8X  d   VP(                  # VP(                  \        V4      8w  d   \+        R4      hVP(                  # V'       d   \        P                  M\        P                  ! 4       pV\        P,                  \        P.                  \        P&                  39   d   ^ # V\        P                  \        P                  39   d   \        V4      # \        RP!                  \        P"                  ! 4       4      4      h^ # )z2Output the given byte string over the serial port.zWriteFile failed ({!r})TzWrite timeout)r   r   r   r   r   	WriteFiler   lenr.   r7   r   rI   r   r   r   r   r,   r/   r   r   r   r	   ERROR_INVALID_USER_BUFFERERROR_NOT_ENOUGH_MEMORY)r   datar   success	errorcodes   &&   r   writeSerial.write/  s   |||"$$ ~4Aood&7&7s4y&,,WX/[_[q[qrG""a'5#5#5#7@S@SUZUkUk?l#l)*C*J*J6??K\*]^^ ))$*;*;T=S=SU[UaUabcUdfjk%%'5+H+HH77N77c$i'0AAww3:E//@R@R@T	!@!@%B_B_!&!>!>!@ @5#6#68N8N"OOt9$)*C*J*J6??K\*]^^r   c                Z    V P                   '       d   \        P                  ! R4       K*  R# )zJFlush of file like objects. In this case, wait until all data
is written.
g?N)out_waitingtimesleepr   s   &r   flushSerial.flushT  s!    
 JJt r   c                    V P                   '       g   \        4       h\        P                  ! V P                  \        P
                  \        P                  ,          4       R# )z9Clear input buffer, discarding all that is in the buffer.N)r   r   r   r9   r   r<   r=   r   s   &r   reset_input_bufferSerial.reset_input_buffer_  s9    |||"$$))5+>+>ATAT+TUr   c                    V P                   '       g   \        4       h\        P                  ! V P                  \        P
                  \        P                  ,          4       R# )z[Clear output buffer, aborting the current output and discarding all
that is in the buffer.
N)r   r   r   r9   r   r:   r;   r   s   &r   reset_output_bufferSerial.reset_output_buffere  s;    
 |||"$$))5+>+>ATAT+TUr   c                    V P                   '       g   \        4       hV P                  '       d#   \        P                  ! V P
                  4       R# \        P                  ! V P
                  4       R# )zBSet break: Controls TXD. When active, to transmitting is possible.N)r   r   _break_stater   SetCommBreakr   ClearCommBreakr   s   &r   _update_break_stateSerial._update_break_staten  sH    |||"$$t001  !2!23r   c                    V P                   '       d2   \        P                  ! V P                  \        P                  4       R# \        P                  ! V P                  \        P
                  4       R# )z)Set terminal status line: Request To SendN)rs   r   EscapeCommFunctionr   SETRTSCLRRTSr   s   &r   _update_rts_stateSerial._update_rts_statew  ?    ???$$T%6%6E$$T%6%6Er   c                    V P                   '       d2   \        P                  ! V P                  \        P                  4       R# \        P                  ! V P                  \        P
                  4       R# )z-Set terminal status line: Data Terminal ReadyN)r   r   r   r   SETDTRCLRDTRr   s   &r   _update_dtr_stateSerial._update_dtr_state~  r   r   c                    V P                   '       g   \        4       h\        P                  ! 4       p\        P                  ! V P
                  \        P                  ! V4      4       VP                  # r   )	r   r   r   r   GetCommModemStatusr   r.   r7   r   )r   stats   & r   _GetCommModemStatusSerial._GetCommModemStatus  sH    |||"$${{}  !2!2FLL4FGzzr   c                R    \         P                  V P                  4       ,          ^ 8g  # )z(Read terminal status line: Clear To Send)r   	MS_CTS_ONr   r   s   &r   cts
Serial.cts  !     !9!9!;;q@@r   c                R    \         P                  V P                  4       ,          ^ 8g  # )z)Read terminal status line: Data Set Ready)r   	MS_DSR_ONr   r   s   &r   dsr
Serial.dsr  r   r   c                R    \         P                  V P                  4       ,          ^ 8g  # )z)Read terminal status line: Ring Indicator)r   
MS_RING_ONr   r   s   &r   ri	Serial.ri  #     $":":"<<AAr   c                R    \         P                  V P                  4       ,          ^ 8g  # )z)Read terminal status line: Carrier Detect)r   
MS_RLSD_ONr   r   s   &r   cd	Serial.cd  r   r   c                T    Vf   Tp\         P                  ! V P                  W4       R# )zvRecommend a buffer size to the driver (device driver can ignore this
value). Must be called after the port is opened.
N)r   r3   r   )r   rx_sizetx_sizes   &&&r   set_buffer_sizeSerial.set_buffer_size  s"    
 ?G))7<r   c                   V P                   '       g   \        4       hV'       d2   \        P                  ! V P                  \        P
                  4       R# \        P                  ! V P                  \        P                  4       R# )a  Manually control flow - when software flow control is enabled.
This will do the same as if XON (true) or XOFF (false) are received
from the other device and control the transmission accordingly.
WARNING: this function is not portable to different platforms!
N)r   r   r   r   r   SETXONSETXOFF)r   enables   &&r   set_output_flow_controlSerial.set_output_flow_control  sM     |||"$$$$T%6%6E$$T%6%6Fr   c                h   \         P                  ! 4       p\         P                  ! 4       p\         P                  ! V P                  \
        P                  ! V4      \
        P                  ! V4      4      '       g.   \        RP                  \
        P                  ! 4       4      4      hVP                  # )z0Return how many bytes the in the outgoing bufferr   )r   r   r   r   r   r.   r7   r   r,   r/   cbOutQuer   s   &  r   r   Serial.out_waiting  sr     --/##D$5$5v||E7JFLLY`Labb!"@"G"GHY"Z[[r   c                   \         P                  ! 4       p\         P                  ! V P                  \        P
                  ! V4      \        P
                  ! V4      R4      pV'       g^   \         P                  ! 4       \         P                  \         P                  39   d$   \         P                  ! V P                  V4       R# R# R# )ACancel a blocking read operation, may be called from other threadFN)
r   r   r   r   r.   r7   r   r   ERROR_IO_INCOMPLETE
CancelIoEx)r   
overlappedr   errs   &&  r   _cancel_overlapped_ioSerial._cancel_overlapped_io  s     [[]''LL$LL	
 u))+0F0FHaHa/bbT..
; csr   c                <    V P                  V P                  4       R# )r
  N)r  r   r   s   &r   r   Serial.cancel_read  s    ""4#8#89r   c                <    V P                  V P                  4       R# )zBCancel a blocking write operation, may be called from other threadN)r  r   r   s   &r   r   Serial.cancel_write  s    ""4#9#9:r   c                    Ve#   V'       g   \        RP                  V4      4      h\        P                  P                  P                  W4       R# )z$Change the exclusive access setting.Nz.win32 only supports exclusive access (not: {}))r$   r,   rS   r   	exclusive__set__)r   r  s   &&r   r  Serial.exclusive  s>      MTTU^_``''//@r   )r5   r   r   r   r   )2   K   n            i,  iX  i  i  i`	  i  i%  i K  i   i   i  )   )r   N)T)&__name__
__module____qualname____firstlineno____doc__	BAUDRATESr   r@   r8   r>   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r  r   r   r   r  setter__static_attributes____classdictcell____classcell__)r   __classdict__s   @@r   r   r      s!    ?4I6? B|DB% !  'R#JVV4FF A A A A B B B B=G    <:;   A !A Ar   r   )
__future__r   r.   r   rS   r   serial.serialutilr   r   r   r   r	   r    r   r   <module>r/     s.    '     m mFAZ FAr   