+
    ^g$                        R t ^ RIHt ^ RIt^ RIt ! R R]4      t ! R R]4      t ! R R]4      t ! R	 R
]4      t	 ! R R]P                  4      t]R8X  d   ^ RIt^ RIt^ RItRt ! R R]	4      t]P$                  ! ]R^R7      t]! ]]4      ;_uu_ 4       t]P+                  R4       ]P,                  ! ^4       RRR4       ]P$                  ! ]R^R7      t]! ]]4      t]P1                  4        ]P3                  4       w  tt]P+                  R4       ]P,                  ! ^4       ]P7                  4        R# R#   + '       g   i     L; i)z%Support threading with serial ports.
)absolute_importNc                   6   a  ] tR t^t o RtR tR tR tRtV t	R# )ProtocolzeProtocol as used by the ReaderThread. This base class provides empty
implementations of all methods.
c                    R# )z$Called when reader thread is startedN self	transports   &&:/usr/lib/python3/dist-packages/serial/threaded/__init__.pyconnection_madeProtocol.connection_made           c                    R# )z2Called with snippets received from the serial portNr   r   datas   &&r
   data_receivedProtocol.data_received   r   r   c                6    \        V\        4      '       d   VhR# )zOCalled when the serial port is closed or the reader loop terminated
otherwise.
N)
isinstance	Exceptionr   excs   &&r
   connection_lostProtocol.connection_lost   s    
 c9%%I &r   r   N)
__name__
__module____qualname____firstlineno____doc__r   r   r   __static_attributes____classdictcell____classdict__s   @r
   r   r      s     
3A r   r   c                   R   a a ] tR t^'t oRtRtR tR tV 3R ltR t	R t
RtVtV ;t# )	
Packetizerz
Read binary packets from serial port. Packets are expected to be terminated
with a TERMINATOR byte (null byte by default).

The class also keeps track of the transport.
    c                2    \        4       V n        R V n        R # N)	bytearraybufferr	   r   s   &r
   __init__Packetizer.__init__1   s    kr   c                    Wn         R# zStore transportNr	   r   s   &&r
   r   Packetizer.connection_made5       "r   c                <   < RV n         \        \        V `  V4       R# )Forget transportN)r	   superr%   r   r   r   	__class__s   &&r
   r   Packetizer.connection_lost9   s    j$/4r   c                    V P                   P                  V4       V P                  V P                   9   dA   V P                   P                  V P                  ^4      w  q n         V P	                  V4       K[  R# )z9Buffer received data, find TERMINATOR, call handle_packetN)r*   extend
TERMINATORsplithandle_packet)r   r   packets   && r
   r   Packetizer.data_received>   sV    4 oo,"&++"3"3DOOQ"GFKv& -r   c                    \        R4      hz1Process packets - to be overridden by subclassingz/please implement functionality in handle_packetNotImplementedErrorr   r>   s   &&r
   r=   Packetizer.handle_packetE       !"STTr   )r*   r	   )r   r   r   r   r   r;   r,   r   r   r   r=   r    r!   __classcell__r7   r#   s   @@r
   r%   r%   '   s1      J#5
'U Ur   r%   c                   \   a a ] tR t^Jt oRtRtRtR tR tV 3R lt	R t
R tR	 tR
tVtV ;t# )FramedPacketzz
Read binary packets. Packets are expected to have a start and stop marker.

