관리-도구
편집 파일: serialutil.cpython-39.pyc
a ������gY�T������������������� ���@���s���d�dl�Z�d�dlZze�W�n&�eefy>���G�dd��de�ZY�n0�ze�W�n�eefyb���eZY�n0�ze�W�n�eefy����efZY�n0�dd��Z dd��Z e dg�Ze d g�Ze d g�Z e dg�Zd\ZZZZZd \ZZZd\ZZZZededededediZG�dd��de�ZG�dd��de�Zed�Zed�Z G�dd��de�Z!G�dd��de�j"�Z#e$dk�r�d�dl%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&���dS�)%�����Nc�������������������@���s���e�Zd�ZdS�)� memoryviewN)�__name__� __module__�__qualname__��r���r����5/usr/lib/python3.9/site-packages/serial/serialutil.pyr������s���r���c�����������������c���sB���t�|�t�r|����}�d}|�||d���}|d7�}|r>|V��qq>qdS�)z=Iterate over bytes, returning bytes instead of ints (python3)r�������N)� isinstancer����tobytes)�b�i�ar���r���r���� iterbytes&���s���� r���c�����������������C���s\���t�|�t�r|�S�t�|�t�r t|��S�t�|�t�r2|����S�t�|�t�rLtd�|����ntt|���S�dS�)z"convert a sequence to a bytes typez?unicode strings are not supported, please encode to bytes: {!r}N)r ����bytes� bytearrayr���r ����unicode� TypeError�format)�seqr���r���r����to_bytes6���s���� r������������ ���� ���)�N�E�O�M�S)r���g�������?����)�����������������NoneZEvenZOddZMarkZSpacec�������������������@���s���e�Zd�ZdZdS�)�SerialExceptionz.Base class for serial port related exceptions.N�r���r���r����__doc__r���r���r���r���r%���Z���s���r%���c�������������������@���s���e�Zd�ZdZdS�)�SerialTimeoutExceptionz Write timeouts give an exceptionNr&���r���r���r���r���r(���^���s���r(���z Write timeoutz)Attempting to use a port that is not openc�������������������@���sH���e�Zd�ZdZeed�rejZnejZdd��Zdd��Z dd��Z d d ��ZdS�)�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�����������������C���s<���|du�|�_�|dk|�_||�_|dur2|����|�|�_nd|�_dS�)z(Initialize a timeout with given durationNr���)�is_infinite�is_non_blocking�duration�TIME�target_time��selfr-���r���r���r����__init__{���s���� zTimeout.__init__c�����������������C���s���|�j�duo|����dkS�)z4Return a boolean, telling if the timeout has expiredNr���)r/���� time_left�r1���r���r���r����expired����s����zTimeout.expiredc�����������������C���sP���|�j�r dS�|�jrdS�|�j|�����}||�jkrB|����|�j�|�_|�jS�td|�S�dS�)z:Return how many seconds are left until the timeout expiresr���N)r,���r+���r/���r.���r-����max)r1���Zdeltar���r���r���r3�������s���� zTimeout.time_leftc�����������������C���s���||�_�|����|�|�_dS�)zb Restart a timeout, only supported if a timeout was already set up before. N)r-���r.���r/���r0���r���r���r����restart����s����zTimeout.restartN)r���r���r���r'����hasattr�timer*���r.���r2���r5���r3���r7���r���r���r���r���r)���f���s��� r)���c�������������������@���s��e�Zd�ZdZdZeeeefZ e eee efZeeefZddee edddddddfdd�Zedd ���Zejd d ���Zedd���Zejd d���Zedd���Zejdd���Zedd���Zejdd���Zedd���Zejdd���Zedd���Zejdd���Zedd���Zejdd���Zedd���Zejdd���Zed d!���Zejd"d!���Zed#d$���Z e jd%d$���Z ed&d'���Z!e!jd(d'���Z!ed)d*���Z"e"jdwd+d*��Z"ed,d-���Z#e#jd.d-���Z#ed/d0���Z$e$jd1d0���Z$ed2d3���Z%e%jd4d3���Z%ed5d6���Z&e&jd7d6���Z&d8Z'd9d:��Z(d;d<��Z)d=d>��Z*d?d@��Z+dAdB��Z,dCdD��Z-dEdF��Z.dGdH��Z/dIdJ��Z0dxdLdM�Z1dNdO��Z2dPdQ��Z3dRdS��Z4dydTdU�Z5dzdWdX�Z6d{dYdZ�Z7d[d\��Z8d]d^��Z9d_d`��Z:dadb��Z;dcdd��Z<ededf���Z=e=jdgdf���Z=edhdi���Z>e>jdjdi���Z>dkdl��Z?dmdn��Z@dodp��ZAdqdr��ZBeCdfdsdt�ZDdudv��ZEdS�)|� SerialBasezh Serial port base class. Provides __init__ function and properties to get/set port settings. )�2����K����n����������������i,��iX��i���i��i` ��i����%��i�K��i����i����i���i���i��i ��i���i��i@B�i���i`��i���i�%&�i��-�i�g5�i� =�NrA���Fc �����������������K���s ��d|�_�d|�_d|�_d|�_d|�_d|�_d|�_d|�_d|�_d|�_ d|�_ d|�_d|�_d|�_ d|�_d|�_d|�_d|�_d|�_||�_||�_||�_||�_||�_||�_| |�_||�_||�_| |�_||�_||�_d| v�r�| �d�|�_d| v�r�| �d�|�_| r�t d�!| ���|du�r|��"���dS�)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�writeTimeout�interCharTimeoutz"unexpected keyword arguments: {!r})#�is_open�portstr�name�_port� _baudrate� _bytesize�_parity� _stopbits�_timeout�_write_timeout�_xonxoff�_rtscts�_dsrdtr�_inter_byte_timeout�_rs485_mode� _rts_state� _dtr_state�_break_state� _exclusive�port�baudrate�bytesize�parity�stopbits�timeout� write_timeout�xonxoff�rtscts�dsrdtr�inter_byte_timeout� exclusive�pop� ValueErrorr����open)r1���rW���rX���rY���rZ���r[���r\���r^���r_���r]���r`���ra���rb����kwargsr���r���r���r2�������sN���� zSerialBase.__init__c�����������������C���s���|�j�S�)z{ Get the current port setting. The value that was passed on init or using setPort() is passed back. )rG���r4���r���r���r���rW�������s����zSerialBase.portc�����������������C���sZ���|dur$t�|t�s$td�t|����|�j}|r6|�����||�_||�_|�j|�_ |rV|�� ���dS�)z! Change the port. Nz'"port" must be None or a string, not {})r ���� basestringrd���r����typerD����closerE���rG���rF���re���)r1���rW���Zwas_openr���r���r���rW�����s����c�����������������C���s���|�j�S�)z"Get the current baud rate setting.)rH���r4���r���r���r���rX�����s����zSerialBase.baudratec�����������������C���s\���zt�|�}W�n �ty,���td�|���Y�n,0�|dk�rDtd�|���||�_|�jrX|�����dS�)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. zNot a valid baudrate: {!r}r���N)�intr���rd���r���rH���rD����_reconfigure_port)r1���rX���r���r���r���r���rX�����s����c�����������������C���s���|�j�S�)z"Get the current byte size setting.)rI���r4���r���r���r���rY���)��s����zSerialBase.bytesizec�����������������C���s0���||�j�vrtd�|���||�_|�jr,|�����dS�)zChange byte size.zNot a valid byte size: {!r}N)� BYTESIZESrd���r���rI���rD���rk���)r1���rY���r���r���r���rY���.��s ���� c�����������������C���s���|�j�S�)z)Get the current exclusive access setting.)rV���r4���r���r���r���rb���7��s����zSerialBase.exclusivec�����������������C���s���||�_�|�jr|�����dS�)z$Change the exclusive access setting.N)rV���rD���rk���)r1���rb���r���r���r���rb���<��s����c�����������������C���s���|�j�S�)zGet the current parity setting.)rJ���r4���r���r���r���rZ���C��s����zSerialBase.parityc�����������������C���s0���||�j�vrtd�|���||�_|�jr,|�����dS�)zChange parity setting.zNot a valid parity: {!r}N)�PARITIESrd���r���rJ���rD���rk���)r1���rZ���r���r���r���rZ���H��s ���� c�����������������C���s���|�j�S�)z"Get the current stop bits setting.)rK���r4���r���r���r���r[���Q��s����zSerialBase.stopbitsc�����������������C���s0���||�j�vrtd�|���||�_|�jr,|�����dS�)zChange stop bits size.zNot a valid stop bit size: {!r}N)�STOPBITSrd���r���rK���rD���rk���)r1���r[���r���r���r���r[���V��s ���� c�����������������C���s���|�j�S��z Get the current timeout setting.)rL���r4���r���r���r���r\���_��s����zSerialBase.timeoutc�����������������C���sd���|durLz|d��W�n �t�y4���td�|���Y�n0�|dk�rLtd�|���||�_|�jr`|�����dS�)�Change timeout setting.Nr����Not a valid timeout: {!r}r���)r���rd���r���rL���rD���rk����r1���r\���r���r���r���r\���d��s����c�����������������C���s���|�j�S�ro���)rM���r4���r���r���r���r]���r��s����zSerialBase.write_timeoutc�����������������C���sd���|durL|dk�rt�d�|���z|d��W�n �tyJ���t�d�|���Y�n0�||�_|�jr`|�����dS�)rp���Nr���rq���r���)rd���r���r���rM���rD���rk���rr���r���r���r���r]���w��s����c�����������������C���s���|�j�S�)z0Get the current inter-character timeout setting.)rQ���r4���r���r���r���ra������s����zSerialBase.inter_byte_timeoutc�����������������C���sd���|durL|dk�rt�d�|���z|d��W�n �tyJ���t�d�|���Y�n0�||�_|�jr`|�����dS�)z"Change inter-byte timeout setting.Nr���rq���r���)rd���r���r���rQ���rD���rk���)r1���Z ic_timeoutr���r���r���ra������s����c�����������������C���s���|�j�S�)z!Get the current XON/XOFF setting.)rN���r4���r���r���r���r^������s����zSerialBase.xonxoffc�����������������C���s���||�_�|�jr|�����dS�)zChange XON/XOFF setting.N)rN���rD���rk���)r1���r^���r���r���r���r^������s����c�����������������C���s���|�j�S�)z-Get the current RTS/CTS flow control setting.)rO���r4���r���r���r���r_������s����zSerialBase.rtsctsc�����������������C���s���||�_�|�jr|�����dS�)z$Change RTS/CTS flow control setting.N)rO���rD���rk���)r1���r_���r���r���r���r_������s����c�����������������C���s���|�j�S�)z-Get the current DSR/DTR flow control setting.)rP���r4���r���r���r���r`������s����zSerialBase.dsrdtrc�����������������C���s*���|du�r|�j�|�_n||�_|�jr&|�����dS�)z#Change DsrDtr flow control setting.N)rO���rP���rD���rk���)r1���r`���r���r���r���r`������s ���� c�����������������C���s���|�j�S��N)rS���r4���r���r���r����rts���s����zSerialBase.rtsc�����������������C���s���||�_�|�jr|�����d�S�rs���)rS���rD���Z_update_rts_state�r1����valuer���r���r���rt������s����c�����������������C���s���|�j�S�rs���)rT���r4���r���r���r����dtr���s����zSerialBase.dtrc�����������������C���s���||�_�|�jr|�����d�S�rs���)rT���rD���Z_update_dtr_stateru���r���r���r���rw������s����c�����������������C���s���|�j�S�rs���)rU���r4���r���r���r����break_condition���s����zSerialBase.break_conditionc�����������������C���s���||�_�|�jr|�����d�S�rs���)rU���rD���Z_update_break_stateru���r���r���r���rx������s����c�����������������C���s���|�j�S�)z� Enable RS485 mode and apply new settings, set to None to disable. See serial.rs485.RS485Settings for more info about the value. )rR���r4���r���r���r���� rs485_mode���s����zSerialBase.rs485_modec�����������������C���s���||�_�|�jr|�����d�S�rs���)rR���rD���rk���)r1���Zrs485_settingsr���r���r���ry������s����) rX���rY���rZ���r[���r^���r`���r_���r\���r]���ra���c��������������������s���t���fdd���jD���S�)zb Get current port settings as a dictionary. For use with apply_settings(). c��������������������s���g�|�]}|t���d�|��f�qS�)�_)�getattr)�.0�keyr4���r���r���� <listcomp>��������z+SerialBase.get_settings.<locals>.<listcomp>)�dict�_SAVED_SETTINGSr4���r���r4���r����get_settings���s����zSerialBase.get_settingsc�����������������C���s>���|�j�D�]2}||v�r||�t|�d|��krt|�|||���qdS�)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. rz���N)r����r{����setattr)r1����dr}���r���r���r����apply_settings���s���� zSerialBase.apply_settingsc�����������������C���s���dj�|�jjt|��|�d�S�)zAString representation of the current port settings and its state.z�{name}<id=0x{id:x}, open={p.is_open}>(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}))rF����id�p)r���� __class__r���r����r4���r���r���r����__repr__��s�����zSerialBase.__repr__c�����������������C���s���dS��NTr���r4���r���r���r����readable��s����zSerialBase.readablec�����������������C���s���dS�r����r���r4���r���r���r����writable��s����zSerialBase.writablec�����������������C���s���dS�)NFr���r4���r���r���r����seekable��s����zSerialBase.seekablec�������������� ���C���s|���|���t|��}t|�}z||d�|�<�W�nP�tyv�}�z8dd�l}t||j�sN|�|�d|�|d�|�<�W�Y�d�}~n d�}~0�0�|S�)Nr���r���)�read�lenr����arrayr ���)r1���r����data�n�errr����r���r���r����readinto ��s����*zSerialBase.readintoc�����������������C���s���|�j�s|�����|�S�rs���)rD���re���r4���r���r���r���� __enter__/��s����zSerialBase.__enter__c�����������������O���s���|������d�S�rs���)ri���)r1����argsrf���r���r���r����__exit__4��s����zSerialBase.__exit__��������?c�����������������C���s$���|�j�s t�d|�_t�|��d|�_dS�)za Send break condition. Timed, returns to idle state after given duration. TFN)rD����portNotOpenErrorrx���r9����sleepr0���r���r���r���� send_break9��s ���� zSerialBase.send_breakc�����������������C���s���|������d�S�rs���)Zreset_input_bufferr4���r���r���r���� flushInputG��s����zSerialBase.flushInputc�����������������C���s���|������d�S�rs���)Zreset_output_bufferr4���r���r���r����flushOutputJ��s����zSerialBase.flushOutputc�����������������C���s���|�j�S�rs���)� in_waitingr4���r���r���r���� inWaitingM��s����zSerialBase.inWaitingc�����������������C���s���|���|��d�S�rs���)r����r0���r���r���r���� sendBreakP��s����zSerialBase.sendBreakr���c�����������������C���s ���||�_�d�S�rs���)rt���ru���r���r���r����setRTSS��s����zSerialBase.setRTSc�����������������C���s ���||�_�d�S�rs���)rw���ru���r���r���r����setDTRV��s����zSerialBase.setDTRc�����������������C���s���|�j�S�rs���)Zctsr4���r���r���r����getCTSY��s����zSerialBase.getCTSc�����������������C���s���|�j�S�rs���)Zdsrr4���r���r���r����getDSR\��s����zSerialBase.getDSRc�����������������C���s���|�j�S�rs���)Zrir4���r���r���r����getRI_��s����zSerialBase.getRIc�����������������C���s���|�j�S�rs���)Zcdr4���r���r���r����getCDb��s����zSerialBase.getCDc�����������������C���s ���||�_�d�S�rs���)rW���)r1���rW���r���r���r����setPorte��s����zSerialBase.setPortc�����������������C���s���|�j�S�rs����r]���r4���r���r���r���rB���h��s����zSerialBase.writeTimeoutc�����������������C���s ���||�_�d�S�rs���r����rr���r���r���r���rB���l��s����c�����������������C���s���|�j�S�rs����ra���r4���r���r���r���rC���p��s����zSerialBase.interCharTimeoutc�����������������C���s ���||�_�d�S�rs���r����)r1���rC���r���r���r���rC���t��s����c�����������������C���s���|�����S�rs���)r����r4���r���r���r����getSettingsDictx��s����zSerialBase.getSettingsDictc�����������������C���s���|���|��d�S�rs���)r����)r1���r����r���r���r����applySettingsDict{��s����zSerialBase.applySettingsDictc�����������������C���s���|�j�S�rs���)rD���r4���r���r���r����isOpen~��s����zSerialBase.isOpenc�����������������C���s���|���|�j�S�)zL Read all bytes currently available in the buffer of the OS. )r����r����r4���r���r���r����read_all���s����zSerialBase.read_allc�����������������C���sp���t�|�}t��}t|�j�}|��d�}|rh||7�}||�d��|krBqh|dur\t�|�|kr\qhnqh|���rqhqt|�S�)z� Read until a termination sequence is found (' ' by default), the size is exceeded or until timeout occurs. r���N)r����r���r)���rL���r����r5���r���)r1���� terminator�sizeZlenterm�liner\����cr���r���r���� read_until���s���� zSerialBase.read_untilc�����������������o���s"���|�j�|i�|��}|sq|V��q�dS�)zs Read lines, implemented as generator. It will raise StopIteration on timeout (empty read). N)r����)r1���r����rf���r����r���r���r����iread_until���s����zSerialBase.iread_until)N)r����)r����)r���)r���)Fr���r���r���r'���� BAUDRATES�FIVEBITS�SIXBITS� SEVENBITS� EIGHTBITSrl����PARITY_NONE�PARITY_EVEN� PARITY_ODD�PARITY_MARK�PARITY_SPACErm����STOPBITS_ONE�STOPBITS_ONE_POINT_FIVE�STOPBITS_TWOrn���r2����propertyrW����setterrX���rY���rb���rZ���r[���r\���r]���ra���r^���r_���r`���rt���rw���rx���ry���r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����rB���rC���r����r����r����r�����LFr����r����r���r���r���r���r:�������s���� � J r:����__main__zport name: {} zbaud rates: {} zbyte sizes: {} zparities: {} zstop bits: {} z{} )/�ior9���r���� NameError�AttributeError�objectr����strrg���r���r���ZXONZXOFFZCRr����r����r����r����r����r����r����r����r����r����r����r����r����ZPARITY_NAMES�IOErrorr%���r(���ZwriteTimeoutErrorr����r)���� RawIOBaser:���r����sys�s�stdout�writer���rF���r����rl���rm���rn���r���r���r���r����<module> ���s^��� � ;����