ptcc-library


Nameptcc-library JSON
Version 0.2.0 PyPI version JSON
download
home_pageNone
SummaryThis is a modular Python library for communicating with PTCC hardware devices over a custom byte-based protocol. It supports message construction, parsing, throttled I/O communication, device detection, and callback-based event handling.
upload_time2025-08-12 10:20:34
maintainerNone
docs_urlNone
authorNone
requires_python>=3.12
licenseNone
keywords ptcc
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PTCC Communication Framework

A modular Python library for communicating with PTCC hardware devices over a custom byte-based protocol. It supports message construction, parsing, throttled I/O communication, device detection, and callback-based event handling.

- Project Homepage: https://gitlab.com/vigophotonics/ptcc-library
- Download Page: https://pypi.org/project/ptcc-library
- Product Page: https://vigophotonics.com/product/programmable-smart-ptcc-01-tec-controller-series/


## Features
- Communication with PTCC devices and modules
- Simplified message generation for communication
- Interface abstraction for serial or custom communication backends
- Auto-detection of PTCC device/module types (NOMEM, MEM, LAB_M)
- Full PtccObject and PtccMessage encoding/decoding support
- Callback registration for received object IDs
- Values retrieving and setting in SI units

## Documentation
Full documentation can be found at https://ptcc-library.readthedocs.io/


## Installation
`ptcc_library` can be installed from PyPI:
``pip install ptcc-library``

Detailed information can be found at https://pypi.org/project/ptcc-library


## Quick Start Example

### 1. Detect and Connect to Device
To communicate with your hardware, the library first needs an active communication channel. 
This is typically a `serial` port object that you create and configure. 
You pass this communication object to the `detect_device()` function. 
If a compatible `device` is found, the function returns a device object, which is your primary interface for all further interactions.

```python
from ptcc_library import detect_device
import serial

with serial.Serial('COM5', baudrate=57600, timeout=0.1) as ser:
        device = detect_device(comm=ser)
```

### 2. Register Callbacks
A callback is a function you write that is automatically executed when a specific piece of data arrives from the device. 
This allows you to react to incoming information asynchronously. 
You link your function to a data ID using `device.receiver.register_callback()`. 
You can also pass an optional `context` argument, which is a static value supplied to your callback, useful for identifying a measurement's source.

```python
from ptcc_library import CallbackPtccObjectID


def name_callback(name):
        print("Module Name:", name)


def temp_callback(temp, context):
        print(f"Temperature: {temp} K ({context})")


device.receiver.register_callback(CallbackPtccObjectID.MODULE_IDEN_NAME, name_callback)
device.receiver.register_callback(CallbackPtccObjectID.MODULE_BASIC_PARAMS_T_DET, temp_callback, "live")
```

### 3. Send Messages

The `device` object provides straightforward methods for sending commands and requests to the hardware, typically named `write_msg_*`. 
For example, `write_msg_get_module_iden()` requests identity information, while `write_msg_set_temperature()` commands the device to change its temperature. 
When the device responds, it will trigger the corresponding callbacks you registered.

```python
device.write_msg_get_module_iden()
device.write_msg_set_temperature(value_in_kelvins=230)
```


### 4. Handle Incoming Data

The library does not read from the serial port on its own. 
Your application is responsible for reading incoming bytes and feeding them to the library's receiver. 
You must implement a loop that reads data and passes it to `device.receiver.add_byte()` or `device.receiver.add_bytes()`. 
As the receiver processes data, it automatically finds complete messages and triggers the appropriate callbacks.


```python
while True:
    byte = ser.read(1)
    if byte:
        if device.receiver.add_byte(byte[0]) == PtccMessageReceiveStatus.FINISHED:
                print("New message received")
```


### Handle Containers

The device communicates by sending data in packets called containers.
Each container holds a collection of related data objects.
To process full data as it arrives, you must register a callback function that will be executed when a specific type of container is received.

Container IDs include:

* `DEVICE_IDEN`
* `MODULE_IDEN`
* `PTCC_CONFIG`
* `PTCC_MONITOR`
* `MODULE_BASIC_PARAMS`
* `MODULE_LAB_M_MONITOR`
* `MODULE_LAB_M_PARAMS`

```python

def iden_callback(objects):
    for o in objects:
        print(f"{o.name} = {o.value}")
device.receiver.register_callback(CallbackPtccObjectID.DEVICE_IDEN, iden_callback)
```