The class also keeps track of the transport.
   (   )c                @    \        4       V n        R V n        RV n        R# )FN)r)   r>   	in_packetr	   r+   s   &r
   r,   FramedPacket.__init__T   s    kr   c                    Wn         R# r/   r0   r   s   &&r
   r   FramedPacket.connection_madeY   r2   r   c                d   < RV n         RV n        V P                  R \        \        V `  V4       R# )r4   NFNNN)r	   rN   r>   r5   rJ   r   r6   s   &&r
   r   FramedPacket.connection_lost]   s+    KKNlD1#6r   c                   \         P                  ! V4       F  pW P                  8X  d
   RV n        K  W P                  8X  d;   RV n        V P                  \        V P                  4      4       V P                  R Kf  V P                  '       d   V P                  P                  V4       K  V P                  V4       K  	  R# )z4Find data enclosed in START/STOP, call handle_packetTFrS   N)
serial	iterbytesSTARTrN   STOPr=   bytesr>   r:   handle_out_of_packet_data)r   r   bytes   && r
   r   FramedPacket.data_receivedd   s    $$T*Dzz!!%"!&""5#56KKN""4(..t4 +r   c                    \        R4      hrA   rB   rD   s   &&r
   r=   FramedPacket.handle_packetr   rF   r   c                    R# )z0Process data that is received outside of packetsNr   r   s   &&r
   r[   &FramedPacket.handle_out_of_packet_datav   s    r   )rN   r>   r	   )r   r   r   r   r   rX   rY   r,   r   r   r   r=   r[   r    r!   rG   rH   s   @@r
   rJ   rJ   J   s:      ED
#75U r   rJ   c                   B   a  ] tR t^{t o RtRtRtRtR tR t	R t
RtV tR	# )

LineReaderzN
Read and write (Unicode) lines from/to serial port.
The encoding is applied.
s   
zutf-8replacec                p    V P                  VP                  V P                  V P                  4      4       R # r(   )handle_linedecodeENCODINGUNICODE_HANDLINGrD   s   &&r
   r=   LineReader.handle_packet   s%    t}}d6K6KLMr   c                    \        R4      h)z2Process one line - to be overridden by subclassingz-please implement functionality in handle_linerB   )r   lines   &&r
   rf   LineReader.handle_line   s    !"QRRr   c                    V P                   P                  VP                  V P                  V P                  4      V P
                  ,           4       R# )z
Write text to the transport. ``text`` is a Unicode string and the encoding
is applied before sending ans also the newline is append.
N)r	   writeencoderh   ri   r;   )r   texts   &&r
   
write_lineLineReader.write_line   s7     	T[[8M8MNQUQ`Q``ar   r   N)r   r   r   r   r   r;   rh   ri   r=   rf   rr   r    r!   r"   s   @r
   rc   rc   {   s4     
 JH NSb br   rc   c                   `   a a ] tR t^t oRtV 3R ltR tR tR tR t	R t
R tR	 tR
tVtV ;t# )ReaderThreada  Implement a serial port read loop and dispatch to a Protocol instance (like
the asyncio.Protocol) but do it with threads.

Calls to close() will close the serial port but it is also possible to just
stop() this thread and continue the serial port instance otherwise.
c                   < \         \        V `  4        RV n        Wn        W n        RV n        \        P                  ! 4       V n	        \        P                  ! 4       V n        RV n        R# )zqInitialize thread.

Note that the serial_instance' timeout is set to one second!
Other settings are not changed.
TN)r5   ru   r,   daemonrV   protocol_factoryalive	threadingLock_lockEvent_connection_madeprotocol)r   serial_instancerx   r7   s   &&&r
   r,   ReaderThread.__init__   sO     	lD*,% 0
^^%
 ) 1r   c                    RV n         \        V P                  R4      '       d   V P                  P                  4        V P	                  ^4       R# )zStop the reader threadFcancel_readN)ry   hasattrrV   r   joinr+   s   &r
   stopReaderThread.stop   s5    
