404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@18.117.188.109: ~ $
3

M�]WZJ�@sTddlZddlZddlmZddlZddlmZmZmZmZm	Z	Gdd�de�Z
dS)�N)�win32)�
SerialBase�SerialException�to_bytes�portNotOpenError�writeTimeoutErrorcseZdZdZdIZ�fdd�Zdd�Zdd�Zdd�Zdd�Z	e
dd��ZdJd d!�Zd"d#�Z
d$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Ze
d2d3��Ze
d4d5��Ze
d6d7��Ze
d8d9��ZdKd<d=�ZdLd?d@�Ze
dAdB��ZdCdD�ZdEdF�ZdGdH�Z�ZS)M�Serialz5Serial port implementation for Win32 based on ctypes.�2�K�n�����,�X���`	��%�K������cs(d|_d|_d|_tt|�j||�dS)N)�_port_handle�_overlapped_read�_overlapped_write�superr�__init__)�self�args�kwargs)�	__class__��!/usr/lib/python3.6/serialwin32.pyrszSerial.__init__cCs�|jdkrtd��|jr td��|j}y.|j�jd�rRt|dd��dkrRd|}Wntk
rhYnXtj	|tj
tjBddtjtj
tjBd�|_|jtjkr�d|_td	j|jtj����y�tj�|_tjdd
dd�|j_tj�|_tjdddd�|j_tj|jdd�tj�|_tj|jtj|j��|j�tj |jtj!tj"Btj#Btj$B�Wn.y|j%�WnYnXd|_�YnXd|_dS)
zx        Open port with current settings. This may throw a SerialException
        if the port cannot be opened.
        Nz.Port must be configured before it can be used.zPort is already open.ZCOM��z\\.\rzcould not open port {!r}: {!r}�iT)&Z_portr�is_open�name�upper�
startswith�int�
ValueErrorrZ
CreateFileZGENERIC_READZ
GENERIC_WRITEZ
OPEN_EXISTING�FILE_ATTRIBUTE_NORMALZFILE_FLAG_OVERLAPPEDrZINVALID_HANDLE_VALUE�formatZportstr�ctypes�WinErrorZ
OVERLAPPEDrZCreateEvent�hEventr�	SetupComm�COMMTIMEOUTS�_orgTimeoutsZGetCommTimeouts�byref�_reconfigure_port�	PurgeComm�
PURGE_TXCLEAR�
PURGE_TXABORT�
PURGE_RXCLEAR�
PURGE_RXABORT�_close)rZportr#r#r$�open!sR
"




zSerial.opencCs�|jstd��tj�}|jdkr"n*|jdkr6tj|_ntt|jd�d�|_	|jdkrv|j
dk	rvtt|j
d�d�|_|jdkr�n*|jdkr�tj|_ntt|jd�d�|_tj
|jtj|��tj|jtj�tj�}tj|jtj|��|j|_|jtjk�r
d|_nR|jtjk�r d|_n<|jtjk�r6d|_n&|jtjk�rLd	|_ntd
j|j���|jtj k�rztj!|_"d|_#n�|jtj$k�r�tj%|_"d|_#nj|jtj&k�r�tj'|_"d|_#nL|jtj(k�r�tj)|_"d|_#n.|jtj*k�r�tj+|_"d|_#ntdj|j���|j,tj-k�rtj.|_/n@|j,tj0k�r2tj1|_/n(|j,tj2k�rJtj3|_/ntdj|j,���d|_4|j5dk�r�|j6�r~tj7|_8n|j9�r�tj:ntj;|_8|j6|_<n�|j5j=�s�td
j|j5j=���|j5j>�r�tdj|j5j>���|j5j?dk	�r�tdj|j5j?���|j5j@dk	�rtdj|j5j@���|j5jA�r2tdj|j5jA���tjB|_8d|_<|jC�rRtjD|_En|jF�r`tjGntjH|_E|jC|_I|jJ|_K|jJ|_Ld|_Md|_Nd|_OtjP|_QtjR|_StjT|jtj|���s�tdjtjU����dS)z,Set communication parameters on opened port.z'Can only operate on a valid port handleNri�r'���r&z%Unsupported number of data bits: {!r}zUnsupported parity mode: {!r}z%Unsupported number of stop bits: {!r}z:Unsupported value for RS485Settings.rts_level_for_tx: {!r}z:Unsupported value for RS485Settings.rts_level_for_rx: {!r}z9Unsupported value for RS485Settings.delay_before_tx: {!r}z9Unsupported value for RS485Settings.delay_before_rx: {!r}z2Unsupported value for RS485Settings.loopback: {!r}zCCannot configure port, something went wrong. Original message: {!r})Vrrrr4Z_timeoutZMAXDWORDZReadIntervalTimeout�maxr,ZReadTotalTimeoutConstantZ_inter_byte_timeout�_write_timeoutZWriteTotalTimeoutConstant�SetCommTimeoutsr0r6ZSetCommMaskZEV_ERRZDCBZGetCommStateZ	_baudrateZBaudRateZ	_bytesize�serialZFIVEBITSZByteSizeZSIXBITSZ	SEVENBITSZ	EIGHTBITSr-r/Z_parityZPARITY_NONEZNOPARITYZParityZfParityZPARITY_EVENZ
EVENPARITYZ
PARITY_ODDZ	ODDPARITYZPARITY_MARKZ
MARKPARITYZPARITY_SPACEZSPACEPARITYZ	_stopbitsZSTOPBITS_ONEZ
ONESTOPBITZStopBitsZSTOPBITS_ONE_POINT_FIVEZONE5STOPBITSZSTOPBITS_TWOZTWOSTOPBITSZfBinaryZ_rs485_modeZ_rtsctsZRTS_CONTROL_HANDSHAKEZfRtsControl�
_rts_stateZRTS_CONTROL_ENABLEZRTS_CONTROL_DISABLEZfOutxCtsFlowZrts_level_for_txZrts_level_for_rxZdelay_before_txZdelay_before_rxZloopbackZRTS_CONTROL_TOGGLEZ_dsrdtrZDTR_CONTROL_HANDSHAKEZfDtrControl�
_dtr_stateZDTR_CONTROL_ENABLEZDTR_CONTROL_DISABLEZfOutxDsrFlowZ_xonxoffZfOutXZfInXZfNullZ
fErrorCharZ
fAbortOnErrorZXONZXonCharZXOFFZXoffCharZSetCommStater1)rZtimeoutsZcomDCBr#r#r$r7bs�














