# UART interface modules for Cocotb
[](https://github.com/alexforencich/cocotbext-uart/actions/workflows/regression-tests.yml)
[](https://codecov.io/gh/alexforencich/cocotbext-uart)
[](https://pypi.org/project/cocotbext-uart)
[](https://pepy.tech/project/cocotbext-uart)
GitHub repository: https://github.com/alexforencich/cocotbext-uart
## Introduction
UART simulation models for [cocotb](https://github.com/cocotb/cocotb).
## Installation
Installation from pip (release version, stable):
    $ pip install cocotbext-uart
Installation from git (latest development version, potentially unstable):
    $ pip install https://github.com/alexforencich/cocotbext-uart/archive/master.zip
Installation for active development:
    $ git clone https://github.com/alexforencich/cocotbext-uart
    $ pip install -e cocotbext-uart
## Documentation and usage examples
See the `tests` directory, [taxi](https://github.com/fpganinja/taxi), and [verilog-uart](https://github.com/alexforencich/verilog-uart) for complete testbenches using these modules.
### UART
The `UartSource` and `UartSink` classes can be used to drive, receive, and monitor asynchronous serial data.
To use these modules, import the one you need and connect it to the DUT:
    from cocotbext.uart import UartSource, UartSink
    uart_source = UartSource(dut.rxd, baud=115200, bits=8)
    uart_sink = UartSink(dut.rxd, baud=115200, bits=8)
To send data into a design with a `UartSource`, call `write()` or `write_nowait()`.  Accepted data types are iterables of ints, including lists, bytes, bytearrays, etc.  Optionally, call `wait()` to wait for the transmit operation to complete.  Example:
    await uart_source.send(b'test data')
    # wait for operation to complete (optional)
    await uart_source.wait()
To receive data with a `UartSink`, call `read()` or `read_nowait()`.  Optionally call `wait()` to wait for new receive data.  `read()` will block until at least 1 data byte is available.  Both `read()` and `read_nowait()` will return up to _count_ bytes from the receive queue, or the entire contents of the receive queue if not specified.
    data = await uart_sink.recv()
#### Constructor parameters:
* _data_: data signal
* _baud_: baud rate in bits per second (optional, default 9600)
* _bits_: bits per byte (optional, default 8)
* _stop_bits_: length of stop bit in bit times (optional, default 1)
#### Attributes:
* _baud_: baud rate in bits per second
* _bits_: bits per byte
* _stop_bits_: length of stop bit in bit times
#### Methods
* `write(data)`: send _data_ (blocking) (source)
* `write_nowait(data)`: send _data_ (non-blocking) (source)
* `read(count)`: read _count_ bytes from buffer (blocking) (sink)
* `read_nowait(count)`: read _count_ bytes from buffer (non-blocking) (sink)
* `count()`: returns the number of items in the queue (all)
* `empty()`: returns _True_ if the queue is empty (all)
* `idle()`: returns _True_ if no transfer is in progress (all) or if the queue is not empty (source)
* `clear()`: drop all data in queue (all)
* `wait()`: wait for idle (source)
* `wait(timeout=0, timeout_unit='ns')`: wait for data received (sink)
            
         
        Raw data
        
            {
    "_id": null,
    "home_page": "https://github.com/alexforencich/cocotbext-uart",
    "name": "cocotbext-uart",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "uart, cocotb",
    "author": "Alex Forencich",
    "author_email": "alex@alexforencich.com",
    "download_url": "https://files.pythonhosted.org/packages/0d/14/150453a9113885a93f8be7a4f21b89e8c67f91369e808d4e16ad8ec35869/cocotbext_uart-0.1.4.tar.gz",
    "platform": "any",
    "description": "# UART interface modules for Cocotb\n\n[](https://github.com/alexforencich/cocotbext-uart/actions/workflows/regression-tests.yml)\n[](https://codecov.io/gh/alexforencich/cocotbext-uart)\n[](https://pypi.org/project/cocotbext-uart)\n[](https://pepy.tech/project/cocotbext-uart)\n\nGitHub repository: https://github.com/alexforencich/cocotbext-uart\n\n## Introduction\n\nUART simulation models for [cocotb](https://github.com/cocotb/cocotb).\n\n## Installation\n\nInstallation from pip (release version, stable):\n\n    $ pip install cocotbext-uart\n\nInstallation from git (latest development version, potentially unstable):\n\n    $ pip install https://github.com/alexforencich/cocotbext-uart/archive/master.zip\n\nInstallation for active development:\n\n    $ git clone https://github.com/alexforencich/cocotbext-uart\n    $ pip install -e cocotbext-uart\n\n## Documentation and usage examples\n\nSee the `tests` directory, [taxi](https://github.com/fpganinja/taxi), and [verilog-uart](https://github.com/alexforencich/verilog-uart) for complete testbenches using these modules.\n\n### UART\n\nThe `UartSource` and `UartSink` classes can be used to drive, receive, and monitor asynchronous serial data.\n\nTo use these modules, import the one you need and connect it to the DUT:\n\n    from cocotbext.uart import UartSource, UartSink\n\n    uart_source = UartSource(dut.rxd, baud=115200, bits=8)\n    uart_sink = UartSink(dut.rxd, baud=115200, bits=8)\n\nTo send data into a design with a `UartSource`, call `write()` or `write_nowait()`.  Accepted data types are iterables of ints, including lists, bytes, bytearrays, etc.  Optionally, call `wait()` to wait for the transmit operation to complete.  Example:\n\n    await uart_source.send(b'test data')\n    # wait for operation to complete (optional)\n    await uart_source.wait()\n\nTo receive data with a `UartSink`, call `read()` or `read_nowait()`.  Optionally call `wait()` to wait for new receive data.  `read()` will block until at least 1 data byte is available.  Both `read()` and `read_nowait()` will return up to _count_ bytes from the receive queue, or the entire contents of the receive queue if not specified.\n\n    data = await uart_sink.recv()\n\n#### Constructor parameters:\n\n* _data_: data signal\n* _baud_: baud rate in bits per second (optional, default 9600)\n* _bits_: bits per byte (optional, default 8)\n* _stop_bits_: length of stop bit in bit times (optional, default 1)\n\n#### Attributes:\n\n* _baud_: baud rate in bits per second\n* _bits_: bits per byte\n* _stop_bits_: length of stop bit in bit times\n\n#### Methods\n\n* `write(data)`: send _data_ (blocking) (source)\n* `write_nowait(data)`: send _data_ (non-blocking) (source)\n* `read(count)`: read _count_ bytes from buffer (blocking) (sink)\n* `read_nowait(count)`: read _count_ bytes from buffer (non-blocking) (sink)\n* `count()`: returns the number of items in the queue (all)\n* `empty()`: returns _True_ if the queue is empty (all)\n* `idle()`: returns _True_ if no transfer is in progress (all) or if the queue is not empty (source)\n* `clear()`: drop all data in queue (all)\n* `wait()`: wait for idle (source)\n* `wait(timeout=0, timeout_unit='ns')`: wait for data received (sink)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "UART modules for cocotb",
    "version": "0.1.4",
    "project_urls": {
        "Bug Tracker": "https://github.com/alexforencich/cocotbext-uart/issues",
        "Download": "https://github.com/alexforencich/cocotbext-uart/tarball/master",
        "Homepage": "https://github.com/alexforencich/cocotbext-uart",
        "Source Code": "https://github.com/alexforencich/cocotbext-uart"
    },
    "split_keywords": [
        "uart",
        " cocotb"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "2432351045b5ac3feb65c3b54153a20ffb882a5445297572d67752ac755791c9",
                "md5": "d75e6bce2c679ce81039ee3d1f787a4b",
                "sha256": "be78f266449765a1cb7877a733f796bbfdbe492e7205051c4cc413e2e0c4727f"
            },
            "downloads": -1,
            "filename": "cocotbext_uart-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d75e6bce2c679ce81039ee3d1f787a4b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 6627,
            "upload_time": "2025-09-07T18:51:14",
            "upload_time_iso_8601": "2025-09-07T18:51:14.381326Z",
            "url": "https://files.pythonhosted.org/packages/24/32/351045b5ac3feb65c3b54153a20ffb882a5445297572d67752ac755791c9/cocotbext_uart-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0d14150453a9113885a93f8be7a4f21b89e8c67f91369e808d4e16ad8ec35869",
                "md5": "253397f1d185d047b6ec919b110f0b90",
                "sha256": "574643c82067be5e1dd6e2e830f46b8803c07fc1f27b7f75bf25066fd6d06798"
            },
            "downloads": -1,
            "filename": "cocotbext_uart-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "253397f1d185d047b6ec919b110f0b90",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 7948,
            "upload_time": "2025-09-07T18:51:30",
            "upload_time_iso_8601": "2025-09-07T18:51:30.235369Z",
            "url": "https://files.pythonhosted.org/packages/0d/14/150453a9113885a93f8be7a4f21b89e8c67f91369e808d4e16ad8ec35869/cocotbext_uart-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-07 18:51:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "alexforencich",
    "github_project": "cocotbext-uart",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "cocotbext-uart"
}