4;;..KK##%		!r   c                   \        V P                  R4      '       g   ^V P                  n        V P                  4       V n         V P                  P                  V 4       RpT P                  P                  4        T P                  '       d   T P                  P                  '       dc    T P                  P                  T P                  P                  ;'       g    ^4      pT'       d    T P                  P                  T4       K  K  RT n        T P                  P                  T4       RT n        R#   \         dH   pRT n        T P                  P                  T4       T P                  P                  4         Rp?R# Rp?ii ; i  \         d   pTp Rp?K  Rp?ii ; i  \        P                   d   pTp Rp?K  Rp?ii ; i)zReader loopr   FN)r   rV   timeoutrx   r   r   r   ry   r   r~   setis_openread
in_waitingr   SerialException)r   eerrorr   s   &   r
   runReaderThread.run   s_   t{{M22"#DKK--/	MM))$/ !!#jjjT[[000{{''(>(>(C(C!D 33D9  
%%e,5  	DJMM))!,!!%%'		* %  ! ))  	sN   D6 *1F& F& ,F 6F<FFF#FF#&G;GGc                    V P                   ;_uu_ 4        V P                  P                  V4      uuRRR4       #   + '       g   i     R# ; i)zThread safe writing (uses lock)N)r|   rV   ro   r   s   &&r
   ro   ReaderThread.write   s)    ZZZ;;$$T* ZZZs	   ;A	c                    V P                   ;_uu_ 4        V P                  4        V P                  P                  4        RRR4       R#   + '       g   i     R# ; i)z8Close the serial port and exit reader thread (uses lock)N)r|   r   rV   closer+   s   &r
   r   ReaderThread.close   s2     ZZZIIKKK ZZZs   +A

A	c                    V P                   '       dE   V P                  P                  4        V P                   '       g   \        R4      hW P                  3# \        R4      h)zR
Wait until connection is set up and return the transport and protocol
instances.
connection_lost already calledzalready stopped)ry   r~   waitRuntimeErrorr   r+   s   &r
   connectReaderThread.connect   sM    
 :::!!&&(:::"#CDD--((011r   c                    V P                  4        V P                  P                  4        V P                  '       g   \	        R4      hV P
                  # )z[Enter context handler. May raise RuntimeError in case the connection
could not be created.
r   )startr~   r   ry   r   r   r+   s   &r
   	__enter__ReaderThread.__enter__   s>    
 	

""$zzz?@@}}r   c                &    V P                  4        R# )zLeave context: close portN)r   )r   exc_typeexc_valexc_tbs   &&&&r
   __exit__ReaderThread.__exit__   s    

r   )r~   r|   ry   rw   r   rx   rV   )r   r   r   r   r   r,   r   r   ro   r   r   r   r   r    r!   rG   rH   s   @@r
   ru   ru      s8      !F+
 2	 r   ru   __main__zloop://c                   >   a a ] tR tRt oV 3R ltR tR tRtVtV ;t	# )
PrintLinesi  c                   < \         \        V `  V4       \        P                  P                  R 4       V P                  R4       R# )zport opened
zhello worldN)r5   r   r   sysstdoutro   rr   )r   r	   r7   s   &&r
   r   PrintLines.connection_made  s0    *d3I>JJ_-OOM*r   c                b    \         P                  P                  R P                  V4      4       R# )zline received: {!r}
N)r   r   ro   formatr   s   &&r
   rf   PrintLines.handle_line  s     JJ4;;DABr   c                    V'       d   \         P                  ! V4       \        P                  P	                  R 4       R# )zport closed
N)	traceback	print_excr   r   ro   r   s   &&r
   r   PrintLines.connection_lost  s%    ##C(JJ_-r   r   )
r   r   r   r   r   rf   r   r    r!   rG   rH   s   @@r
   r   r     s     	+
	C	. 	.r   r   i  )baudrater   hello)r   
__future__r   rV   rz   objectr   r%   rJ   rc   Threadru   r   r   timer   PORTr   serial_for_urlserr   rr   sleeptr   r   r	   r   r   r   r
   <module>r      s5   '  v * U  UF.8 .bb b4l9## lb z D.Z . 

vq
AC	c:	&	&(G$

1 
'
 

vq
ACS*%AGGI))+Ix JJqMGGIG 0 
'	&s   $D<<E	