o
    ^_#                     @   sL   d dl mZ 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 )    )absolute_importN)*c                 C   s   t dd | D S )Nc                 S   s   g | ]}t |qS  )ord).0xr   r   2/usr/lib/python3/dist-packages/serial/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dZdd Zdd Zdd Zed	d
 Z	d#d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d d! Zd"S )$Serialz)Serial port implementation for .NET/Mono.)2   K   n            i,  iX  i  i  i`	  i  i%  i K  i   i   i  c              
   C   s   | j du r	td| jrtdztjj| j| _W n t	y3 } zd| _td| j|f d}~ww | j
du r<d| _
| jdu rDd| _|   | j  d| _| jsW|   | js^|   |   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)_portSerialExceptionis_openSystemIOPorts
SerialPortportstr_port_handle	Exception
_rts_state
_dtr_state_reconfigure_portOpen_dsrdtr_update_dtr_state_rtscts_update_rts_statereset_input_buffer)selfmsgr   r   r   open   s.   



zSerial.openc              
   C   sp  | j std| jdu rtjjjj| j _n	t	| jd | j _| j
du r,tjjjj| j _n	t	| j
d | j _z| j| j _W n tyN } ztt|d}~ww | jtkrYd| j _n%| jtkrcd| j _n| jtkrmd| j _n| jtkrwd| j _ntd| j | jtkrttjjjd	| j _n?| jtkrtjjjj| j _n1| jtkrtjjjj| j _n#| 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 _%n#| j#t'krtjjj%j(| j _%n| j#t)krtjjj%j*| j _%ntd| j# | j+r| j,rtjjj-j.| j _-dS | j+rtjjj-j/| j _-dS | j,r,tjjj-j0| j _-dS 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   _timeoutr   r   r   r   InfiniteTimeoutReadTimeoutint_write_timeoutWriteTimeout	_baudrateBaudRateIOError
ValueErrorstr	_bytesizeFIVEBITSDataBitsSIXBITS	SEVENBITS	EIGHTBITS_parityPARITY_NONEgetattrParityPARITY_EVENEven
PARITY_ODDOddPARITY_MARKMarkPARITY_SPACESpace	_stopbitsSTOPBITS_ONEStopBitsOneSTOPBITS_ONE_POINT_FIVEOnePointFiveSTOPBITS_TWOTwor$   _xonxoff	HandshakeRequestToSendXOnXOffRequestToSendXOnXOff)r'   er   r   r   r    =   s`   

















zSerial._reconfigure_portc                 C   sH   | j r"| jrz| j  W n tjjjy   Y nw d| _d| _ dS dS )z
Close portNF)r   r   Closer   r   r   InvalidOperationExceptionr'   r   r   r   close   s   
zSerial.closec                 C      | j st | jjS )z>Return the number of characters currently in the input buffer.)r   PortNotOpenErrorr   BytesToReadr\   r   r   r   
in_waiting      zSerial.in_waiting   c                 C   sZ   | j st t }|r)z
|| j  W n tjy"   Y t|S w |d8 }|s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.
        rc   )	r   r_   	bytearrayappendr   ReadByter   TimeoutExceptionbytes)r'   sizedatar   r   r   read   s   zSerial.readc                 C   sH   | j st z| jt|dt| W t|S  tjy#   tdw )z-Output the given string over the serial port.r   zWrite timeout)	r   r_   r   Writer   lenr   rg   SerialTimeoutException)r'   rj   r   r   r   write   s   zSerial.writec                 C      | j st | j  dS )z9Clear input buffer, discarding all that is in the buffer.N)r   r_   r   DiscardInBufferr\   r   r   r   r&      s   zSerial.reset_input_bufferc                 C   rp   )zs        Clear output buffer, aborting the current output and
        discarding all that is in the buffer.
        N)r   r_   r   DiscardOutBufferr\   r   r   r   reset_output_buffer   s   zSerial.reset_output_bufferc                 C      | j st t| j| j_dS )zT
        Set break: Controls TXD. When active, to transmitting is possible.
        N)r   r_   bool_break_stater   
BreakStater\   r   r   r   _update_break_state   s   zSerial._update_break_statec                 C   rt   )z)Set terminal status line: Request To SendN)r   r_   ru   r   r   	RtsEnabler\   r   r   r   r%         zSerial._update_rts_statec                 C   rt   )z-Set terminal status line: Data Terminal ReadyN)r   r_   ru   r   r   	DtrEnabler\   r   r   r   r#      rz   zSerial._update_dtr_statec                 C   r^   )z(Read terminal status line: Clear To Send)r   r_   r   
CtsHoldingr\   r   r   r   cts   rb   z
Serial.ctsc                 C   r^   )z)Read terminal status line: Data Set Ready)r   r_   r   
DsrHoldingr\   r   r   r   dsr   rb   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   r^   )z)Read terminal status line: Carrier Detect)r   r_   r   	CDHoldingr\   r   r   r   cd   rb   z	Serial.cdN)rc   )__name__
__module____qualname____doc__	BAUDRATESr)   r    r]   propertyra   rk   ro   r&   rs   rx   r%   r#   r}   r   r   r   r   r   r   r   r      s.    H

	


r   )
__future__r   r   System.IO.Portsserial.serialutilArrayByter
   r   
SerialBaser   r   r   r   r   <module>   s   	