%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17212/usr/lib/python3/dist-packages/serial/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17212/usr/lib/python3/dist-packages/serial/__pycache__/serialutil.cpython-35.pyc



�M�V6L�@sUddlZddlZyeWn.eefk
rPGdd�de�ZYnXyeWneefk
ryeZYnXdd�Zdd�Z	e	dg�Z
e	d	g�Ze	d
g�Ze	dg�Z
dd
dddf\ZZZZZdddf\ZZZddddf\ZZZZededededediZGdd�de�ZGdd �d e�Zed!�Zed"�ZGd#d$�d$ej �Z!e"d%krQddl#Z#e!�Z$e#j%j&d&e$j'�e#j%j&d'e$j(�e#j%j&d(e$j)�e#j%j&d)e$j*�e#j%j&d*e$j+�e#j%j&d+e$�dS),�Nc@seZdZdS)�
memoryviewN)�__name__�
__module__�__qualname__�rr�3/usr/lib/python3/dist-packages/serial/serialutil.pyrsrccsYt|t�r|j�}d}x1|||d�}|d7}|rP|Vq$Pq$WdS)z=Iterate over bytes, returning bytes instead of ints (python3)r�N)�
isinstancer�tobytes)�b�x�arrr�	iterbytes!s
rcCs�t|t�r|St|t�r,t|�St|t�rE|j�St|t�rjtd|f��nLt�}x6|D].}t|t�r�t|�}|j|�qzWt|�SdS)z"convert a sequence to a bytes typez=unicode strings are not supported, please encode to bytes: %rN)	r	�bytes�	bytearrayrr
�unicode�	TypeError�ord�append)�seqr�itemrrr�to_bytes1s

	
r���
�
�N�E�O�M�Srg�?������NoneZEvenZOddZMarkZSpacec@seZdZdZdS)�SerialExceptionz.Base class for serial port related exceptions.N)rrr�__doc__rrrrr'Zsr'c@seZdZdZdS)�SerialTimeoutExceptionz Write timeouts give an exceptionN)rrrr(rrrrr)^sr)z
Write timeoutz)Attempting to use a port that is not openc@sieZdZdZd�ZeeeefZ	e
eee
efZeeefZd dee
ed d!d!d d!d d"d#�Zed$d%��Zejd&d%��Zed'd(��Zejd)d(��Zed*d+��Zejd,d+��Zed-d.��Zejd/d.��Zed0d1��Zejd2d1��Zed3d4��Zejd5d4��Zed6d7��Zejd8d7��Zed9d:��Zejd;d:��Zed<d=��Zejd>d=��Zed?d@��Z e jdAd@��Z edBdC��Z!e!jd dDdC��Z!edEdF��Z"e"jdGdF��Z"edHdI��Z#e#jdJdI��Z#edKdL��Z$e$jdMdL��Z$edNdO��Z%e%jdPdO��Z%d�Z&d[d\�Z'd]d^�Z(d_d`�Z)dadb�Z*dcdd�Z+dedf�Z,dgdh�Z-didj�Z.dkdl�Z/dmdndo�Z0dpdq�Z1drds�Z2dtdu�Z3dmdvdw�Z4dxdydz�Z5dxd{d|�Z6d}d~�Z7dd��Z8d�d��Z9d�d��Z:ed�d���Z;e;jd�d���Z;ed�d���Z<e<jd�d���Z<d�d��Z=d�d��Z>d�d��Z?d�d��Z@eAd d�d��ZBd�d��ZCd S)��
SerialBasezh    Serial port base class. Provides __init__ function and properties to
    get/set port settings.
    �2�K�n�����,�X���`	��%�K���������� �����@B���`�逄�%&��-��g5�	=NFc