zSerial._reconfigure_portcCs||jdk	rxtj|j|j�|jdk	r@|j�tj|jj�d|_|jdk	rf|j	�tj|jj�d|_tj|j�d|_dS)zinternal close port helperN)
rrrDr5r�cancel_readZCloseHandler2r�cancel_write)rr#r#r$r=�s


z
Serial._closecCs|jr|j�d|_dS)z
Close portFN)r(r=)rr#r#r$�close�szSerial.closecCs:tj�}tj�}tj|jtj|�tj|��s4td��|jS)z9Return the number of bytes currently in the input buffer.zcall to ClearCommError failed)	r�DWORD�COMSTAT�ClearCommErrorrr0r6r�cbInQue)r�flags�comstatr#r#r$�
in_waiting�s
zSerial.in_waitingr'c
CsT|js
t�|dk�rFtj|jj�tj�}tj�}tj|j	t
j|�t
j|��s`tdj
t
j����|jdkrvt|j|�n|}|dk�r>t
j|�}tj�}tj|j	||t
j|�t
j|j��}|r�tj�tjtjfkr�tdj
t
j����tj|j	t
j|j�t
j|�d�}|�s,tj�tjk�r,tdj
t
j����|jd|j�}	nt�}	nt�}	t|	�S)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.
        rzClearCommError failed ({!r})zReadFile failed ({!r})Tz!GetOverlappedResult failed ({!r})N)r(rrZ
ResetEventrr2rKrLrMrr0r6rr/r1Ztimeout�minrNZcreate_string_bufferZReadFile�GetLastErrorZ
ERROR_SUCCESS�ERROR_IO_PENDING�GetOverlappedResult�ERROR_OPERATION_ABORTED�raw�value�bytes)
r�sizerOrP�nZbuf�rcZread_okZ	result_ok�readr#r#r$r]s@



zSerial.readcCs�|js
t�t|�}|r�tj�}tj|j|t|�tj	|�|j
�}|rdtj�tjkrdt
djtj����|jdkr�tj|j|j
tj	|�d�}tj�tjkr�|jS|jt|�kr�t�|jSdSdS)z2Output the given byte string over the serial port.zWriteFile failed ({!r})rTN)r(rrrrKZ	WriteFiler�lenr0r6rrSrTrr/r1rCrUrVrXr)r�datar[�errr#r#r$�write-s  
zSerial.writecCsx|jrtjd�qWdS)zb        Flush of file like objects. In this case, wait until all data
        is written.
        g�������?N)�out_waiting�timeZsleep)rr#r#r$�flushGszSerial.flushcCs$|js
t�tj|jtjtjB�dS)z9Clear input buffer, discarding all that is in the buffer.N)r(rrr8rr;r<)rr#r#r$�reset_input_bufferRszSerial.reset_input_buffercCs$|js
t�tj|jtjtjB�dS)zs        Clear output buffer, aborting the current output and discarding all
        that is in the buffer.
        N)r(rrr8rr9r:)rr#r#r$�reset_output_bufferXszSerial.reset_output_buffercCs.|js
t�|jrtj|j�ntj|j�dS)zBSet break: Controls TXD. When active, to transmitting is possible.N)r(rZ_break_staterZSetCommBreakrZClearCommBreak)rr#r#r$�_update_break_stateas
zSerial._update_break_statecCs,|jrtj|jtj�ntj|jtj�dS)z)Set terminal status line: Request To SendN)rFr�EscapeCommFunctionrZSETRTSZCLRRTS)rr#r#r$�_update_rts_statejszSerial._update_rts_statecCs,|jrtj|jtj�ntj|jtj�dS)z-Set terminal status line: Data Terminal ReadyN)rGrrhrZSETDTRZCLRDTR)rr#r#r$�_update_dtr_stateqszSerial._update_dtr_statecCs,|js
t�tj�}tj|jtj|��|jS)N)	r(rrrKZGetCommModemStatusrr0r6rX)r�statr#r#r$�_GetCommModemStatusxs
zSerial._GetCommModemStatuscCstj|j�@dkS)z(Read terminal status line: Clear To Sendr)rZ	MS_CTS_ONrl)rr#r#r$�ctssz
Serial.ctscCstj|j�@dkS)z)Read terminal status line: Data Set Readyr)rZ	MS_DSR_ONrl)rr#r#r$�dsr�sz
Serial.dsrcCstj|j�@dkS)z)Read terminal status line: Ring Indicatorr)rZ
MS_RING_ONrl)rr#r#r$�ri�sz	Serial.ricCstj|j�@dkS)z)Read terminal status line: Carrier Detectr)rZ
MS_RLSD_ONrl)rr#r#r$�cd�sz	Serial.cd�NcCs |dkr|}tj|j||�dS)z�        Recommend a buffer size to the driver (device driver can ignore this
        value). Must be called before the port is opended.
        N)rr3r)rZrx_sizeZtx_sizer#r#r$�set_buffer_size�szSerial.set_buffer_sizeTcCs4|js
t�|r tj|jtj�ntj|jtj�dS)a*        Manually control flow - when software flow control is enabled.
        This will do the same as if XON (true) or XOFF (false) are received
        from the other device and control the transmission accordingly.
        WARNING: this function is not portable to different platforms!
        N)r(rrrhrZSETXONZSETXOFF)r�enabler#r#r$�set_output_flow_control�s
zSerial.set_output_flow_controlcCs:tj�}tj�}tj|jtj|�tj|��s4td��|jS)z0Return how many bytes the in the outgoing bufferzcall to ClearCommError failed)	rrKrLrMrr0r6rZcbOutQue)rrOrPr#r#r$rb�s
zSerial.out_waitingcCsRtj�}tj|jtj|�tj|�d�}|rNtj�tjtjfkrNtj	|j|�dS)zACancel a blocking read operation, may be called from other threadFN)
rrKrUrr0r6rSrTZERROR_IO_INCOMPLETEZ
CancelIoEx)rZ
overlappedr\r`r#r#r$�_cancel_overlapped_io�szSerial._cancel_overlapped_iocCs|j|j�dS)zACancel a blocking read operation, may be called from other threadN)rur)rr#r#r$rH�szSerial.cancel_readcCs|j|j�dS)zBCancel a blocking write operation, may be called from other threadN)rur)rr#r#r$rI�szSerial.cancel_write)r	r
rrr
rrrrrrrrrrrr)r')rqN)T) �__name__�
__module__�__qualname__�__doc__Z	BAUDRATESrr>r7r=rJ�propertyrQr]rardrerfrgrirjrlrmrnrorprrrtrbrurHrI�
__classcell__r#r#)r"r$rs:A	
)		
	
	
r)r0rcrErZserial.serialutilrrrrrrr#r#r#r$�<module>
s


