a_)ddlmZddlZddlZddlZ ddlZ ddl Z ddl m Z m Z mZmZmZmZej$ej&ej(ej*dZGdde Zedk(rddlZedZej6j9d j;eej6j9d ej9d ej=ej6j9d j;ej?d ejAyy#e$r ddlmZYwxYw#e$rddl Z Y*wxYw))absolute_importN) SerialBaseSerialExceptionto_bytes iterbytesSerialTimeoutExceptionPortNotOpenError)debuginfowarningerrorceZdZdZdZfdZdZfdZdZdZ e dZ dd Z d Z d Zd Zd ZdZe dZdZdZdZe dZe dZe dZe dZxZS)SerialzSSerial port implementation that simulates a loop back connection in plain software.)2Kni,iXiii` ii%iKiiicdd|_d|_d|_d|_t t ||i|y)NiF) buffer_sizequeuelogger _cancel_writesuperr__init__)selfargskwargs __class__s A/usr/lib/python3/dist-packages/serial/urlhandler/protocol_loop.pyrzSerial.__init__/s5  " fd$d5f5c|jr tdd|_tj|j |_|j td|j|j|jd|_|js|j|js|j|j|jy)zx Open port with current settings. This may throw a SerialException if the port cannot be opened. zPort is already open.Nz.Port must be configured before it can be used.T)is_openrrrQueuer_portfrom_urlport_reconfigure_port_dsrdtr_update_dtr_state_rtscts_update_rts_statereset_input_bufferreset_output_bufferrs r!openz Serial.open6s <<!"9: : [[!1!12 :: !"RS S dii    ||  " " $||  " " $ !   "r"c|jr#d|_ |jjdtt |y#tj$rY(wxYw)NF)r$r put_nowaitFullrrclose)rr s r!r5z Serial.closeQsO << DL  %%d+ fd!#::  sAAAct|jtjrd|jcxkrdks&nt dj |j|j r|j jdyy)zx Set communication parameters on opened port. For the loop:// protocol all settings are ignored! rlzinvalid baudrate: {!r}z_reconfigure_port()N) isinstance _baudratenumbersIntegral ValueErrorformatrr r0s r!r)zSerial._reconfigure_portZsc $..'*:*:;1t~~C_X_C_5< {:d}r$r rr r<rqsizer0s r! in_waitingzSerial.in_waiting~s[||"$ $ ;; KK  299$**:J:J:LM Nzz!!r"c|js t|j1|jdk7r"tj|jz}nd}t }|dkDr|jr |j j |j}| ||z }|dz}n t|S|rJtj|kDr3|jr|jjd t|S|dkDr |jrt|S#t j$r|jdk(r Yt|SYwxYw)z 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. Nrtimeoutz read timeout) r$r _timeouttime bytearrayrgetEmptyrr bytes)rsizerUdatabs r!readz Serial.reads# ||"$ $ == $!);iikDMM1GG{Qh4<< JJNN4==N9 =AIDAIDT{ 499;0;;KK$$^4T{%Qh4<<$T{;; ==A%T{& s2&D"E  E c:|jjdy)N)rr3r0s r! cancel_readzSerial.cancel_reads d#r"cd|_y)NT)rr0s r! cancel_writezSerial.cancel_writes !r"cd|_|js tt|}dt |z|j z }|j z||j kDrk|j }|dkDrB|js6tjt|d|dz}|dkDr |js6|jrytdt|D])}|jj||j +t |S)z Output the given byte string over the serial port. Can block if the connection is blocked. May raise SerialException if the connection is closed. Fg$@rg?z Write timeoutrT)rr$r rlenr8_write_timeoutrXsleepminrrrput)rr^time_used_to_send time_leftbytes r!writez Serial.writes #||"$ $~ 3t9,t~~=    */@4CVCV/V++Ia-(:(: 3y#./S a-(:(:!!(9 9dO >D JJNN4)<)4yr"cR|js t|jr|jjd |jj r6|jj |jj r5yy#tj$rYywxYw)z9Clear input buffer, discarding all that is in the buffer.zreset_input_buffer()Nr$r rr rrQ get_nowaitr[r0s r!r.zSerial.reset_input_buffersy||"$ $ ;; KK  3 4 **""$ %%'**""${{   ABB&%B&cR|js t|jr|jjd |jj r6|jj |jj r5yy#tj$rYywxYw)zs Clear output buffer, aborting the current output and discarding all that is in the buffer. zreset_output_buffer()Nrpr0s r!r/zSerial.reset_output_buffers{ ||"$ $ ;; KK  4 5 **""$ %%'**""${{   rrc|js t|jrB|jjdj |j j |j j S)z0Return how many bytes the in the outgoing bufferzout_waiting -> {:d}rPr0s r! out_waitingzSerial.out_waitings[||"$ $ ;; KK  3::4::;K;K;MN Ozz!!r"c|jr5|jjdj|jyy)z[ Set break: Controls TXD. When active, to transmitting is possible. z_update_break_state({!r})N)rr r< _break_stater0s r!_update_break_statezSerial._update_break_states4 ;; KK  8??@Q@QR S r"c|jr5|jjdj|jyy)z)Set terminal status line: Request To Sendz'_update_rts_state({!r}) -> state of CTSN)rr r< _rts_stater0s r!r-zSerial._update_rts_state0 ;; KK  FMMdoo^ _ r"c|jr5|jjdj|jyy)z-Set terminal status line: Data Terminal Readyz'_update_dtr_state({!r}) -> state of DSRNrr r< _dtr_stater0s r!r+zSerial._update_dtr_stater{r"c|js t|jr4|jjdj |j |j S)z(Read terminal status line: Clear To SendzCTS -> state of RTS ({!r}))r$r rr r<rzr0s r!ctsz Serial.ctssG||"$ $ ;; KK  9@@Q Rr"c|jr4|jjdj|j|jS)z)Read terminal status line: Data Set ReadyzDSR -> state of DTR ({!r})r}r0s r!dsrz Serial.dsr s7 ;; KK  9@@Q Rr"c~|js t|jr|jjdy)z)Read terminal status line: Ring Indicatorzreturning dummy for RIFr$r rr r0s r!riz Serial.ris1||"$ $ ;; KK  5 6r"c~|js t|jr|jjdy)z)Read terminal status line: Carrier Detectzreturning dummy for CDTrr0s r!cdz Serial.cds1||"$ $ ;; KK  5 6r")rV)__name__ __module__ __qualname____doc__ BAUDRATESrr1r5r)r'propertyrRr`rbrdrnr.r/rurxr-r+rrrr __classcell__)r s@r!rr)s]4I6#6$ 4P2""B$"6  ""T` `  r"r__main__zloop://z{} z write... zhello z read: {!r} )! __future__rr?r9rXr@ ImportError urllib.parseparserr%serial.serialutilrrrrrr DEBUGINFOWARNINGERRORrIrrsyssstdoutrnr<flushr`r5r"r!rs ' $yx]] LL ]]  zZzB zyAJJV]]1%&JJ\"GGIGGIJJ^**166!956GGIg$##$s"D)D;) D87D8; EE