BinhoSupernova


NameBinhoSupernova JSON
Version 3.1.1 PyPI version JSON
download
home_pagehttps://binho.io
SummaryPython package for Binho Supernova USB host adapter
upload_time2024-10-10 13:25:46
maintainerNone
docs_urlNone
authorBinho LLC
requires_python>=3.8
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SupernovaSDK: Python SDK for Binho Supernova USB Host Adapter

SupernovaSDK is a Python package that facilitates seamless interaction with the innovative Supernova USB host adapter developed by Binho. Designed to simplify device orchestration during embedded system development and testing, the Supernova host adapter enhances hardware control for developers and engineers.

The SupernovaSDK currently supports I2C and I3C protocols, allowing effortless communication with I2C and I3C devices as the host adapter acts as a controller device.

# Prerequisites

Before installing and using the SupernovaSDK, please ensure your system meets the following requirements:

- Python 3.6 or higher.
- Windows, MacOS or Linux operating systems.
- Binho Supernova USB host adapter with up-to-date firmware.

# Installation From PyPi

For the most recent update of the BinhoSupernova Python package on PyPi, follow these steps:

1. Open your terminal or command prompt.

3. Use pip to install the SupernovaSDK:

```sh
pip install BinhoSupernova
```

Now, the SupernovaSDK is installed and ready to be used in your Python projects. You can import and use it as shown in the usage example.

# Installation From the Git Repository

