o ^_ !@sLddlmZddlTddZddZeddgZd d ZGd d d eZd S))absolute_import)*cCs2t|}|d}|ddD]}t||}q|S)N.) __import__splitgetattr)namemod componentscompr 3/usr/lib/python3/dist-packages/serial/serialjava.py my_imports   rc Cs@|D]}z t|}|j|WSttfyYqwtd)z1try given list of modules and return that importsz/No Java Communications API implementation found)r SerialPort ImportErrorAttributeError)namesr r r r rdetect_java_comms rz javax.commzgnu.iocCsLtj}g}|r |}|tjjkr|||s ||S)z%Turn a port number into a device name) commCommPortIdentifiergetPortIdentifiershasMoreElements nextElement getPortType PORT_SERIALappendgetName) portnumberenumportselr r rdevice,s   r"c@seZdZdZddZddZddZedd Zd%d d Z d dZ ddZ ddZ d&ddZ ddZddZddZeddZeddZed 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 Cs|jdur td|jrtdt|jtdkr!tj|j}n tjt|j}z |dd|_ Wnt yH}z d|_ td|d}~ww| |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)_portSerialExceptionis_opentyperrgetPortIdentifierr"opensPort Exception_reconfigurePortgetInputStream _instreamgetOutputStream _outstream)selfportIdmsgr r rr+=s$     z Serial.opencCs|jstd|jd|jtkrtjj}n%|jtkr!tjj }n|jt kr+tjj }n|jt kr5tjj }ntd|j|jtkrFtjj}n|jtkrPtjj}n|jtkrZtjj}ntd|j|jtkrktjj}n/|jtkrutjj}n%|jtkrtjj}n|jtkrtjj}n|jtkrtjj}ntd|jd}}|jr|tjjO}|tjjO}|jr|tjj O}|tjj!O}|j"|j#||||j$||B|j%dkr|jt&|j%ddS|j'dS) z,Set communication parameters on opened port.z'Can only operate on a valid port handlezunsupported bytesize: %rz"unsupported number of stopbits: %rzunsupported parity type: %rriN)(r,r'enableReceiveTimeout _bytesizeFIVEBITSrr DATABITS_5SIXBITS DATABITS_6 SEVENBITS DATABITS_7 EIGHTBITS DATABITS_8 ValueError _stopbits STOPBITS_ONE STOPBITS_1STOPBITS_ONE_POINT_FIVE STOPBITS_1_5 STOPBITS_TWO STOPBITS_2_parity PARITY_NONE PARITY_EVEN PARITY_ODD PARITY_MARK PARITY_SPACE_rtsctsFLOWCONTROL_RTSCTS_INFLOWCONTROL_RTSCTS_OUT_xonxoffFLOWCONTROL_XONXOFF_INFLOWCONTROL_XONXOFF_OUTsetSerialPortParams _baudratesetFlowControlMode_timeoutintdisableReceiveTimeout)r3 jdatabits jstopbitsjparityjflowinjflowoutr r rr.TsT                              zSerial._reconfigurePortcCs>|jr|jr|j|j|jd|_d|_dSdS)z Close portNF)r(r,r0closer2r3r r rr`s    z Serial.closecCs|jst|jS)z>Return the number of characters currently in the input buffer.)r,PortNotOpenErrorr0 availablerar r r in_waitings zSerial.in_waitingrcCsl|jstt}|dkr2t||kr2|j}|dkr'|jdkr& t|Sn||t||kst|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,rb bytearraylenr0readtimeoutrbytes)r3sizerhxr r rrhs     z Serial.readcCsB|jstt|ttfstdtt|f|j|t |S)z-Output the given string over the serial port.z expected %s or bytearray, got %s) r,rb isinstancerjrf TypeErrorr)r2writerg)r3datar r rros  z Serial.writecCs"|jst|j|jdS)z9Clear input buffer, discarding all that is in the buffer.N)r,rbr0skiprcrar r rreset_input_bufferszSerial.reset_input_buffercCs|jst|jdS)zs Clear output buffer, aborting the current output and discarding all that is in the buffer. N)r,rbr2flushrar r rreset_output_bufferszSerial.reset_output_buffer?cCs |jst|j|ddS)zHSend break condition. Timed, returns to idle state after given duration.g@@N)r,rb sendBreak)r3durationr r r send_breakszSerial.send_breakcCs|jdurttd)zBSet break: Controls TXD. When active, to transmitting is possible.Nzs