Filemanager

Name Type Size Permission Actions
__init__.cpython-36.opt-1.pyc File 2 KB 0644
__init__.cpython-36.pyc File 2 KB 0644
aio.cpython-36.opt-1.pyc File 14 KB 0644
aio.cpython-36.pyc File 14.18 KB 0644
rfc2217.cpython-36.opt-1.pyc File 31.88 KB 0644
rfc2217.cpython-36.pyc File 31.88 KB 0644
rs485.cpython-36.opt-1.pyc File 2.72 KB 0644
rs485.cpython-36.pyc File 2.72 KB 0644
serialcli.cpython-36.opt-1.pyc File 6.45 KB 0644
serialcli.cpython-36.pyc File 6.45 KB 0644
serialjava.cpython-36.opt-1.pyc File 7.08 KB 0644
serialjava.cpython-36.pyc File 7.08 KB 0644
serialposix.cpython-36.opt-1.pyc File 18.69 KB 0644
serialposix.cpython-36.pyc File 18.72 KB 0644
serialutil.cpython-36.opt-1.pyc File 16.04 KB 0644
serialutil.cpython-36.pyc File 16.04 KB 0644
serialwin32.cpython-36.opt-1.pyc File 12.11 KB 0644
serialwin32.cpython-36.pyc File 12.11 KB 0644
win32.cpython-36.opt-1.pyc File 6.15 KB 0644
win32.cpython-36.pyc File 6.15 KB 0644