PSU without background daemon#

psu.py#
"""Example: PSU without background daemon.

Demonstrates publishing measurements/commands to a dataset (Nominal Core publisher).

"""

import logging
import time

from instro.lib import install_nominal_core_log_handler
from instro.lib.publishers import NominalCorePublisher
from instro.psu import InstroPSU
from instro.psu.drivers import SimulatedPSU

# enable logging
logging.basicConfig(level=logging.DEBUG)

VISA_RESOURCE = "TCPIP0::127.0.0.1::5025::SOCKET"
DATASET_RID = "<dataset_rid>"  # Replace with your dataset RID.

# forward all debug logs to Nominal Core
install_nominal_core_log_handler(DATASET_RID, level=logging.DEBUG)

psu = InstroPSU(
    name="myPSU",
    driver=SimulatedPSU(VISA_RESOURCE),
    num_channels=2,
)

psu.add_publisher(NominalCorePublisher(dataset_rid=DATASET_RID))

# Alternatively, construct from JSON config file (see bench_psu.json):
# psu = InstroPSU(config="bench_psu.json")

with psu:
    # Set up initial state of test: current limit, then voltage, then output off
    psu.apply(current_limit=0.2, voltage=0, channel=2)

    time.sleep(0.5)

    psu.get_current(channel=2)
    psu.get_voltage(channel=2)

    psu.apply(current_limit=0.2, voltage=0.5, enable=True, channel=2)

    # Voltage sweep
    for v in range(10):
        psu.set_voltage(v, channel=2)
        time.sleep(1)

    psu.output_enable(False, channel=2)

Source: examples/psu/psu.py