a ;V @s@ddlTddZddZeddgZdd ZGd d d eZd S) )*cCs2t|}|d}|ddD]}t||}q|S)N.) __import__splitgetattr)namemod componentscompr 5/usr/lib/python3.9/site-packages/serial/serialjava.py my_import s   rc CsF|D]4}zt|}|j|WSttfy6Yq0qtddS)z1try given list of modules and return that importsz/No Java Communications API implementation foundN)r SerialPort ImportErrorAttributeError)namesrr r r r detect_java_comms rz javax.commzgnu.iocCsFtj}g}|r:|}|tjjkr||q||S)z%Turn a port number into a device name) commCommPortIdentifierZgetPortIdentifiersZhasMoreElementsZ nextElementZ getPortTypeZ PORT_SERIALappendgetName)Z portnumberenumZportselr r r device*s  rc@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|jdurtd|jr tdt|jtdkrBtj|j}ntjt|j}z|dd|_ Wn6t y}zd|_ td|WYd}~n d}~00| |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_portSerialExceptionis_opentyperrZgetPortIdentifierropensPort Exception_reconfigurePortZgetInputStream _instreamZgetOutputStream _outstream)selfZportIdmsgr r r r!;s  "  z Serial.opencCs|jstd|jd|jtkr.tjj}nJ|jtkrBtjj }n6|jt krVtjj }n"|jt krjtjj }ntd|j|jtkrtjj}n6|jtkrtjj}n"|jtkrtjj}ntd|j|jtkrtjj}nb|jtkrtjj}nN|jtkrtjj}n:|jtkrtjj}n$|jtkr*tjj}ntd|jd}}|jr`|tjjO}|tjjO}|jr|tjj O}|tjj!O}|j"|j#||||j$||B|j%dkr|jt&|j%dn |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"rZenableReceiveTimeoutZ _bytesizeZFIVEBITSrrZ DATABITS_5ZSIXBITSZ DATABITS_6Z SEVENBITSZ DATABITS_7Z EIGHTBITSZ DATABITS_8 ValueErrorZ _stopbitsZ STOPBITS_ONEZ STOPBITS_1ZSTOPBITS_ONE_POINT_FIVEZ STOPBITS_1_5Z STOPBITS_TWOZ STOPBITS_2Z_parityZ PARITY_NONEZ PARITY_EVENZ PARITY_ODDZ PARITY_MARKZ PARITY_SPACEZ_rtsctsZFLOWCONTROL_RTSCTS_INZFLOWCONTROL_RTSCTS_OUTZ_xonxoffZFLOWCONTROL_XONXOFF_INZFLOWCONTROL_XONXOFF_OUTZsetSerialPortParamsZ _baudrateZsetFlowControlMode_timeoutintZdisableReceiveTimeout)r'Z jdatabitsZ jstopbitsZjparityZjflowinZjflowoutr r r r$RsT                              zSerial._reconfigurePortcCs:|jr6|jr0|j|j|jd|_d|_dS)z Close portNF)rr"r%closer&r'r r r r-s   z Serial.closecCs|js t|jS)z>Return the number of characters currently in the input buffer.)r"portNotOpenErrorr% availabler.r r r in_waitingszSerial.in_waitingrcCsX|js tt}|dkrPt||krP|j}|dkrD|jdkrNqPq||qt|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/ bytearraylenr%readtimeoutrbytes)r'sizer5xr r r r5s    z Serial.readcCs@|js tt|ttfs,tdtt|f|j|t |S)z-Output the given string over the serial port.z expected %s or bytearray, got %s) r"r/ isinstancer7r3 TypeErrorr r&writer4)r'datar r r r<s  z Serial.writecCs |js t|j|jdS)z9Clear input buffer, discarding all that is in the buffer.N)r"r/r%skipr0r.r r r reset_input_bufferszSerial.reset_input_buffercCs|js t|jdS)zs Clear output buffer, aborting the current output and discarding all that is in the buffer. N)r"r/r&flushr.r r r reset_output_bufferszSerial.reset_output_buffer?cCs|js t|j|ddS)zHSend break condition. Timed, returns to idle state after given duration.g@@N)r"r/Z sendBreak)r'Zdurationr r r send_breakszSerial.send_breakcCs|jdurttddS)zBSet break: Controls TXD. When active, to transmitting is possible.Nz s