File: //usr/lib/python3.6/site-packages/serial/__pycache__/serialjava.cpython-36.pyc
3
M�]W� � @ s@ d dl T dd� Zdd� Zeddg�Zdd � ZG d
d� de�ZdS )
� )�*c C s6 t | �}| jd�}x|dd � D ]}t||�}q W |S )N�.� )�
__import__�split�getattr)�name�modZ
components�comp� r � /usr/lib/python3.6/serialjava.py� my_import
s
r
c
C sF x8| D ]0}yt |�}|j |S ttfk
r4 Y qX qW td��dS )z1try given list of modules and return that importsz/No Java Communications API implementation foundN)r
�
SerialPort�ImportError�AttributeError)�namesr r r r r �detect_java_comm s
r z
javax.commzgnu.ioc C sJ t jj� }g }x.|j� r<|j� }|j� t jjkr|j|� qW || j� S )z%Turn a port number into a device name) �comm�CommPortIdentifierZgetPortIdentifiersZhasMoreElementsZnextElementZgetPortTypeZPORT_SERIAL�appendZgetName)Z
portnumber�enumZportsZelr r r �device* s
r c @ s� e Zd ZdZdd� Zdd� Zdd� Zedd � �Zd%dd�Z d
d� Z
dd� Zdd� Zd&dd�Z
dd� Zdd� Zdd� Zedd� �Zedd� �Zed d!� �Zed"d#� �Zd$S )'�Serialz� Serial port class, implemented with Java Communications API and
thus usable with jython and the appropriate java extension.
c C s� | j dkrtd��| jr td��t| j �td�krBtjj| j �}ntjjt| j ��}y|jdd�| _ W n4 t
k
r� } zd| _ td| ��W Y dd}~X nX | j� | j j� | _
| j j� | _d| _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.� zpython serial module�
zCould not open port: %sT)Z_port�SerialException�is_open�typer r ZgetPortIdentifierr �open�sPort� Exception�_reconfigurePortZgetInputStream� _instreamZgetOutputStream�
_outstream)�selfZportId�msgr r r r ; s
zSerial.openc C s� | j std��| j jd� | jtkr.tjj}nJ| jtkrBtjj }n6| jt
krVtjj}n"| jtkrjtjj
}ntd| j ��| jtkr�tjj}n6| jtkr�tjj}n"| jtkr�tjj}ntd| j ��| jtkr�tjj}nd| jtkr�tjj}nP| jtk�r tjj}n:| jtk�rtjj}n$| jtk�r,tjj}ntd| j ��d }}| j�rb|tjjO }|tjjO }| j�r�|tjj O }|tjj!O }| j j"| j#|||� | j j$||B � | j%dk�r�| j jt&| j%d �� n
| j j'� dS ) z,Set communication parameters on opened port.z'Can only operate on a valid port handle� zunsupported bytesize: %rz"unsupported number of stopbits: %rzunsupported parity type: %rr i� N)(r r ZenableReceiveTimeoutZ _bytesizeZFIVEBITSr r Z
DATABITS_5ZSIXBITSZ
DATABITS_6Z SEVENBITSZ
DATABITS_7Z EIGHTBITSZ
DATABITS_8�
ValueErrorZ _stopbitsZSTOPBITS_ONEZ
STOPBITS_1ZSTOPBITS_ONE_POINT_FIVEZSTOPBITS_1_5ZSTOPBITS_TWOZ
STOPBITS_2Z_parityZPARITY_NONEZPARITY_EVENZ
PARITY_ODDZPARITY_MARKZPARITY_SPACEZ_rtsctsZFLOWCONTROL_RTSCTS_INZFLOWCONTROL_RTSCTS_OUTZ_xonxoffZFLOWCONTROL_XONXOFF_INZFLOWCONTROL_XONXOFF_OUTZsetSerialPortParamsZ _baudrateZsetFlowControlModeZ_timeout�intZdisableReceiveTimeout)r$ Z jdatabitsZ jstopbitsZjparityZjflowinZjflowoutr r r r! R sT
zSerial._reconfigurePortc C s: | j r6| jr0| jj� | jj� | jj� d| _d| _ dS )z
Close portNF)r r r"