## Product Page

<p align="center">
  <a href="https://vigophotonics.com/product/programmable-smart-ptcc-01-tec-controller-series/">
    <img src="docs/source/_static/PTCC-01-TEC-controllers-2048x1051.jpg" alt="Photo of the PTCC-01 TEC Controller" width="400">
  </a>
</p>

PTCC-01 is a series of programmable, precision, low-noise thermoelectric cooler controllers.
They are designed to operate with VIGO infrared detection modules.
- Product Page: https://vigophotonics.com/product/programmable-smart-ptcc-01-tec-controller-series/



## 👤 Author

**Wojciech Szczytko**  
[wszczytko@vigo.com.pl](mailto:wszczytko@vigo.com.pl)  
GitLab: [@wszczytko1](https://gitlab.com/wszczytko1)
        [@wszczytko](https://gitlab.com/wszczytko)
        [@wszczytk](https://gitlab.com/wszczytk)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ptcc-library",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "PTCC",
    "author": null,
    "author_email": "Wojceich Szczytko <wszczytko@vigo.com.pl>",
    "download_url": "https://files.pythonhosted.org/packages/6a/ad/4c0edd58dddb4ed14f1f0d5b1cbaa49a4d83162ac2e2ad384ee308183307/ptcc_library-0.2.0.tar.gz",
    "platform": null,
    "description": "# PTCC Communication Framework\n\nA modular Python library for communicating with PTCC hardware devices over a custom byte-based protocol. It supports message construction, parsing, throttled I/O communication, device detection, and callback-based event handling.\n\n- Project Homepage: https://gitlab.com/vigophotonics/ptcc-library\n- Download Page: https://pypi.org/project/ptcc-library\n- Product Page: https://vigophotonics.com/product/programmable-smart-ptcc-01-tec-controller-series/\n\n\n## Features\n- Communication with PTCC devices and modules\n- Simplified message generation for communication\n- Interface abstraction for serial or custom communication backends\n- Auto-detection of PTCC device/module types (NOMEM, MEM, LAB_M)\n- Full PtccObject and PtccMessage encoding/decoding support\n- Callback registration for received object IDs\n- Values retrieving and setting in SI units\n\n## Documentation\nFull documentation can be found at https://ptcc-library.readthedocs.io/\n\n\n## Installation\n`ptcc_library` can be installed from PyPI:\n``pip install ptcc-library``\n\nDetailed information can be found at https://pypi.org/project/ptcc-library\n\n\n## Quick Start Example\n\n### 1. Detect and Connect to Device\nTo communicate with your hardware, the library first needs an active communication channel. \nThis is typically a `serial` port object that you create and configure. \nYou pass this communication object to the `detect_device()` function. \nIf a compatible `device` is found, the function returns a device object, which is your primary interface for all further interactions.\n\n```python\nfrom ptcc_library import detect_device\nimport serial\n\nwith serial.Serial('COM5', baudrate=57600, timeout=0.1) as ser:\n        device = detect_device(comm=ser)\n```\n\n### 2. Register Callbacks\nA callback is a function you write that is automatically executed when a specific piece of data arrives from the device. \nThis allows you to react to incoming information asynchronously. \nYou link your function to a data ID using `device.receiver.register_callback()`. \nYou can also pass an optional `context` argument, which is a static value supplied to your callback, useful for identifying a measurement's source.\n\n```python\nfrom ptcc_library import CallbackPtccObjectID\n\n\ndef name_callback(name):\n        print(\"Module Name:\", name)\n\n\ndef temp_callback(temp, context):\n        print(f\"Temperature: {temp} K ({context})\")\n\n\ndevice.receiver.register_callback(CallbackPtccObjectID.MODULE_IDEN_NAME, name_callback)\ndevice.receiver.register_callback(CallbackPtccObjectID.MODULE_BASIC_PARAMS_T_DET, temp_callback, \"live\")\n```\n\n### 3. Send Messages\n\nThe `device` object provides straightforward methods for sending commands and requests to the hardware, typically named `write_msg_*`. \nFor example, `write_msg_get_module_iden()` requests identity information, while `write_msg_set_temperature()` commands the device to change its temperature. \nWhen the device responds, it will trigger the corresponding callbacks you registered.\n\n```python\ndevice.write_msg_get_module_iden()\ndevice.write_msg_set_temperature(value_in_kelvins=230)\n```\n\n\n### 4. Handle Incoming Data\n\nThe library does not read from the serial port on its own. \nYour application is responsible for reading incoming bytes and feeding them to the library's receiver. \nYou must implement a loop that reads data and passes it to `device.receiver.add_byte()` or `device.receiver.add_bytes()`. \nAs the receiver processes data, it automatically finds complete messages and triggers the appropriate callbacks.\n\n\n```python\nwhile True:\n    byte = ser.read(1)\n    if byte:\n        if device.receiver.add_byte(byte[0]) == PtccMessageReceiveStatus.FINISHED:\n                print(\"New message received\")\n```\n\n\n### Handle Containers\n\nThe device communicates by sending data in packets called containers.\nEach container holds a collection of related data objects.\nTo process full data as it arrives, you must register a callback function that will be executed when a specific type of container is received.\n\nContainer IDs include:\n\n* `DEVICE_IDEN`\n* `MODULE_IDEN`\n* `PTCC_CONFIG`\n* `PTCC_MONITOR`\n* `MODULE_BASIC_PARAMS`\n* `MODULE_LAB_M_MONITOR`\n* `MODULE_LAB_M_PARAMS`\n\n```python\n\ndef iden_callback(objects):\n    for o in objects:\n        print(f\"{o.name} = {o.value}\")\ndevice.receiver.register_callback(CallbackPtccObjectID.DEVICE_IDEN, iden_callback)\n```\n\n## Product Page\n\n<p align=\"center\">\n  <a href=\"https://vigophotonics.com/product/programmable-smart-ptcc-01-tec-controller-series/\">\n    <img src=\"docs/source/_static/PTCC-01-TEC-controllers-2048x1051.jpg\" alt=\"Photo of the PTCC-01 TEC Controller\" width=\"400\">\n  </a>\n</p>\n\nPTCC-01 is a series of programmable, precision, low-noise thermoelectric cooler controllers.\nThey are designed to operate with VIGO infrared detection modules.\n- Product Page: https://vigophotonics.com/product/programmable-smart-ptcc-01-tec-controller-series/\n\n\n\n## \ud83d\udc64 Author\n\n**Wojciech Szczytko**  \n[wszczytko@vigo.com.pl](mailto:wszczytko@vigo.com.pl)  \nGitLab: [@wszczytko1](https://gitlab.com/wszczytko1)\n        [@wszczytko](https://gitlab.com/wszczytko)\n        [@wszczytk](https://gitlab.com/wszczytk)\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "This is a modular Python library for communicating with PTCC hardware devices over a custom byte-based protocol. It supports message construction, parsing, throttled I/O communication, device detection, and callback-based event handling.",
    "version": "0.2.0",
    "project_urls": null,
    "split_keywords": [
        "ptcc"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "bdbae15d8cf1ee89993b2be0463bd781c043da29cbb4cf257fddbc0072fe17a8",
                "md5": "fac2f40f84f3f752e1ebb53857b5dec7",
                "sha256": "72721e9520929b6b43ac00f4b3fd377a8537413df579b3d74b88d90040300d2d"
            },
            "downloads": -1,
            "filename": "ptcc_library-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fac2f40f84f3f752e1ebb53857b5dec7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 185352,
            "upload_time": "2025-08-12T10:20:32",
            "upload_time_iso_8601": "2025-08-12T10:20:32.650017Z",
            "url": "https://files.pythonhosted.org/packages/bd/ba/e15d8cf1ee89993b2be0463bd781c043da29cbb4cf257fddbc0072fe17a8/ptcc_library-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "6aad4c0edd58dddb4ed14f1f0d5b1cbaa49a4d83162ac2e2ad384ee308183307",
                "md5": "672bf18dae1f036aa7c9d10ccefbe725",
                "sha256": "25bfccac68ab458fcf7077764acfc036ad614cb56f1cdbbb2929a56744d4c674"
            },
            "downloads": -1,
            "filename": "ptcc_library-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "672bf18dae1f036aa7c9d10ccefbe725",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 181167,
            "upload_time": "2025-08-12T10:20:34",
            "upload_time_iso_8601": "2025-08-12T10:20:34.953241Z",
            "url": "https://files.pythonhosted.org/packages/6a/ad/4c0edd58dddb4ed14f1f0d5b1cbaa49a4d83162ac2e2ad384ee308183307/ptcc_library-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-12 10:20:34",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "ptcc-library"
}
        
Elapsed time: 1.27827s