> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lagerdata.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Net

> Core Net class for managing hardware connections

The `Net` class is the primary abstraction for interacting with hardware instruments. It provides a unified interface for controlling different types of hardware including power supplies, oscilloscopes, GPIO, ADC, DAC, and more.

## Import

```python theme={null}
from lager import Net, NetType

# For exception handling
from lager import InvalidNetError, SetupFunctionRequiredError
```

## Class Methods

| Method | Description |
| - | - |
| `Net.get()` | Create a Net instance for the specified net name and type |
| `Net.list_saved()` | List all nets configured on the Lager Box |
| `Net.list_all_from_env()` | List nets from environment (legacy) |
| `Net.get_local_nets()` | Get all local net configurations |
| `Net.save_local_nets()` | Save multiple net configurations |
| `Net.save_local_net()` | Save a single net configuration |
| `Net.delete_local_net()` | Delete a net configuration |
| `Net.delete_all_local_nets()` | Delete all net configurations |
| `Net.rename_local_net()` | Rename a net configuration |
| `Net.filter_nets()` | Return a list without the nets that match a name and role |

## Instance Methods

| Method | Description |
| - | - |
| `enable()` | Enable the net and connect to hardware |
| `disable()` | Disable the net and disconnect from hardware |

## Method Reference

### `Net.get(name, type, *, setup_function=None, teardown_function=None)`

Create a Net instance for the specified net name and type.

```python theme={null}
# Get a power supply net
psu = Net.get('VDD', type=NetType.PowerSupply)

# Get a GPIO net
led = Net.get('LED', type=NetType.GPIO)

# Get an analog oscilloscope net
scope = Net.get('PROBE', type=NetType.Analog)
```

**Parameters:**

| Parameter | Type | Description |
| - | - | - |
| `name` | `str` | Name of the net to create |
| `type` | `NetType` | Type of net (e.g., `NetType.PowerSupply`, `NetType.GPIO`) |
| `setup_function` | `callable` | Optional function called when net is enabled |
| `teardown_function` | `callable` | Optional function called when net is disabled |

**Returns:** An object for the net's role. For most roles this is a role-specific class,
for example `LabJackGPIO`, `DebugNet`, `UARTNet`, `YubiHsm2` or a supply function mapper.
Those classes have the methods on the role's page, and they do not always have `enable()`
and `disable()`.

### `Net.list_saved()`

List all nets configured on the Lager Box.

```python theme={null}
nets = Net.list_saved()
for net in nets:
    print(f"{net['name']}: {net['role']}")
```

**Returns:** `list[dict]` - List of net configurations with keys:

* `name` (str) - Net name
* `role` (str) - Net type/role
* `pin` (str) - Hardware channel, as `lager nets add` saved it
* `instrument` (str) - Associated instrument type
* `address` (str) - Instrument address

### `Net.list_all_from_env()`

List nets from the LAGER\_MUXES environment variable (legacy behavior).

```python theme={null}
nets = Net.list_all_from_env()
for net in nets:
    print(f"{net['name']}: {net['role']} on channel {net['channel']}")
```

**Returns:** `list[dict]` - List of net information

### `Net.save_local_net(data)`

Save a net configuration to the Lager Box.

```python theme={null}
Net.save_local_net({
    'name': 'VDD',
    'role': 'power-supply',
    'pin': '1',
    'instrument': 'Rigol_DP832',
    'address': '192.168.1.100'
})
```

**Parameters:**

| Parameter | Type | Description |
| - | - | - |
| `data` | `dict` | Net configuration dictionary |

### `Net.delete_local_net(name, role=None)`

Delete a net configuration from the Lager Box.

```python theme={null}
# Delete by name only
Net.delete_local_net('VDD')

# Delete by name and role
Net.delete_local_net('VDD', role='power-supply')
```

**Parameters:**

| Parameter | Type | Description |
| - | - | - |
| `name` | `str` | Name of net to delete |
| `role` | `str` | Optional role to match |

