Metadata-Version: 2.4
Name: ikalogic-at1000
Version: 0.10.0
Summary: Python SDK for Ikalogic AT1000 devices
Keywords: at1000,ikalogic,test-sequencer,automated-testing,hardware,instrumentation,sdk,api
Author: Corentin AZAIS, Vladislav KOSINOV
Author-email: Corentin AZAIS <c.azais@ikalogic.com>, Vladislav KOSINOV <v.kosinov@ikalogic.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Manufacturing
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Embedded Systems
Classifier: Topic :: Scientific/Engineering
Classifier: Typing :: Typed
Requires-Dist: httpx>=0.28.1
Requires-Dist: pydantic>=2.12.5
Requires-Dist: websockets>=13.0
Requires-Dist: zeroconf>=0.148.0
Requires-Python: >=3.10
Project-URL: Homepage, https://ikalogic.com/test-sequencers/at1000/intro/
Project-URL: Documentation, https://ikalogic.com/kb/at1000-api/at1000_home/
Description-Content-Type: text/markdown

# ikalogic-at1000

Official Python SDK for the Ikalogic AT1000 Series Test Sequencers.

This package controls and automates the Ikalogic [AT1000](https://ikalogic.com/test-sequencers/at1000/intro/), a test sequencer for functional testing of electronic devices, PCBs, and complex systems. It ships a synchronous client (`ikalogic_at1000`) and an asynchronous client (`ikalogic_at1000.aio`) with the same API.

## Key Features

- **32 Programmable I/Os:** Handle analog and digital signals within a ±25V range.
- **8 Dry Contact Relays:** Control external circuits, with one relay equipped for high-precision current measurement.
- **Programmable Power Supply:** Delivers 0 to 24V at up to 2A with precise current monitoring.
- **Dual USB 3.0 Ports:** Feature power cycling (on/off control) and current measurement for testing USB devices.
- **Communication Interfaces:** Includes Ethernet, RS232, RS485, CAN, SPI, I2C, and UART.
- **Human-Machine Interface (HMI):** Onboard screen, rotary knob, and speaker for standalone operation and feedback.

## Installation

```bash
pip install ikalogic-at1000
```

Or, with [uv](https://docs.astral.sh/uv/):

```bash
uv add ikalogic-at1000
```

Requires Python 3.10 or newer.

Starting a new project? `uvx create-ikalogic-at1000 my-project` scaffolds a ready-to-run demo that depends on this SDK.

## Quick Start

Discover devices on the local network, then open one:

```python
from ikalogic_at1000 import AT1000

# mDNS discovery returns host strings
for host in AT1000.find_devices():
    print(host)

device = AT1000.open("at1000.local")  # hostname or IP
print(device.info.model, device.info.serial_number)

device.reset()  # every subsystem back to its default state
device.close()
```

Inside an AT1000 project container the device resolves its own address without mDNS:

```python
from ikalogic_at1000 import AT1000

if AT1000.is_standalone():
    device_address = AT1000.find_local_device()
else:
    devices = AT1000.find_devices()
    device_address = devices[0] if devices else None

if not device_address:
    raise SystemExit("No devices found")

device = AT1000.open(device_address)
```

## Basic Usage

Resources are attributes of the opened device. Pin, port, and relay numbers start at 0.

```python
from ikalogic_at1000 import AT1000

device = AT1000.open("at1000.local")
try:
    # GPIO: digital input with 0.8 V / 1.5 V thresholds, digital and analog outputs
    test_point = device.gpio.digital(5)
    test_point.configure_input(vil=0.8, vih=1.5)
    print("GPIO 5 high:", test_point.read())

    device.gpio.digital(0).configure_output(value=True, vol=0.0, voh=3.3)
    device.gpio.analog(2).configure_output(1.5)
    print("GPIO 3 voltage:", device.gpio.analog(3).read())

    # Power: DUT supply and USB port power with current measurement
    dut = device.power.dut(0)
    dut.enable(5.0)
    print("DUT current:", dut.read_current())
    device.power.usb(0).disable()

    # Relays
    device.relays.relay(2).close()
    print("Relay 2 closed:", device.relays.relay(2).is_closed())
finally:
    device.reset()
    device.close()
```

`device.gpio.sequence()` batches GPIO writes, reads, waits, and delays into one request that runs on the device. `device.com` exposes the CAN, I2C, SPI, UART, RS232, RS485, and USB interfaces.

## Sessions

`open()` acquires exclusive access to the device. The session is labelled with the `label` argument, or the project id or local hostname when omitted. If another client opens the same device, this client's mutating calls raise `AccessRevokedError` until it calls `open()` again.

Pass `readonly=True` to observe a device without taking control. Reads work, and mutating calls raise `DeviceNotOpenError`:

```python
from ikalogic_at1000 import AT1000

monitor = AT1000.open("at1000.local", readonly=True)
print(monitor.session.state())  # who holds the device, if anyone
monitor.close()
```

## Errors

Every error response from the device raises `ApiError`, with `code`, `suggestion`, and `path` attributes. Specific codes raise subclasses:

- `AccessRevokedError`: another client opened the device. Call `open()` again to take it back.
- `DeviceNotOpenError`: a mutating call was made without a session, for example on a `readonly` client.
- `InsufficientStorageError`: an upload does not fit in the device storage.
- `BundleSourceUnreachableError`: the device cannot reach a streamed firmware bundle source.

```python
from ikalogic_at1000 import AccessRevokedError, ApiError, AT1000

device = AT1000.open("at1000.local")
try:
    device.relays.relay(0).close()
except AccessRevokedError:
    device = AT1000.open("at1000.local")  # reacquire, then retry
except ApiError as error:
    print(error.code, error.suggestion)
```

Arguments that fail local validation raise `ValueError` (including pydantic's `ValidationError`) before any request is sent.

## Asynchronous Usage

`ikalogic_at1000.aio` exports the same classes and models as coroutines. Close the async client with `aclose()`:

```python
import asyncio

from ikalogic_at1000.aio import AT1000


async def main():
    device = await AT1000.open("at1000.local")
    try:
        await device.gpio.digital(5).configure_input(vil=0.8, vih=1.5)
        print(await device.gpio.digital(5).read())
    finally:
        await device.aclose()


asyncio.run(main())
```

## Real-time Events

Live device state changes arrive over a WebSocket. The synchronous client registers callbacks per event type, or `"*"` for all events:

```python
from ikalogic_at1000 import AT1000

device = AT1000.open("at1000.local", readonly=True)
device.events.connect()


def on_gpio(event):
    print(event.type, event.data)


unsubscribe = device.events.subscribe("gpio.state", on_gpio)

# later
unsubscribe()
device.events.close()
device.close()
```

The async client iterates events instead. `listen()` filters by type and yields everything when called with no types:

```python
from ikalogic_at1000.aio import AT1000


async def watch(host: str):
    device = await AT1000.open(host, readonly=True)
    try:
        async for event in device.events.listen("gpio.state", "relays.state"):
            print(event.type, event.data)
    finally:
        await device.aclose()
```

Both clients reconnect automatically after the first successful connection. `events.close()` stops the stream.

## HMI

`device.hmi` drives the screen, speaker, and knob. `knob().wait_event(timeout_ms)` waits for a press or a turn and returns a `KnobEvent`, or `None` on timeout. Rotation is reported in detent steps, so use a server and SDK release with matching knob handling.

`hmi.prompt()` shows a single-choice prompt and blocks until the operator answers:

```python
from ikalogic_at1000 import AT1000, PromptChoice, PromptRequest

device = AT1000.open("at1000.local")
try:
    result = device.hmi.prompt(
        PromptRequest(
            text="Test failed.\nChoose the next action.",
            choices=[
                PromptChoice(label="Retry", color="#1769AA"),
                "Skip",  # shorthand for PromptChoice(label="Skip")
                PromptChoice(label="Cancel", color="#B3261E"),
            ],
            default_index=2,
            timeout_ms=60_000,
        )
    )
    print(result.status, result.selection.label, result.selection.index)
finally:
    device.close()
```

- `status` is `selected`, `cancelled`, or `timed_out`. `selection` is always set: the chosen choice, or the last highlighted one.
- 1 to 32 choices. Text is at most 256 UTF-8 bytes, each label at most 64 UTF-8 bytes, and neither may be blank.
- `timeout_ms` is 1,000 to 1,800,000 (default 60,000). The first knob turn stops the timeout.
- `default_index` sets the initial highlight. It is not selected automatically on timeout.
- A prompt needs an owning session, and only one can be active. Screen changes and raw knob reads conflict with it while it is pending.

See the [HMI documentation](https://ikalogic.com/kb/at1000-api/hmi/) for the full behaviour.

## Examples

The SDK source tree has runnable scripts in `examples/`. Each needs a device on the network:

- `discovery.py`: mDNS discovery with the default and a custom timeout.
- `example.py`: async discovery, then print the device information and capabilities.
- `gpio_sequence.py`: digital and analog outputs, readback, and a GPIO sequence run in one request.
- `hmi_prompt.py`: a colored-choice prompt, sync or `--async`.
- `i2c_sensor_check.py`: I2C transactions against two sensor breakouts, from both clients.

## Documentation

Full API documentation, with Python snippets for every subsystem, is at <https://ikalogic.com/kb/at1000-api/at1000_home/>.

## License

This package is distributed under the MIT License.
