<commit_before>==============
 pySerial API
==============

.. module:: serial

Classes
=======

Native ports
------------

.. class:: Serial

    .. method:: __init__(port=None, baudrate=9600, bytesize=EIGHTBITS, parity=PARITY_NONE, stopbits=STOPBITS_ONE, timeout=None, xonxoff=False, rtscts=False, write_timeout=None, dsrdtr=False, inter_byte_timeout=None)

        :param port:
            Device name or :const:`None`.

        :param int baudrate:
            Baud rate such as 9600 or 115200 etc.

        :param bytesize:
            Number of data bits. Possible values:
            :const:`FIVEBITS`, :const:`SIXBITS`, :const:`SEVENBITS`,
            :const:`EIGHTBITS`

        :param parity:
            Enable parity checking. Possible values:
            :const:`PARITY_NONE`, :const:`PARITY_EVEN`, :const:`PARITY_ODD`
            :const:`PARITY_MARK`, :const:`PARITY_SPACE`

        :param stopbits:
            Number of stop bits. Possible values:
            :const:`STOPBITS_ONE`, :const:`STOPBITS_ONE_POINT_FIVE`,
            :const:`STOPBITS_TWO`

        :param float timeout:
            Set a read timeout value.

        :param bool xonxoff:
            Enable software flow control.

        :param bool rtscts:
            Enable hardware (RTS/CTS) flow control.

        :param bool dsrdtr:
            Enable hardware (DSR/DTR) flow control.

        :param float write_timeout:
            Set a write timeout value.

        :param float inter_byte_timeout:
            Inter-character timeout, :const:`None` to disable (default).

        :exception ValueError:
            Will be raised when parameter are out of range, e.g. baud rate, data bits.

        :exception SerialException:
            In case the device can not be found or can not be configured.


        The port is immediately opened on object creation, when a *port* is
        given. It is not opened when *port* is :const:`None` and a successive call
        to :meth:`open` is required.

        *port* is a device name: depending on operating system. e.g.
        ``/dev/ttyUSB0`` on GNU/Linux or ``COM3`` on Windows.

        The parameter *baudrate* can be one of the standard values:
        50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
        9600, 19200, 38400, 57600, 115200.
        These are well supported on all platforms.

        Standard values above 115200, such as: 230400, 460800, 500000, 576000,
        921600, 1000000, 1152000, 1500000, 2000000, 2500000, 3000000, 3500000,
        4000000 also work on many platforms and devices.

        Non-standard values are also supported on some platforms (GNU/Linux, MAC
        OSX >= Tiger, Windows). Though, even on these platforms some serial
        ports may reject non-standard values.

        Possible values for the parameter *timeout* which controls the behavior
        of :meth:`read`:

        - ``timeout = None``:  wait forever / until requested number of bytes
          are received
        - ``timeout = 0``:     non-blocking mode, return immediately in any case,
          returning zero or more, up to the requested number of bytes
        - ``timeout = x``:     set timeout to ``x`` seconds (float allowed)
          returns immediately when the requested number of bytes are available,
          otherwise wait until the timeout expires and return all bytes that
          were received until then.

        :meth:`write` is blocking by default, unless *write_timeout* is set.
        For possible values refer to the list for *timeout* above.

        Note that enabling both flow control methods (*xonxoff* and *rtscts*)
        together may not be supported. It is common to use one of the methods
        at once, not both.

        *dsrdtr* is not supported by all platforms (silently ignored). Setting
        it to ``None`` has the effect that its state follows *rtscts*.

        Also consider using the function :func:`serial_for_url` instead of
        creating Serial instances directly.

        .. versionchanged:: 2.5
            *dsrdtr* now defaults to ``False`` (instead of *None*)
        .. versionchanged:: 3.0 numbers as *port* argument are no longer supported

    .. method:: open()

        Open port.

    .. method:: close()

        Close port immediately.

    .. method:: __del__()

        Destructor, close port when serial port instance is freed.


    The following methods may raise :exc:`SerialException` when applied to a closed
    port.

    .. method:: read(size=1)

        :param size: Number of bytes to read.
        :return: Bytes read from the port.
        :rtype: bytes

        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.

        .. versionchanged:: 2.5
            Returns an instance of :class:`bytes` when available (Python 2.6
            and newer) and :class:`str` otherwise.

    .. method:: write(data)

        :param data: Data to send.
        :return: Number of bytes written.
        :rtype: int
        :exception SerialTimeoutException:
            In case a write timeout is configured for the port and the time is
            exceeded.

        Write the bytes *data* to the port. This should be of type ``bytes``
        (or compatible such as ``bytearray`` or ``memoryview``). Unicode
        strings must be encoded (e.g. ``'hello'.encode('utf-8'``).

    .. versionchanged:: 2.5
            Accepts instances of :class:`bytes` and :class:`bytearray` when
            available (Python 2.6 and newer) and :class:`str` otherwise.

        .. versionchanged:: 2.5
            Write returned ``None`` in previous versions.

    .. method:: flush()

        Flush of file like objects. In this case, wait until all data is
        written.

    .. attribute:: in_waiting

        :getter: Get the number of bytes in the input buffer
        :type: int

        Return the number of bytes in the receive buffer.

        .. versionchanged:: 3.0 changed to property from ``inWaiting()``

    .. attribute:: out_waiting

        :getter: Get the number of bytes in the output buffer
        :type: int
        :platform: Posix
        :platform: Windows

        Return the number of bytes in the output buffer.

        .. versionchanged:: 2.7 (Posix support added)
        .. versionchanged:: 3.0 changed to property from ``outWaiting()``

    .. method:: reset_input_buffer()

        Flush input buffer, discarding all it's contents.

        .. versionchanged:: 3.0 renamed from ``flushInput()``

    .. method:: reset_output_buffer()

        Clear output buffer, aborting the current output and
        discarding all that is in the buffer.

        .. versionchanged:: 3.0 renamed from ``flushOutput()``

    .. method:: send_break(duration=0.25)

        :param float duration: Time to activate the BREAK condition.

        Send break condition. Timed, returns to idle state after given
        duration.


    .. attribute:: break_condition

        :getter: Get the current BREAK state
        :setter: Control the BREAK state
        :type: bool

        When set to ``True`` activate BREAK condition, else disable.
        Controls TXD. When active, no transmitting is possible.

    .. attribute:: rts

        :setter: Set the state of the RTS line
        :getter: Return the state of the RTS line
        :type: bool

        Set RTS line to specified logic level. It is possible to assign this
        value before opening the serial port, then the value is applied uppon
        :meth:`open`.<commit_msg>doc: add note about reset_ouput_buffer and USB devices<commit_after>==============
 pySerial API
==============

.. module:: serial

Classes
=======

Native ports
------------

.. class:: Serial

    .. method:: __init__(port=None, baudrate=9600, bytesize=EIGHTBITS, parity=PARITY_NONE, stopbits=STOPBITS_ONE, timeout=None, xonxoff=False, rtscts=False, write_timeout=None, dsrdtr=False, inter_byte_timeout=None)

        :param port:
            Device name or :const:`None`.

        :param int baudrate:
            Baud rate such as 9600 or 115200 etc.

        :param bytesize:
            Number of data bits. Possible values:
            :const:`FIVEBITS`, :const:`SIXBITS`, :const:`SEVENBITS`,
            :const:`EIGHTBITS`

        :param parity:
            Enable parity checking. Possible values:
            :const:`PARITY_NONE`, :const:`PARITY_EVEN`, :const:`PARITY_ODD`
            :const:`PARITY_MARK`, :const:`PARITY_SPACE`

        :param stopbits:
            Number of stop bits. Possible values:
            :const:`STOPBITS_ONE`, :const:`STOPBITS_ONE_POINT_FIVE`,
            :const:`STOPBITS_TWO`

        :param float timeout:
            Set a read timeout value.

        :param bool xonxoff:
            Enable software flow control.

        :param bool rtscts:
            Enable hardware (RTS/CTS) flow control.

        :param bool dsrdtr:
            Enable hardware (DSR/DTR) flow control.

        :param float write_timeout:
            Set a write timeout value.

        :param float inter_byte_timeout:
            Inter-character timeout, :const:`None` to disable (default).

        :exception ValueError:
            Will be raised when parameter are out of range, e.g. baud rate, data bits.

        :exception SerialException:
            In case the device can not be found or can not be configured.


        The port is immediately opened on object creation, when a *port* is
        given. It is not opened when *port* is :const:`None` and a successive call
        to :meth:`open` is required.

        *port* is a device name: depending on operating system. e.g.
        ``/dev/ttyUSB0`` on GNU/Linux or ``COM3`` on Windows.

        The parameter *baudrate* can be one of the standard values:
        50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
        9600, 19200, 38400, 57600, 115200.
        These are well supported on all platforms.

        Standard values above 115200, such as: 230400, 460800, 500000, 576000,
        921600, 1000000, 1152000, 1500000, 2000000, 2500000, 3000000, 3500000,
        4000000 also work on many platforms and devices.

        Non-standard values are also supported on some platforms (GNU/Linux, MAC
        OSX >= Tiger, Windows). Though, even on these platforms some serial
        ports may reject non-standard values.

        Possible values for the parameter *timeout* which controls the behavior
        of :meth:`read`:

        - ``timeout = None``:  wait forever / until requested number of bytes
          are received
        - ``timeout = 0``:     non-blocking mode, return immediately in any case,
          returning zero or more, up to the requested number of bytes
        - ``timeout = x``:     set timeout to ``x`` seconds (float allowed)
          returns immediately when the requested number of bytes are available,
          otherwise wait until the timeout expires and return all bytes that
          were received until then.

        :meth:`write` is blocking by default, unless *write_timeout* is set.
        For possible values refer to the list for *timeout* above.

        Note that enabling both flow control methods (*xonxoff* and *rtscts*)
        together may not be supported. It is common to use one of the methods
        at once, not both.

        *dsrdtr* is not supported by all platforms (silently ignored). Setting
        it to ``None`` has the effect that its state follows *rtscts*.

        Also consider using the function :func:`serial_for_url` instead of
        creating Serial instances directly.

        .. versionchanged:: 2.5
            *dsrdtr* now defaults to ``False`` (instead of *None*)
        .. versionchanged:: 3.0 numbers as *port* argument are no longer supported

    .. method:: open()

        Open port.

    .. method:: close()

        Close port immediately.

    .. method:: __del__()

        Destructor, close port when serial port instance is freed.


    The following methods may raise :exc:`SerialException` when applied to a closed
    port.

    .. method:: read(size=1)

        :param size: Number of bytes to read.
        :return: Bytes read from the port.
        :rtype: bytes

        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.

        .. versionchanged:: 2.5
            Returns an instance of :class:`bytes` when available (Python 2.6
            and newer) and :class:`str` otherwise.

    .. method:: write(data)

        :param data: Data to send.
        :return: Number of bytes written.
        :rtype: int
        :exception SerialTimeoutException:
            In case a write timeout is configured for the port and the time is
            exceeded.

        Write the bytes *data* to the port. This should be of type ``bytes``
        (or compatible such as ``bytearray`` or ``memoryview``). Unicode
        strings must be encoded (e.g. ``'hello'.encode('utf-8'``).

    .. versionchanged:: 2.5
            Accepts instances of :class:`bytes` and :class:`bytearray` when
            available (Python 2.6 and newer) and :class:`str` otherwise.

        .. versionchanged:: 2.5
            Write returned ``None`` in previous versions.

    .. method:: flush()

        Flush of file like objects. In this case, wait until all data is
        written.

    .. attribute:: in_waiting

        :getter: Get the number of bytes in the input buffer
        :type: int

        Return the number of bytes in the receive buffer.

        .. versionchanged:: 3.0 changed to property from ``inWaiting()``

    .. attribute:: out_waiting

        :getter: Get the number of bytes in the output buffer
        :type: int
        :platform: Posix
        :platform: Windows

        Return the number of bytes in the output buffer.

        .. versionchanged:: 2.7 (Posix support added)
        .. versionchanged:: 3.0 changed to property from ``outWaiting()``

    .. method:: reset_input_buffer()

        Flush input buffer, discarding all it's contents.

        .. versionchanged:: 3.0 renamed from ``flushInput()``

    .. method:: reset_output_buffer()

        Clear output buffer, aborting the current output and
        discarding all that is in the buffer.

        Note, for some USB serial adapters, this may only flush the buffer of
        the OS and not all the data that may be present in the USB part.

        .. versionchanged:: 3.0 renamed from ``flushOutput()``

    .. method:: send_break(duration=0.25)

        :param float duration: Time to activate the BREAK condition.

        Send break condition. Timed, returns to idle state after given
        duration.


    .. attribute:: break_condition

        :getter: Get the current BREAK state
        :setter: Control the BREAK state
        :type: bool

        When set to ``True`` activate BREAK condition, else disable.
        Controls TXD. When active, no transmitting is possible.

    .. attribute:: rts

        :setter: Set the state of the RTS line
        :getter: Return the state of the RTS line
        :type: bool

        Set RTS line to specified logic level. It is possible to assign this
        value before opening the serial port, then the value is applied uppon
        :meth:`open`.
{'fraction_non_alphanumeric': 0.08827140549273021, 'fraction_numerical': 0.025977382875605817, 'mean_word_length': 2.271881606765328, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6934870', 'n_tokens_mistral': 4460, 'n_tokens_neox': 3945, 'n_words': 1760}