**Returns:** `bool` - True if net was deleted

### `Net.rename_local_net(old_name, new_name)`

Rename a net configuration.

```python theme={null}
Net.rename_local_net('OLD_NAME', 'NEW_NAME')
```

**Parameters:**

| Parameter | Type | Description |
| - | - | - |
| `old_name` | `str` | Current net name |
| `new_name` | `str` | New net name |

**Returns:** `bool` - True if net was renamed

### `Net.get_local_nets()`

Get all local net configurations.

```python theme={null}
nets = Net.get_local_nets()
for net in nets:
    print(f"{net['name']}: {net['role']}")
```

**Returns:** `list[dict]` - List of net configuration dictionaries

### `Net.save_local_nets(nets)`

Save multiple net configurations at once.

```python theme={null}
Net.save_local_nets([
    {'name': 'VDD', 'role': 'power-supply', 'pin': '1', 'instrument': 'Rigol_DP832', 'address': '192.168.1.100'},
    {'name': 'GND', 'role': 'power-supply', 'pin': '2', 'instrument': 'Rigol_DP832', 'address': '192.168.1.100'}
])
```

**Parameters:**

| Parameter | Type | Description |
| - | - | - |
| `nets` | `list[dict]` | List of net configuration dictionaries |

### `Net.delete_all_local_nets()`

Delete all net configurations from the Lager Box.

```python theme={null}
Net.delete_all_local_nets()
```

**Returns:** `bool` - True if nets were deleted

### `Net.filter_nets(all_nets, name, role=None)`

Return the list without the nets that match a name, and optionally a role. This is the
helper `delete_local_net()` uses. To find a net, filter the list yourself:
`[n for n in all_nets if n['name'] == 'VDD']`.

```python theme={null}
all_nets = Net.get_local_nets()

# Every net except the ones named 'VDD'
without_vdd = Net.filter_nets(all_nets, 'VDD')

# Every net except 'VDD' with this role
without_vdd_psu = Net.filter_nets(all_nets, 'VDD', role='power-supply')
```

**Parameters:**

| Parameter | Type | Description |
| - | - | - |
| `all_nets` | `list[dict]` | List of nets to search |
| `name` | `str` | Net name to remove |
| `role` | `str` | Optional role to match |

**Returns:** `list[dict]` - The nets that do not match

### `enable()`

Enable the net and connect to hardware.

```python theme={null}
scope = Net.get('PROBE', type=NetType.Analog)
scope.enable()  # Connect to oscilloscope
```

**Behavior by net type:**

* **Analog**: Connects to multiplexer and enables oscilloscope channel
* **Logic**: Enables logic analyzer channel
* **Battery**: Enables battery simulation output
* **PowerSupply**: Enables power supply output
* **ELoad**: Enables electronic load

### `disable(teardown=True)`

Disable the net and disconnect from hardware.

```python theme={null}
scope.disable()  # Disconnect and run teardown
scope.disable(teardown=False)  # Disconnect without teardown
```

**Parameters:**

| Parameter | Type | Default | Description |
| - | - | - | - |
| `teardown` | `bool` | `True` | Whether to call teardown function |

## NetType Enum

Available net types:

