semvec/pypi-packages huggingface dataset:
agiltron-selfalign 0.2.0
Python interface for the Agiltron SelfAlign fiber switch
License: MIT
Requires Python: >=3.11
Keywords: agiltron, fiber, lab-automation, serial, switch

# Agiltron-SelfAlign
[![Python versions on PyPI](https://img.shields.io/pypi/pyversions/agiltron-selfalign.svg)](https://pypi.org/project/agiltron-selfalign/)
[![agiltron-selfalign version on PyPI](https://img.shields.io/pypi/v/agiltron-selfalign.svg "Agiltron-SelfAlign on PyPI")](https://pypi.org/project/agiltron-selfalign/)

Python interface for the [Agiltron SelfAlign](https://agiltron.com/product/selfalign-series-1xn-switch-box/) fiber switch.

Requires Python 3.11 or newer.

## Install
```
uv add agiltron-selfalign
```

Or install directly from source:
```
uv add git+https://github.com/ograsdijk/Agiltron-SelfAlign.git
```

## Code Example
```Python
from agiltron_selfalign import AgiltronSelfAlign

resource_name = "COM8"
switch = AgiltronSelfAlign(resource_name, number_of_ports=16)

# change port to port 14
switch.set_fiber_port(14)

# home switch to port 1
switch.home()
```

## Context Manager Example
```Python
from agiltron_selfalign import AgiltronSelfAlign

resource_name = "COM8"

with AgiltronSelfAlign(resource_name, number_of_ports=16) as switch:
		switch.set_fiber_port(14)
		switch.home()
```

## API
- `AgiltronSelfAlign(resource_name, timeout=2.0, number_of_ports=16, baudrate=9600, write_timeout=None, inter_byte_timeout=None)`
	- Opens the serial connection to the switch.
	- `write_timeout=None` defaults to the read `timeout` value.
- `set_fiber_port(fiber_port)`
	- Switches to the requested fiber port and validates the acknowledgement frame.
- `home()`
	- Sends the home command to move the switch to port 1.
- `close()`
	- Closes the serial connection.
- `AgiltronSelfAlignError`
	- Raised for serial communication failures and protocol response errors.