a ¿;­VÞ ã@s@ddlTdd„Zdd„ZeddgƒZdd „ZGd d „d eƒZd S) é)Ú*cCs2t|ƒ}| d¡}|dd…D]}t||ƒ}q|S)NÚ.é)Ú __import__ÚsplitÚgetattr)ÚnameÚmodÚ componentsÚcomp©r ú5/usr/lib/python3.9/site-packages/serial/serialjava.pyÚ my_import s   rc CsF|D]4}zt|ƒ}|j|WSttfy6Yq0qtdƒ‚dS)z1try given list of modules and return that importsz/No Java Communications API implementation foundN)rÚ SerialPortÚ ImportErrorÚAttributeError)Ú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) ÚcommÚCommPortIdentifierZgetPortIdentifiersZhasMoreElementsZ nextElementZ getPortTypeZ PORT_SERIALÚappendÚgetName)Z portnumberÚenumZportsÚelr r r Údevice*s  rc@s¨eZdZdZdd„Zdd„Zdd„Zedd „ƒZd%d d „Z d d„Z dd„Z dd„Z d&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 CsÈ|jdurtdƒ‚|jr tdƒ‚t|jƒtdƒkrBtj |j¡}ntj t|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_portÚSerialExceptionÚis_openÚtyperrZgetPortIdentifierrÚopenÚsPortÚ ExceptionÚ_reconfigurePortZgetInputStreamÚ _instreamZgetOutputStreamÚ _outstream)ÚselfZportIdÚmsgr r r r!;s  "  z Serial.opencCsÖ|jstdƒ‚|j d¡|jtkr.tjj}nJ|jtkrBtjj }n6|jt krVtjj }n"|jt krjtjj }ntd|jƒ‚|jtkrŒtjj}n6|jtkr tjj}n"|jtkr´tjj}ntd|jƒ‚|jtkrÖtjj}nb|jtkrêtjj}nN|jtkrþtjj}n:|jtk�rtjj}n$|jtk�r*tjj}ntd|jƒ‚d}}|j�r`|tjjO}|tjjO}|j�r€|tjj O}|tjj!O}|j "|j#|||¡|j $||B¡|j%dk�rÈ|j t&|j%dƒ¡n |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: %rrièN)(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Ú_timeoutÚintZdisableReceiveTimeout)r'Z jdatabitsZ jstopbitsZjparityZjflowinZjflowoutr r r r$RsT                              zSerial._reconfigurePortcCs:|jr6|jr0|j ¡|j ¡|j ¡d|_d|_dS)z Close portNF)rr"r%Úcloser&©r'r r r r-‰s   z Serial.closecCs|js t‚|j ¡S)z>Return the number of characters currently in the input buffer.)r"ÚportNotOpenErrorr%Ú availabler.r r r Ú in_waiting•szSerial.in_waitingrcCsX|js t‚tƒ}|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/Ú bytearrayÚlenr%ÚreadÚtimeoutrÚbytes)r'Úsizer5Úxr r r r5œs    z Serial.readcCs@|js t‚t|ttfƒs,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 |j ¡¡dS)z9Clear input buffer, discarding all that is in the buffer.N)r"r/r%Úskipr0r.r r r Úreset_input_buffer¸szSerial.reset_input_buffercCs|js t‚|j ¡dS)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_buffer¾szSerial.reset_output_bufferçÐ?cCs|js t‚|j |d¡dS)zHSend break condition. Timed, returns to idle state after given duration.g@�@N)r"r/Z sendBreak)r'Zdurationr r r Ú send_breakÇszSerial.send_breakcCs|jdurt‚tdƒ‚dS)zBSet break: Controls TXD. When active, to transmitting is possible.Nz sþ