| NetType | Role String | Description |
| - | - | - |
| `NetType.Analog` | `analog`, `scope`, `scope-channel` | Oscilloscope. A `scope` net is the instrument; a `scope-channel` net is one of its channels |
| `NetType.Logic` | `logic` | Logic analyzer input |
| `NetType.Waveform` | `waveform` | Not implemented. No driver backs this type, so `Net.get()` raises `NotImplementedError` |
| `NetType.Battery` | `battery` | Battery simulator |
| `NetType.PowerSupply` | `power-supply` | Power supply |
| `NetType.ELoad` | `eload` | Electronic load |
| `NetType.GPIO` | `gpio` | Digital I/O |
| `NetType.ADC` | `adc` | Analog-to-digital converter |
| `NetType.DAC` | `dac` | Digital-to-analog converter |
| `NetType.Thermocouple` | `thermocouple` | Temperature sensor |
| `NetType.DMM` | `dmm` | Bench multimeter |
| `NetType.BleSniffer` | `ble-sniffer` | Bluetooth LE sniffer |
| `NetType.Hsm` | `hsm` | Hardware security module |
| `NetType.WattMeter` | `watt-meter` | Power meter |
| `NetType.EnergyAnalyzer` | `energy-analyzer` | Energy analyzer |
| `NetType.UART` | `uart` | Serial communication |
| `NetType.SPI` | `spi` | SPI bus |
| `NetType.I2C` | `i2c` | I2C bus |
| `NetType.Webcam` | `webcam` | Webcam stream |
| `NetType.Router` | `router`, `mikrotik` | MikroTik router |
| `NetType.Debug` | `debug` | Debug probe |
| `NetType.Arm` | `arm` | Robotic arm |
| `NetType.Usb` | `usb` | USB device |
| `NetType.Rotation` | `rotation` | Rotary encoder |
| `NetType.Wifi` | `wifi` | WiFi module |
| `NetType.Actuate` | `actuate` | Actuator control |
| `NetType.PowerSupply2Q` | `power-supply-2q` | Two-quadrant power supply. Solar nets use `NetType.Solar` |
| `NetType.Solar` | `solar` | Solar simulator; see [Solar Simulation](https://docs.lagerdata.com/source/reference/python/solar.md) |

## Properties

### `name`

Get the net name.

```python theme={null}
print(net.name)  # 'VDD'
```

### `type`

Get the net type.

```python theme={null}
print(net.type)  # NetType.PowerSupply
```

## Examples

### List and Use Nets

```python theme={null}
from lager import Net, NetType

# List all available nets
nets = Net.list_saved()
print("Available nets:")
for net in nets:
    print(f"  {net['name']}: {net['role']}")

# Get and use a specific net
psu = Net.get('VDD', type=NetType.PowerSupply)
psu.set_voltage(3.3)
psu.enable()
```

### Simple Nets (GPIO, ADC, DAC)

```python theme={null}
from lager import Net, NetType

# GPIO - no enable/disable needed
button = Net.get('BUTTON', type=NetType.GPIO)
state = button.input()

led = Net.get('LED', type=NetType.GPIO)
led.output(1)

# ADC - no enable/disable needed
sensor = Net.get('SENSOR', type=NetType.ADC)
voltage = sensor.input()

# DAC - no enable/disable needed
vref = Net.get('VREF', type=NetType.DAC)
vref.output(2.5)
```

### Complex Nets (Power, Scope)

```python theme={null}
from lager import Net, NetType

# Power supply - requires enable/disable
psu = Net.get('VDD', type=NetType.PowerSupply)
psu.set_voltage(3.3)
psu.set_current(0.5)
psu.enable()
# ... use the power supply ...
psu.disable()

# Oscilloscope - requires enable/disable
scope = Net.get('PROBE', type=NetType.Analog)
scope.enable()
freq = scope.measurement.frequency()
scope.disable()
```

### Manage Net Configuration

```python theme={null}
from lager import Net

# Save a new net
Net.save_local_net({
    'name': 'NEW_PSU',
    'role': 'power-supply',
    'pin': '2',
    'instrument': 'Rigol_DP832',
    'address': '192.168.1.100'
})

# Rename a net
Net.rename_local_net('NEW_PSU', 'MAIN_POWER')

# Delete a net
Net.delete_local_net('MAIN_POWER')
```

## Notes

* Simple nets (GPIO, ADC, DAC, Thermocouple) work directly without `enable()`/`disable()` calls
* Complex nets (Analog, Logic, PowerSupply, Battery, ELoad) require `enable()` before use
* Always call `disable()` when finished with complex nets to properly release hardware
* Net names must match those configured on the Lager Box
* Use `Net.list_saved()` to see all available nets


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.