Ksbd|_d|_d|_d|_d|_d|_d|_d|_d|_d|_	d|_
d|_d|_d|_
d|_d|_||_||_||_||_||_||_|	|_||_||_|
|_||_d|kr|jd�|_d|kr/|jd�|_|rHtd|f��|dk	r^|j�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�_port�	_baudrate�	_bytesize�_parity�	_stopbits�_timeout�_write_timeout�_xonxoff�_rtscts�_dsrdtr�_inter_byte_timeout�_rs485_mode�
_rts_state�
_dtr_state�_break_state�port�baudrate�bytesize�parity�stopbits�timeout�
write_timeout�xonxoff�rtscts�dsrdtr�inter_byte_timeout�pop�
ValueError�open)
�selfr[r\r]r^r_r`rbrcrardre�kwargsrrr�__init__usF																											zSerialBase.__init__cCs|jS)z�        Get the current port setting. The value that was passed on init or using
        setPort() is passed back. See also the attribute portstr which contains
        the name of the port as a string.
        )rL)rirrrr[�szSerialBase.portcCsK|j}|r|j�||_||_|j|_|rG|j�dS)zv        Change the port. The attribute portstr is set to a string that
        contains the name of the port.
        N)rK�close�portstrrL�namerh)rir[Zwas_openrrrr[�s	
		cCs|jS)z"Get the current baud rate setting.)rM)rirrrr\�szSerialBase.baudratecCswyt|�}Wn%tk
r7td|f��Yn<X|dkrWtd|f��||_|jrs|j�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: %rrN)�intrrgrMrK�_reconfigure_port)rir\rrrrr\�s
		cCs|jS)z"Get the current byte size setting.)rN)rirrrr]�szSerialBase.bytesizecCsB||jkr"td|f��||_|jr>|j�dS)zChange byte size.zNot a valid byte size: %rN)�	BYTESIZESrgrNrKrp)rir]rrrr]�s
		cCs|jS)zGet the current parity setting.)rO)rirrrr^szSerialBase.paritycCsB||jkr"td|f��||_|jr>|j�dS)zChange parity setting.zNot a valid parity: %rN)�PARITIESrgrOrKrp)rir^rrrr^s
		cCs|jS)z"Get the current stop bits setting.)rP)rirrrr_szSerialBase.stopbitscCsB||jkr"td|f��||_|jr>|j�dS)zChange stop bits size.zNot a valid stop bit size: %rN)�STOPBITSrgrPrKrp)rir_rrrr_s
		cCs|jS)z Get the current timeout setting.)rQ)rirrrr`szSerialBase.timeoutcCs|dk	r_y|dWn%tk
r?td|f��YnX|dkr_td|f��||_|jr{|j�dS)zChange timeout setting.NrzNot a valid timeout: %rr)rrgrQrKrp)rir`rrrr`$s
		cCs|jS)z Get the current timeout setting.)rR)rirrrra3szSerialBase.write_timeoutcCs||dk	r\|dkr+td|f��y|dWn"tk
r[td|��YnX||_|jrx|j�dS)zChange timeout setting.NrzNot a valid timeout: %rr)rgrrRrKrp)rir`rrrra8s
		cCs|jS)z0Get the current inter-character timeout setting.)rV)rirrrreHszSerialBase.inter_byte_timeoutcCsy|dk	rY|dkr(td|��y|dWn"tk
rXtd|��YnX||_|jru|j�dS)z"Change inter-byte timeout setting.NrzNot a valid timeout: %rr)rgrrVrKrp)riZ
ic_timeoutrrrreMs
		cCs|jS)z!Get the current XON/XOFF setting.)rS)rirrrrb]szSerialBase.xonxoffcCs ||_|jr|j�dS)zChange XON/XOFF setting.N)rSrKrp)rirbrrrrbbs		cCs|jS)z-Get the current RTS/CTS flow control setting.)rT)rirrrrcjszSerialBase.rtsctscCs ||_|jr|j�dS)z$Change RTS/CTS flow control setting.N)rTrKrp)rircrrrrcos		cCs|jS)z-Get the current DSR/DTR flow control setting.)rU)rirrrrdwszSerialBase.dsrdtrcCs;|dkr|j|_n	||_|jr7|j�dS)z#Change DsrDtr flow control setting.N)rTrUrKrp)rirdrrrrd|s
		cCs|jS)N)rX)rirrr�rts�szSerialBase.rtscCs ||_|jr|j�dS)N)rXrKZ_update_rts_state)ri�valuerrrrt�s		cCs|jS)N)rY)rirrr�dtr�szSerialBase.dtrcCs ||_|jr|j�dS)N)rYrKZ_update_dtr_state)rirurrrrv�s		cCs|jS)N)rZ)rirrr�break_condition�szSerialBase.break_conditioncCs ||_|jr|j�dS)N)rZrKZ_update_break_state)rirurrrrw�s		cCs|jS)z�        Enable RS485 mode and apply new settings, set to None to disable.
        See serial.rs485.RS485Settings for more info about the value.
        )rW)rirrr�
rs485_mode�szSerialBase.rs485_modecCs ||_|jr|j�dS)N)rWrKrp)riZrs485_settingsrrrrx�s		r\r]r^r_rbrdrcr`rarecs t�fdd��jD��S)zb        Get current port settings as a dictionary. For use with
        apply_settings().
        cs)g|]}|t�d|�f�qS)�_)�getattr)�.0�key)rirr�
<listcomp>�s	z+SerialBase.get_settings.<locals>.<listcomp>)�dict�_SAVED_SETTINGS)rir)rir�get_settings�szSerialBase.get_settingscCsUxN|jD]C}||kr
||t|d|�kr
t||||�q
WdS)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.
        ryN)rrz�setattr)ri�dr|rrr�apply_settings�s)zSerialBase.apply_settingsc
