
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
M]W#                 @   s@   d dl Z d dlZ d dlT e je j Zdd ZG dd deZdS )    N)*c             C   s   t dd | D S )Nc             S   s   g | ]}t |qS  )ord).0xr   r   /usr/lib/python3.6/serialcli.py
<listcomp>   s    z!as_byte_array.<locals>.<listcomp>)sab)stringr   r   r   as_byte_array   s    r   c               @   s   e Zd ZdZd3Zdd Zdd Zdd Zedd Z	d4ddZ
dd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zed*d+ Zed,d- Zed.d/ Zed0d1 Zd2S )5Serialz)Serial port implementation for .NET/Mono.2   K   n            ,  X      `	    %   K          c             C   s   | j dkrtd| jr tdytjjj| j| _W n: t	k
rp } zd| _td| j|f W Y dd}~X nX | j
dkrd| _
| jdkrd| _| j  | jj  d| _| js| j  | js| j  | j  dS )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.zPort is already open.zcould not open port %s: %sT)Z_portSerialExceptionis_openSystemIOPorts
SerialPortZportstr_port_handle	Exception
_rts_state
_dtr_state_reconfigure_portZOpenZ_dsrdtr_update_dtr_state_rtscts_update_rts_statereset_input_buffer)selfmsgr   r   r   open   s*    
$


zSerial.openc             C   s  | j std| jdkr*tjjjj| j _nt	| jd | j _| j
dkrXtjjjj| j _nt	| j
d | j _y| j| j _W n. tk
r } ztt|W Y dd}~X nX | jtkrd| j _nJ| jtkrd| j _n6| jtkrd| j _n"| jtkrd| j _ntd| j | jtkr(ttjjjd	| j _n| jtkrFtjjjj| j _nh| jtkrdtjjjj| j _nJ| jtkrtjjjj | j _n,| jt!krtjjjj"| j _ntd
| j | j#t$krtjjj%j&| j _%nJ| j#t'krtjjj%j(| j _%n,| j#t)krtjjj%j*| j _%ntd| j# | j+r8| j,r8tjjj-j.| j _-nH| j+rRtjjj-j/| j _-n.| j,rltjjj-j0| j _-nttjjj-d	| j _-dS )z,Set communication parameters on opened port.z'Can only operate on a valid port handleNi              z#Unsupported number of data bits: %rNonezUnsupported parity mode: %rz#Unsupported number of stop bits: %r)1r$   r   Z_timeoutr    r!   r"   r#   ZInfiniteTimeoutZReadTimeoutintZ_write_timeoutZWriteTimeoutZ	_baudrateZBaudRateIOError
ValueErrorstrZ	_bytesizeZFIVEBITSZDataBitsZSIXBITSZ	SEVENBITSZ	EIGHTBITSZ_parityZPARITY_NONEgetattrZParityZPARITY_EVENZEvenZ
PARITY_ODDZOddZPARITY_MARKZMarkZPARITY_SPACEZSpaceZ	_stopbitsZSTOPBITS_ONEZStopBitsZOneZSTOPBITS_ONE_POINT_FIVEZOnePointFiveZSTOPBITS_TWOZTwor*   Z_xonxoffZ	HandshakeZRequestToSendXOnXOffZRequestToSendZXOnXOff)r-   er   r   r   r(   ;   s\    









zSerial._reconfigure_portc             C   sF   | j rB| jr<y| jj  W n tjjjk
r4   Y nX d| _d| _ dS )z
Close portNF)r   r$   ZCloser    r!   r"   ZInvalidOperationException)r-   r   r   r   close   s    zSerial.closec             C   s   | j s
t| jjS )z>Return the number of characters currently in the input buffer.)r   portNotOpenErrorr$   ZBytesToRead)r-   r   r   r   
in_waiting   s    zSerial.in_waiting   c             C   sX   | j s
tt }x>|rNy|j| jj  W n tjk
rB   P Y qX |d8 }qW 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.
        r>   )	r   r<   	bytearrayappendr$   ZReadByter    TimeoutExceptionbytes)r-   sizedatar   r   r   read   s    zSerial.readc             C   sJ   | j s
ty| jjt|dt| W n tjk
r@   tY nX t|S )z-Output the given string over the serial port.r   )	r   r<   r$   ZWriter   lenr    rA   ZwriteTimeoutError)r-   rD   r   r   r   write   s    
zSerial.writec             C   s   | j s
t| jj  dS )z9Clear input buffer, discarding all that is in the buffer.N)r   r<   r$   ZDiscardInBuffer)r-   r   r   r   r,      s    zSerial.reset_input_bufferc             C   s   | j s
t| jj  dS )zs        Clear output buffer, aborting the current output and
        discarding all that is in the buffer.
        N)r   r<   r$   ZDiscardOutBuffer)r-   r   r   r   reset_output_buffer   s    zSerial.reset_output_bufferc             C   s   | j s
tt| j| j_dS )zT
        Set break: Controls TXD. When active, to transmitting is possible.
        N)r   r<   boolZ_break_stater$   Z
BreakState)r-   r   r   r   _update_break_state   s    zSerial._update_break_statec             C   s   | j s
tt| j| j_dS )z)Set terminal status line: Request To SendN)r   r<   rI   r&   r$   Z	RtsEnable)r-   r   r   r   r+      s    zSerial._update_rts_statec             C   s   | j s
tt| j| j_dS )z-Set terminal status line: Data Terminal ReadyN)r   r<   rI   r'   r$   Z	DtrEnable)r-   r   r   r   r)      s    zSerial._update_dtr_statec             C   s   | j s
t| jjS )z(Read terminal status line: Clear To Send)r   r<   r$   Z
CtsHolding)r-   r   r   r   cts   s    z
Serial.ctsc             C   s   | j s
t| jjS )z)Read terminal status line: Data Set Ready)r   r<   r$   Z
DsrHolding)r-   r   r   r   dsr   s    z
Serial.dsrc             C   s   | j s
tdS )z)Read terminal status line: Ring IndicatorF)r   r<   )r-   r   r   r   ri   s    z	Serial.ric             C   s   | j s
t| jjS )z)Read terminal status line: Carrier Detect)r   r<   r$   Z	CDHolding)r-   r   r   r   cd   s    z	Serial.cdN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r>   )__name__
__module____qualname____doc__Z	BAUDRATESr/   r(   r;   propertyr=   rE   rG   r,   rH   rJ   r+   r)   rK   rL   rM   rN   r   r   r   r   r      s$    H
	r   )	r    ZSystem.IO.PortsZserial.serialutilZArrayZByter	   r   Z
SerialBaser   r   r   r   r   <module>
   s
   