3 M�]W�# � @ s@ d dl Z d dlZ d dlT e je j Zdd� ZG dd� de�ZdS )� N)�*c C s t dd� | D ��S )Nc S s g | ]}t |��qS � )�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 Zd ZdZd3Zdd� Zdd� Zdd� Zedd� �Z d4dd�Z dd� Zd d!� Zd"d#� Z d$d%� Zd&d'� Zd(d)� Zed*d+� �Zed,d-� �Zed.d/� �Zed0d1� �Zd2S )5�Serialz)Serial port implementation for .NET/Mono.�2 �K �n � � �� �, �X � � �` � �% � K � � � � � � c C s� | j dkrtd��| jr td��ytjjj| j�| _W n: t k rp } zd| _td| j|f ��W Y dd}~X nX | j dkr�d| _ | jdkr�d| _| j� | jj � d| _| js�| j� | js�| j� | j� 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.zcould not open port %s: %sT)Z_port�SerialException�is_open�System�IO�Ports� SerialPortZportstr�_port_handle� Exception� _rts_state� _dtr_state�_reconfigure_portZOpenZ_dsrdtr�_update_dtr_state�_rtscts�_update_rts_state�reset_input_buffer)�self�msgr r r �open s* $ zSerial.openc C s� | j std��| jdkr*tjjjj| j _nt | jd �| j _| j dkrXtjjjj| j _nt | j d �| j _y| j| j _ W n. tk r� } ztt|���W Y dd}~X nX | jtkr�d| j _nJ| jtkr�d| j _n6| jtkr�d| j _n"| jtkr�d| j _ntd| j ��| jtk�r(ttjjjd �| j _n�| jtk�rFtjjjj| j _nh| jtk�rdtjjjj| j _nJ| jtk�r�tjjjj | j _n,| jt!k�r�tjjjj"| j _ntd | j ��| j#t$k�r�tjjj%j&| j _%nJ| j#t'k�r�tjjj%j(| j _%n,| j#t)k�rtjjj%j*| j _%ntd| j# ��| j+�r8| j,�r8tjjj-j.| j _-nH| j+�rRtjjj-j/| j _-n.| j,�rltjjj-j0| j _-nttjjj-d �| j _-dS )z,Set communication parameters on opened port.z'Can only operate on a valid port handleNi� � � � � z#Unsupported number of data bits: %r�NonezUnsupported parity mode: %rz#Unsupported number of stop bits: %r)1r$ r Z_timeoutr r! r"