a zYW#@s@ddlZddlZddlTejejZddZGdddeZdS)N)*cCstdd|DS)NcSsg|] }t|qS)ord).0xrr4/usr/lib/python3.9/site-packages/serial/serialcli.py z!as_byte_array..)sab)stringrrr as_byte_arraysr c@seZdZdZdZddZddZddZed d Z d#d d Z ddZ ddZ ddZ ddZddZddZeddZeddZeddZed d!Zd"S)$Serialz)Serial port implementation for .NET/Mono.)2Kni,iXiii` ii%iKiiic Cs|jdurtd|jr tdztjj|j|_Wn<t yr}z$d|_td|j|fWYd}~n d}~00|j durd|_ |j durd|_ | |j d|_|js||js||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_portSerialExceptionis_openSystemIOPorts SerialPortZportstr _port_handle Exception _rts_state _dtr_state_reconfigure_portZOpenZ_dsrdtr_update_dtr_state_rtscts_update_rts_statereset_input_buffer)selfmsgrrropens* (   z Serial.openc Cs|jstd|jdur*tjjjj|j_nt |jd|j_|j durXtjjjj|j_ nt |j d|j_ z|j |j_ Wn0ty}ztt|WYd}~n d}~00|jtkrd|j_nJ|jtkrd|j_n6|jtkrd|j_n"|jtkrd|j_ntd|j|jtkr*ttjjjd |j_n|jtkrHtjjjj|j_nh|jtkrftjjjj|j_nJ|jtkrtjjjj |j_n,|jt!krtjjjj"|j_ntd |j|j#t$krtjjj%j&|j_%nJ|j#t'krtjjj%j(|j_%n,|j#t)kr tjjj%j*|j_%ntd |j#|j+r:|j,r:tjjj-j.|j_-nH|j+rTtjjj-j/|j_-n.|j,rntjjj-j0|j_-nttjjj-d |j_-dS) z,Set communication parameters on opened port.z'Can only operate on a valid port handleNiz#Unsupported number of data bits: %rNonezUnsupported parity mode: %rz#Unsupported number of stop bits: %r)1rr_timeoutrrrrZInfiniteTimeoutZ ReadTimeoutintZ_write_timeoutZ WriteTimeoutZ _baudrateZBaudRateIOError ValueErrorstrZ _bytesizeZFIVEBITSZDataBitsZSIXBITSZ SEVENBITSZ EIGHTBITSZ_parityZ PARITY_NONEgetattrZParityZ PARITY_EVENZEvenZ PARITY_ODDZOddZ PARITY_MARKZMarkZ PARITY_SPACEZSpaceZ _stopbitsZ STOPBITS_ONEZStopBitsZOneZSTOPBITS_ONE_POINT_FIVEZ OnePointFiveZ STOPBITS_TWOZTwor Z_xonxoffZ HandshakeZRequestToSendXOnXOffZ RequestToSendZXOnXOff)r#errrr;s\  "                zSerial._reconfigure_portcCsD|jr@|jr:z|jWntjjjy2Yn0d|_d|_dS)z Close portNF)rrZCloserrrZInvalidOperationExceptionr#rrrclosesz Serial.closecCs|js t|jjS)z>Return the number of characters currently in the input buffer.)rportNotOpenErrorrZ BytesToReadr2rrr in_waitingszSerial.in_waitingcCsT|js tt}|rLz||jWntjy@YqLYq0|d8}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. r6) rr4 bytearrayappendrZReadByterTimeoutExceptionbytes)r#sizedatarrrreads  z Serial.readcCsH|js tz|jt|dt|Wntjy>tYn0t|S)z-Output the given string over the serial port.r) rr4rZWriter lenrr9ZwriteTimeoutError)r#r<rrrwrites z Serial.writecCs|js t|jdS)z9Clear input buffer, discarding all that is in the buffer.N)rr4rZDiscardInBufferr2rrrr"szSerial.reset_input_buffercCs|js t|jdS)zs Clear output buffer, aborting the current output and discarding all that is in the buffer. N)rr4rZDiscardOutBufferr2rrrreset_output_bufferszSerial.reset_output_buffercCs|js tt|j|j_dS)zT Set break: Controls TXD. When active, to transmitting is possible. N)rr4boolZ _break_staterZ BreakStater2rrr_update_break_stateszSerial._update_break_statecCs|js tt|j|j_dS)z)Set terminal status line: Request To SendN)rr4rArrZ RtsEnabler2rrrr!szSerial._update_rts_statecCs|js tt|j|j_dS)z-Set terminal status line: Data Terminal ReadyN)rr4rArrZ DtrEnabler2rrrrszSerial._update_dtr_statecCs|js t|jjS)z(Read terminal status line: Clear To Send)rr4rZ CtsHoldingr2rrrctssz Serial.ctscCs|js t|jjS)z)Read terminal status line: Data Set Ready)rr4rZ DsrHoldingr2rrrdsrsz Serial.dsrcCs|js tdS)z)Read terminal status line: Ring IndicatorF)rr4r2rrrrisz Serial.ricCs|js t|jjS)z)Read terminal status line: Carrier Detect)rr4rZ CDHoldingr2rrrcdsz Serial.cdN)r6)__name__ __module__ __qualname____doc__Z BAUDRATESr%rr3propertyr5r=r?r"r@rBr!rrCrDrErFrrrrr s,H      r ) rZSystem.IO.PortsZserial.serialutilZArrayZByter r Z SerialBaser rrrr s