CsVd|jjt|�|j|j|j|j|j|j|j	|j
|j|jfS)zAString representation of the current port settings and its state.z}%s<id=0x%x, open=%s>(port=%r, baudrate=%r, bytesize=%r, parity=%r, stopbits=%r, timeout=%r, xonxoff=%r, rtscts=%r, dsrdtr=%r))
�	__class__r�idrKrmr\r]r^r_r`rbrcrd)rirrr�__repr__�s		zSerialBase.__repr__cCsdS)NTr)rirrr�readable�szSerialBase.readablecCsdS)NTr)rirrr�writable�szSerialBase.writablecCsdS)NFr)rirrr�seekable�szSerialBase.seekablecCs�|jt|��}t|�}y||d|�<Wnetk
r�}zEddl}t||j�sn|�|jd|�|d|�<WYdd}~XnX|S)Nrr)�read�lenr�arrayr	)rir�data�n�errr�rrr�readinto�s/zSerialBase.readintocCs|S)Nr)rirrr�	__enter__�szSerialBase.__enter__cOs|j�dS)N)rl)ri�argsrjrrr�__exit__szSerialBase.__exit__g�?cCs2|jst�d|_tj|�d|_dS)za        Send break condition. Timed, returns to idle state after given
        duration.
        TFN)rK�portNotOpenErrorrw�timeZsleep)ri�durationrrr�
send_breaks
		
zSerialBase.send_breakcCs|j�dS)N)Zreset_input_buffer)rirrr�
flushInputszSerialBase.flushInputcCs|j�dS)N)Zreset_output_buffer)rirrr�flushOutputszSerialBase.flushOutputcCs|jS)N)�
in_waiting)rirrr�	inWaitingszSerialBase.inWaitingcCs|j|�dS)N)r�)rir�rrr�	sendBreakszSerialBase.sendBreakrcCs
||_dS)N)rt)rirurrr�setRTSszSerialBase.setRTScCs
||_dS)N)rv)rirurrr�setDTR"szSerialBase.setDTRcCs|jS)N)Zcts)rirrr�getCTS%szSerialBase.getCTScCs|jS)N)Zdsr)rirrr�getDSR(szSerialBase.getDSRcCs|jS)N)Zri)rirrr�getRI+szSerialBase.getRIcCs|jS)N)Zcd)rirrr�getCD.szSerialBase.getCDcCs|jS)N)ra)rirrrrI1szSerialBase.writeTimeoutcCs
||_dS)N)ra)rir`rrrrI5scCs|jS)N)re)rirrrrJ9szSerialBase.interCharTimeoutcCs
||_dS)N)re)rirJrrrrJ=scCs
|j�S)N)r�)rirrr�getSettingsDictAszSerialBase.getSettingsDictcCs|j|�dS)N)r�)rir�rrr�applySettingsDictDszSerialBase.applySettingsDictcCs|jS)N)rK)rirrr�isOpenGszSerialBase.isOpencCs|j|j�S)zL        Read all bytes currently available in the buffer of the OS.
        )r�r�)rirrr�read_allMszSerialBase.read_allcCs�t|�}t�}x^|jd�}|rq||7}||d�|krOP|dk	rrt|�|krrPqPqWt|�S)z�        Read until a termination sequence is found ('
' by default), the size
        is exceeded or until timeout occurs.
        rN)r�rr�r)ri�
terminator�sizeZlenterm�line�crrr�
read_untilSs	
zSerialBase.read_untilcos)x"|j||�}|sP|VqWdS)zs        Read lines, implemented as generator. It will raise StopIteration on
        timeout (empty read).
        N)r�)rir�rjr�rrr�iread_untilfs
zSerialBase.iread_until)r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrCrDrErFrGrH)
zbaudratezbytesizezparityzstopbitszxonxoffzdsrdtrzrtsctsztimeoutz
write_timeoutzinter_byte_timeout)Drrrr(�	BAUDRATES�FIVEBITS�SIXBITS�	SEVENBITS�	EIGHTBITSrq�PARITY_NONE�PARITY_EVEN�
PARITY_ODD�PARITY_MARK�PARITY_SPACErr�STOPBITS_ONE�STOPBITS_ONE_POINT_FIVE�STOPBITS_TWOrsrk�propertyr[�setterr\r]r^r_r`rarerbrcrdrtrvrwrxrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rIrJr�r�r�r��LFr�r�rrrrr*fs�:	
	r*�__main__zport name:  %s
zbaud rates: %s
zbyte sizes: %s
zparities:   %s
zstop bits:  %s
z%s
),�ior�r�	NameError�AttributeError�objectr�strrrZXONZXOFFZCRr�r�r�r�r�r�r�r�r�r�r�r�r�ZPARITY_NAMES�IOErrorr'r)ZwriteTimeoutErrorr��	RawIOBaser*r�sys�s�stdout�writernr�rqrrrsrrrr�<module>
sN$��	

Zerion Mini Shell 1.0