Remember to activate your virtual environment (if you're using one) before running the installation command.

To install the SupernovaSDK from your local file system, follow these steps:

1. Download the SupernovaSDK package.

2. Extract the downloaded package to a folder on your local file system.

3. Open a terminal or command prompt and navigate to the folder containing the extracted SupernovaSDK.

4. Install the SDK using pip with the local file path:

```sh
pip install .
```

**Note**: Make sure to include the period (.) at the end, indicating the current directory.

Now, the SupernovaSDK is installed and ready to be used in your Python projects. You can import and use it as shown in the usage example.

# Basic Usage Example

This example showcases how to use the Supernova SDK with a Supernova device. Since the Supernova operates in a non-blocking manner, each method of the SDK sends a command to the host adapter and immediately receives an SUCCESS or error message. The actual command response is provided through a callback function.

```python
from BinhoSupernova.Supernova import Supernova
from BinhoSupernova.commands.definitions import *

# Initialize and open a Supernova object for communication with the Supernova device
supernova = Supernova()
supernova.open()

# Define a callback function to handle command responses from the Supernova device
def callback_function(supernova_message: dict, system_message: dict) -> None:
    print(f"Transaction ID: {supernova_message['id']}")
    print(f"Command Code: {supernova_message['command']}")
    print(f"Command Name: {supernova_message['name']}")
    print(f"Message Length: {supernova_message['length']}")
    print(f"Message Content: {supernova_message['message']}")

# Register the callback function to link with Supernova events
supernova.onEvent(callback_function)

# Define a transaction ID to match the command request with its response
transaction_id = 0

# Send a request for the manufacturer's string from a connected USB device (non-blocking)
# The response will be handled by the registered callback
request_result = supernova.getUsbString(transaction_id, GetUsbStringSubCommand.MANUFACTURER)
# E.g., request_result: {'type': 'request_validation_result', 'id': 0, 'command': 96, 'code value': 0, 'code name': 'SUCCESS', 'message': 'GET USB STRING requests success'}
```

# Advanced Usage Example

The following code demonstrates how to make sequential calls to the host adapter using the Supernova SDK. Sequential calls require triggering a new call after the response of the previous call has been received. This is achieved by using a threading Event and a shared list to synchronize the calls and share the result between the callback function and the decorated method.

The code includes a decorator function sequential_call, which surrounds the Supernova method call with `call_event.clear()` and `call_event.wait()` calls. The `sequential_call`` decorator ensures that each method call waits for the response from the previous call before proceeding.

```python
from BinhoSupernova.Supernova import Supernova
from BinhoSupernova.commands.definitions import *
import threading

# Initialize and open a Supernova object for communication with the Supernova device
supernova = Supernova()
supernova.open()

# Define a callback function to handle command responses from the Supernova device
def callback_function(supernova_message: dict, system_message: dict) -> None:
    shared_result[0] = supernova_message # Store the result in the shared list
    call_event.set() # Signal that the response has been received

# Register the callback function to link with Supernova events
supernova.onEvent(callback_function)

# Define a threading Event to control the synchronization between calls
call_event = threading.Event()

# Shared list to store the result
shared_result = [None]

# Decorator function to handle synchronization around the Supernova method call
def sequential_call(method):
    def wrapper(*args, **kwargs):
        call_event.clear() # Reset the event
        method(*args, **kwargs)
        call_event.wait() # Wait for the callback to signal that the response has been received
        return shared_result[0] # Return the result stored by the callback
    return wrapper

# Make sequential calls to the host adapter, using the decorator for synchronization
@sequential_call
def get_manufacturer_string(transaction_id):
    return supernova.getUsbString(transaction_id, GetUsbStringSubCommand.MANUFACTURER)

@sequential_call
def get_product_name_string(transaction_id):
    return supernova.getUsbString(transaction_id, GetUsbStringSubCommand.PRODUCT_NAME)

@sequential_call
def get_serial_number_string(transaction_id):
    return supernova.getUsbString(transaction_id, GetUsbStringSubCommand.SERIAL_NUMBER)

@sequential_call
def get_fw_version_string(transaction_id):
    return supernova.getUsbString(transaction_id, GetUsbStringSubCommand.FW_VERSION)

@sequential_call
def get_hw_version_string(transaction_id):
    return supernova.getUsbString(transaction_id, GetUsbStringSubCommand.HW_VERSION)

manufacturer = get_manufacturer_string(0)
product_name = get_product_name_string(0)
serial_number = get_serial_number_string(0)
fw_version = get_fw_version_string(0)
hw_version = get_hw_version_string(0)

print(manufacturer)
print(product_name)
print(serial_number)
print(fw_version)
print(hw_version)
```

# More Examples

For additional examples and detailed use cases, please refer to the `Examples/Notebooks` folder in the repository. This folder contains various Jupyter Notebooks with hands-on demonstrations and tutorials for working with the Supernova SDK, including:

- **I2C-Protocol-Supernova-API.ipynb:** Tutorial on the I2C protocol with Supernova API.
- **I3C-Protocol-Supernova-API.ipynb:** Comprehensive tutorial on I3C Protocol with Supernova API.

# Documentation

The documentation of all this Python package can be found in [`docs/build/html/`](./docs/build/html/) in HTML format. To open the documentation, open the [`index.html`](./docs/build/html/index.html) file in a browser from the file explorer locally in your computer.

To see how to generate a new version of the documentation see the [Readme](docs/README.md) file in [docs folder](docs/).

            

Raw data

            {
    "_id": null,
    "home_page": "https://binho.io",
    "name": "BinhoSupernova",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Binho LLC",
    "author_email": "support@binho.io",
    "download_url": "https://files.pythonhosted.org/packages/91/7f/c9f0ee339793f61ce6d84cc41154850068c83321ac4ba17c10210aa744e6/BinhoSupernova-3.1.1.tar.gz",
    "platform": "any",
    "description": "# SupernovaSDK: Python SDK for Binho Supernova USB Host Adapter\n\nSupernovaSDK is a Python package that facilitates seamless interaction with the innovative Supernova USB host adapter developed by Binho. Designed to simplify device orchestration during embedded system development and testing, the Supernova host adapter enhances hardware control for developers and engineers.\n\nThe SupernovaSDK currently supports I2C and I3C protocols, allowing effortless communication with I2C and I3C devices as the host adapter acts as a controller device.\n\n# Prerequisites\n\nBefore installing and using the SupernovaSDK, please ensure your system meets the following requirements:\n\n- Python 3.6 or higher.\n- Windows, MacOS or Linux operating systems.\n- Binho Supernova USB host adapter with up-to-date firmware.\n\n# Installation From PyPi\n\nFor the most recent update of the BinhoSupernova Python package on PyPi, follow these steps:\n\n1. Open your terminal or command prompt.\n\n3. Use pip to install the SupernovaSDK:\n\n```sh\npip install BinhoSupernova\n```\n\nNow, the SupernovaSDK is installed and ready to be used in your Python projects. You can import and use it as shown in the usage example.\n\n# Installation From the Git Repository\n\nRemember to activate your virtual environment (if you're using one) before running the installation command.\n\nTo install the SupernovaSDK from your local file system, follow these steps:\n\n1. Download the SupernovaSDK package.\n\n2. Extract the downloaded package to a folder on your local file system.\n\n3. Open a terminal or command prompt and navigate to the folder containing the extracted SupernovaSDK.\n\n4. Install the SDK using pip with the local file path:\n\n```sh\npip install .\n```\n\n**Note**: Make sure to include the period (.) at the end, indicating the current directory.\n\nNow, the SupernovaSDK is installed and ready to be used in your Python projects. You can import and use it as shown in the usage example.\n\n# Basic Usage Example\n\nThis example showcases how to use the Supernova SDK with a Supernova device. Since the Supernova operates in a non-blocking manner, each method of the SDK sends a command to the host adapter and immediately receives an SUCCESS or error message. The actual command response is provided through a callback function.\n\n```python\nfrom BinhoSupernova.Supernova import Supernova\nfrom BinhoSupernova.commands.definitions import *\n\n# Initialize and open a Supernova object for communication with the Supernova device\nsupernova = Supernova()\nsupernova.open()\n\n# Define a callback function to handle command responses from the Supernova device\ndef callback_function(supernova_message: dict, system_message: dict) -> None:\n    print(f\"Transaction ID: {supernova_message['id']}\")\n    print(f\"Command Code: {supernova_message['command']}\")\n    print(f\"Command Name: {supernova_message['name']}\")\n    print(f\"Message Length: {supernova_message['length']}\")\n    print(f\"Message Content: {supernova_message['message']}\")\n\n# Register the callback function to link with Supernova events\nsupernova.onEvent(callback_function)\n\n# Define a transaction ID to match the command request with its response\ntransaction_id = 0\n\n# Send a request for the manufacturer's string from a connected USB device (non-blocking)\n# The response will be handled by the registered callback\nrequest_result = supernova.getUsbString(transaction_id, GetUsbStringSubCommand.MANUFACTURER)\n# E.g., request_result: {'type': 'request_validation_result', 'id': 0, 'command': 96, 'code value': 0, 'code name': 'SUCCESS', 'message': 'GET USB STRING requests success'}\n```\n\n# Advanced Usage Example\n\nThe following code demonstrates how to make sequential calls to the host adapter using the Supernova SDK. Sequential calls require triggering a new call after the response of the previous call has been received. This is achieved by using a threading Event and a shared list to synchronize the calls and share the result between the callback function and the decorated method.\n\nThe code includes a decorator function sequential_call, which surrounds the Supernova method call with `call_event.clear()` and `call_event.wait()` calls. The `sequential_call`` decorator ensures that each method call waits for the response from the previous call before proceeding.\n\n```python\nfrom BinhoSupernova.Supernova import Supernova\nfrom BinhoSupernova.commands.definitions import *\nimport threading\n\n# Initialize and open a Supernova object for communication with the Supernova device\nsupernova = Supernova()\nsupernova.open()\n\n# Define a callback function to handle command responses from the Supernova device\ndef callback_function(supernova_message: dict, system_message: dict) -> None:\n    shared_result[0] = supernova_message # Store the result in the shared list\n    call_event.set() # Signal that the response has been received\n\n# Register the callback function to link with Supernova events\nsupernova.onEvent(callback_function)\n\n# Define a threading Event to control the synchronization between calls\ncall_event = threading.Event()\n\n# Shared list to store the result\nshared_result = [None]\n\n# Decorator function to handle synchronization around the Supernova method call\ndef sequential_call(method):\n    def wrapper(*args, **kwargs):\n        call_event.clear() # Reset the event\n        method(*args, **kwargs)\n        call_event.wait() # Wait for the callback to signal that the response has been received\n        return shared_result[0] # Return the result stored by the callback\n    return wrapper\n\n# Make sequential calls to the host adapter, using the decorator for synchronization\n@sequential_call\ndef get_manufacturer_string(transaction_id):\n    return supernova.getUsbString(transaction_id, GetUsbStringSubCommand.MANUFACTURER)\n\n@sequential_call\ndef get_product_name_string(transaction_id):\n    return supernova.getUsbString(transaction_id, GetUsbStringSubCommand.PRODUCT_NAME)\n\n@sequential_call\ndef get_serial_number_string(transaction_id):\n    return supernova.getUsbString(transaction_id, GetUsbStringSubCommand.SERIAL_NUMBER)\n\n@sequential_call\ndef get_fw_version_string(transaction_id):\n    return supernova.getUsbString(transaction_id, GetUsbStringSubCommand.FW_VERSION)\n\n@sequential_call\ndef get_hw_version_string(transaction_id):\n    return supernova.getUsbString(transaction_id, GetUsbStringSubCommand.HW_VERSION)\n\nmanufacturer = get_manufacturer_string(0)\nproduct_name = get_product_name_string(0)\nserial_number = get_serial_number_string(0)\nfw_version = get_fw_version_string(0)\nhw_version = get_hw_version_string(0)\n\nprint(manufacturer)\nprint(product_name)\nprint(serial_number)\nprint(fw_version)\nprint(hw_version)\n```\n\n# More Examples\n\nFor additional examples and detailed use cases, please refer to the `Examples/Notebooks` folder in the repository. This folder contains various Jupyter Notebooks with hands-on demonstrations and tutorials for working with the Supernova SDK, including:\n\n- **I2C-Protocol-Supernova-API.ipynb:** Tutorial on the I2C protocol with Supernova API.\n- **I3C-Protocol-Supernova-API.ipynb:** Comprehensive tutorial on I3C Protocol with Supernova API.\n\n# Documentation\n\nThe documentation of all this Python package can be found in [`docs/build/html/`](./docs/build/html/) in HTML format. To open the documentation, open the [`index.html`](./docs/build/html/index.html) file in a browser from the file explorer locally in your computer.\n\nTo see how to generate a new version of the documentation see the [Readme](docs/README.md) file in [docs folder](docs/).\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Python package for Binho Supernova USB host adapter",
    "version": "3.1.1",
    "project_urls": {
        "Homepage": "https://binho.io"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d4a6d6583e0878281483d3e213749bc5080efcf3a3720bd7e8fae57dff50fbe5",
                "md5": "1bf47b8ab115ea63b67d9b3bca460876",
                "sha256": "65f2c5e7563807abbe6019faee2568969dee6305fe81e364e4551dbe01950bd6"
            },
            "downloads": -1,
            "filename": "BinhoSupernova-3.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1bf47b8ab115ea63b67d9b3bca460876",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 71234,
            "upload_time": "2024-10-10T13:25:44",
            "upload_time_iso_8601": "2024-10-10T13:25:44.231866Z",
            "url": "https://files.pythonhosted.org/packages/d4/a6/d6583e0878281483d3e213749bc5080efcf3a3720bd7e8fae57dff50fbe5/BinhoSupernova-3.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "917fc9f0ee339793f61ce6d84cc41154850068c83321ac4ba17c10210aa744e6",
                "md5": "06f05b74d64849235e1d8a141c513054",
                "sha256": "b9b58be6a3a3ffde0270d83feb30d8c3d4b5cc358f0ea9752d7892bab2c3c225"
            },
            "downloads": -1,
            "filename": "BinhoSupernova-3.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "06f05b74d64849235e1d8a141c513054",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 68739,
            "upload_time": "2024-10-10T13:25:46",
            "upload_time_iso_8601": "2024-10-10T13:25:46.846277Z",
            "url": "https://files.pythonhosted.org/packages/91/7f/c9f0ee339793f61ce6d84cc41154850068c83321ac4ba17c10210aa744e6/BinhoSupernova-3.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-10 13:25:46",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "binhosupernova"
}
        
Elapsed time: 0.45153s