c g%U nddlmZddlZddlZ en#eef$rGddeZYnwxYw en#eef$re ZYnwxYw e n#eef$re fZ YnwxYwdZ dZ e dgZ e dgZe d gZe d gZd \ZZZZZd \ZZZd \ZZZZededededediZGddeZGddeZ GddeZ!GddeZ"Gddej#Z$e%dkr7ddl&Z&e$Z'e&j()d*e'j+e&j()d*e'j,e&j()d *e'j-e&j()d!*e'j.e&j()d"*e'j/e&j()d#*e'dSdS)$)absolute_importNceZdZdS) memoryviewN)__name__ __module__ __qualname__a/home/jenkins/workspace/simtester-sanitize/venv/lib/python3.11/site-packages/serial/serialutil.pyrrs r rc#Kt|tr|}d} |||dz}|dz }|r|VndS)z=Iterate over bytes, returning bytes instead of ints (python3)rTN) isinstancertobytes)bias r iterbytesr(sf!Z   IIKK A aAgJ Q  GGGG E r cpt|tr|St|trt|St|tr|St|t r"t d|tt|S)z"convert a sequence to a bytes typez?unicode strings are not supported, please encode to bytes: {!r})rbytes bytearrayrrunicode TypeErrorformat)seqs r to_bytesr8s#u % C # #%Szz C $ $%{{}} C ! !%Y``adeefffYs^^$$$r  )NEOMS)r g?)NoneEvenOddMarkSpaceceZdZdZdS)SerialExceptionz.Base class for serial port related exceptions.Nrrr__doc__r r r r0r0\s8888r r0ceZdZdZdS)SerialTimeoutExceptionz Write timeouts give an exceptionNr1r r r r4r4`s****r r4c"eZdZdZfdZxZS)PortNotOpenErrorzPort is not opencXtt|ddS)Nz)Attempting to use a port that is not open)superr6__init__)self __class__s r r9zPortNotOpenError.__init__fs) %%../Z[[[[[r )rrrr2r9 __classcell__)r;s@r r6r6dsG\\\\\\\\\r r6c`eZdZdZeedrejZnejZdZdZ dZ dZ dS)Timeouta> Abstraction for timeout operations. Using time.monotonic() if available or time.time() in all other cases. The class can also be initialized with 0 or None, in order to support non-blocking and fully blocking I/O operations. The attributes is_non_blocking and is_infinite are set accordingly. monotonicc|du|_|dk|_||_|||z|_dSd|_dS)z(Initialize a timeout with given durationNr) is_infiniteis_non_blockingdurationTIME target_timer:rCs r r9zTimeout.__init__sQ$, (A    #yy{{X5D   #D   r cD|jduo|dkS)z4Return a boolean, telling if the timeout has expiredNr)rE time_leftr:s r expiredzTimeout.expireds$t+E0@0@A0EEr c|jrdS|jrdS|j|z }||jkr(||jz|_|jSt d|S)z:Return how many seconds are left until the timeout expiresrN)rBrArErDrCmax)r:deltas r rHzTimeout.time_leftsq   %1   %4$tyy{{2Et}$$#'99;;#> }$1e}}$r cL||_||z|_dS)zb Restart a timeout, only supported if a timeout was already set up before. N)rCrDrErFs r restartzTimeout.restarts& ! 99;;1r N) rrrr2hasattrtimer?rDr9rJrHrOr r r r>r>jswt[!!  ~ y$$$FFF % % %22222r r>c eZdZdZdZeeeefZ e e e e efZeeefZddee edddddddf dZedZejdZed Zejd Zed Zejd Zed ZejdZedZejdZedZejdZedZejdZedZejdZedZejdZedZ e jdZ edZ!e!jdZ!edZ"e"jdIdZ"edZ#e#jd Z#ed!Z$e$jd"Z$ed#Z%e%jd$Z%ed%Z&e&jd&Z&d'Z'd(Z(d)Z)d*Z*d+Z+d,Z,d-Z-d.Z.d/Z/d0Z0dJd2Z1d3Z2d4Z3d5Z4dJd6Z5dKd8Z6dKd9Z7d:Z8d;Z9d<Z:d=Z;d>Ze>jdBZ>dCZ?dDZ@dEZAdFZBeCdfdGZDdHZEdS)L SerialBasezh Serial port base class. Provides __init__ function and properties to get/set port settings. )2Kni,iXiii` i%iKiiiiii iii@Bii`ii%&i-ig5i =NrZFc  d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_d|_d|_||_||_||_||_||_||_| |_||_||_| |_| |_| |_d| vr| d|_d| vr| d|_| r"tAd!| ||"dSdS)z Initialize comm port object. If a "port" is given, then the port will be opened immediately. Otherwise a Serial port object in closed state is returned. FNT writeTimeoutinterCharTimeoutz"unexpected keyword arguments: {!r})#is_openportstrname_port _baudrate _bytesize_parity _stopbits_timeout_write_timeout_xonxoff_rtscts_dsrdtr_inter_byte_timeout _rs485_mode _rts_state _dtr_state _break_state _exclusiveportbaudratebytesizeparitystopbitstimeout write_timeoutxonxoffrtsctsdsrdtrinter_byte_timeout exclusivepop ValueErrorropen)r:rqrrrsrtrurvrxryrwrzr{r|kwargss r r9zSerialBase.__init__sk(      "   #' !         *   "4" V # #!'N!;!;D   ' '&,jj1C&D&DD #  RAHHPPQQ Q   IIKKKKK  r c|jS)z{ Get the current port setting. The value that was passed on init or using setPort() is passed back. )rarIs r rqzSerialBase.ports zr c0|Dt|ts/tdt ||j}|r|||_||_|j|_ |r| dSdS)z! Change the port. Nz'"port" must be None or a string, not {}) r basestringr~rtyper^closer_rar`r)r:rqwas_opens r rqzSerialBase.ports  JtZ$@$@ FMMdSWjjYYZZ Z<   JJLLL  L   IIKKKKK  r c|jS)z"Get the current baud rate setting.)rbrIs r rrzSerialBase.baudrate ~r c t|}|dkr"td|||_|jr|dSdS#t $r#td|wxYw)z Change baud rate. It raises a ValueError if the port is open and the baud rate is not possible. If the port is closed, then the value is accepted and the exception is raised when the port is opened. rzNot a valid baudrate: {!r}N)intr~rrbr^_reconfigure_portr)r:rrrs r rrzSerialBase.baudrates )H A1uu !=!D!DX!N!NOOODN| )&&((((( ) )  L L L9@@JJKK K Ls A-B c|jS)z"Get the current byte size setting.)rcrIs r rszSerialBase.bytesize-rr c||jvr"td|||_|jr|dSdS)zChange byte size.zNot a valid byte size: {!r}N) BYTESIZESr~rrcr^r)r:rss r rszSerialBase.bytesize2sa 4> ) ):AA(KKLL L! < %  " " $ $ $ $ $ % %r c|jS)z)Get the current exclusive access setting.)rprIs r r|zSerialBase.exclusive;s r cN||_|jr|dSdS)z$Change the exclusive access setting.N)rpr^r)r:r|s r r|zSerialBase.exclusive@s7$ < %  " " $ $ $ $ $ % %r c|jS)zGet the current parity setting.)rdrIs r rtzSerialBase.parityG |r c||jvr"td|||_|jr|dSdS)zChange parity setting.zNot a valid parity: {!r}N)PARITIESr~rrdr^r)r:rts r rtzSerialBase.parityLsa  & &7>>vFFGG G < %  " " $ $ $ $ $ % %r c|jS)z"Get the current stop bits setting.)rerIs r ruzSerialBase.stopbitsUrr c||jvr"td|||_|jr|dSdS)zChange stop bits size.zNot a valid stop bit size: {!r}N)STOPBITSr~rrer^r)r:rus r ruzSerialBase.stopbitsZsa 4= ( (>EEhOOPP P! < %  " " $ $ $ $ $ % %r c|jSz Get the current timeout setting.)rfrIs r rvzSerialBase.timeoutc }r c|_ |dzn0#t$r#td|wxYw|dkr"td|||_|jr|dSdS)Change timeout setting.Nr Not a valid timeout: {!r}r)rr~rrfr^rr:rvs r rvzSerialBase.timeouths   N!  N N N !z+SerialBase.get_settings..s,UUUc74s334UUUr )dict_SAVED_SETTINGSrIs`r get_settingszSerialBase.get_settingss+ UUUU@TUUUVVVr c|jD]:}||vr4||t|d|zkrt||||;dS)z Apply stored settings from a dictionary returned from get_settings(). It's allowed to delete keys from the dictionary. These values will simply left unchanged. rN)rrsetattr)r:drs r apply_settingszSerialBase.apply_settingss\ ' + +CaxxAcFgdC#I&>&>>>c1S6*** + +r c`d|jjt||S)zAString representation of the current port settings and its state.z{name}(port={p.portstr!r}, baudrate={p.baudrate!r}, bytesize={p.bytesize!r}, parity={p.parity!r}, stopbits={p.stopbits!r}, timeout={p.timeout!r}, xonxoff={p.xonxoff!r}, rtscts={p.rtscts!r}, dsrdtr={p.dsrdtr!r}))r`idp)rr;rrrIs r __repr__zSerialBase.__repr__s9;rfrrJr)r:expectedsizelentermlinervcs r read_untilzSerialBase.read_untils h--{{$-((  ! A   ?h..#D T(9(9    T{{r c/4K |j|i|}|sdS|V)zs Read lines, implemented as generator. It will raise StopIteration on timeout (empty read). TN)r)r:rrrs r iread_untilzSerialBase.iread_untils<  "4?D3F33D JJJ  r r)r)r )Frrrr2 BAUDRATESFIVEBITSSIXBITS SEVENBITS EIGHTBITSr PARITY_NONE PARITY_EVEN PARITY_ODD PARITY_MARK PARITY_SPACEr STOPBITS_ONESTOPBITS_ONE_POINT_FIVE STOPBITS_TWOrr9propertyrqsetterrrrsr|rtrurvrwr{rxryrzrrrrrrrrrrrrrrrrrrrrrrrrrr r\r]rrrrLFrr!r r r rSrSsV ,I7Iy9I[*k<PH5|DH##&#$(@@@@TX [  [ X_))_)"X_%%_%X%%% X ]%%]%X_%%_%X ^ % %^ %##X# % % %((X( % % %X ^%%^% X ]%%]% X ] % % %] %X Z%%Z% X Z%%Z% !!X!'''  X %%%-OWWW+++FFF     % % % %"""###""""""X"%%%''X'333### *** #%4,     r rS__main__zport name: {} zbaud rates: {} zbyte sizes: {} zparities: {} zstop bits: {} z{} )0 __future__riorQr NameErrorAttributeErrorobjectrstrrrrXONXOFFCRr1r'r(r)r*r+r,r-r.r#r$r%r& PARITY_NAMESIOErrorr0r4r6r> RawIOBaserSrsyssstdoutwriterr`r"rrrr r r rCs'&&&&&  JJ>"        V       GG>"GGGJJ>"JJJ    % % % htnnx~~ Xrd^^ Xrd^^CZ? [*k<6A3 %|*6''9i'  99999g999+++++_+++\\\\\\\\ 8282828282f828282vHHHHHHHHX zJJJ AJ'..qv66777J'..q{;;<<<J'..q{;;<<<J'..qz::;;;J'..qz::;;;JV]]1%%&&&&&s*++2 >>A AA