Skip to content

Commit

Permalink
deploy: c86e55d
Browse files Browse the repository at this point in the history
  • Loading branch information
tfcollins committed Jun 5, 2024
1 parent c4ed01c commit 6439650
Show file tree
Hide file tree
Showing 21 changed files with 1,441 additions and 41 deletions.
33 changes: 33 additions & 0 deletions main/_sources/config_file.md.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Configuration

pybench instruments can be configured in two main ways. The first by providing the instrument address to the constructor of the instrument class, and the second by using a configuration file. The configuration file is a YAML file that defines the instruments available to pybench and their addresses. Using configuration files is useful when you have multiple instruments that you want to use in your tests, or if you want to keep the instrument addresses separate from your test code. pybench looks for local and global configuration files, which can be handy when you want to have multiple test code bases that use the same instruments.

## Configuration file format

The configuration file is a YAML file that defines the instruments available to pybench and their addresses. The configuration file is structured as follows:

```yaml

instrument1:
address: "address1"
type: "instrument_type"
instrument2:
address: "address2"
type: "instrument_type2"
```

Example configuration file:

```yaml
powersupply:
address: "TCPIP0::192.168.10.31::inst0::INSTR"
type: E36233A
specan:
address: "TCPIP::192.168.10.21::inst0::INSTR"
type: N9040B
siggen:
address: "TCPIP::192.168.10.41::inst0::INSTR"
type: SMA100A
```

The "type" field must match an instrument class in pybench. The address field is the address of the instrument, which is used to connect to the instrument. Note that the address field does not need to be TCP/IP addresses, but can be any address that the instrument class can use to connect to the instrument.
52 changes: 52 additions & 0 deletions main/_sources/example_usage.md.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Usage Model

All supported instruments within pybench have a similar API and usage model. This allows for a consistent experience when using different instruments in your tests. This page describes the usage model for pybench instruments through examples.

## Basic usage

The following example demonstrates how to use a power supply instrument to set the output voltage and current, and then enable the output.

```python
from bench.keysight import E36233A

# Create an instance of the power supply
ps = E36233A("TCPIP0::192.168.1.1::inst0::INSTR")

# Set the output voltage to 5V for channel 1
ps.ch1.voltage = 5

# Set the output current to 1A for channel 2
ps.ch2.current = 1

# Enable the output for channel 1
ps.ch1.output_enabled = True

# Check output operational mode
print(ps.ch1.operational_mode)
```

## Using configuration files

The following example demonstrates how to use a configuration file to define the instruments available to pybench.

We will use the following configuration file ("bench.yaml") to define the instruments available to pybench:
```yaml
siggen:
address: "TCPIP::192.168.1.2::inst0::INSTR"
type: SMA100A
```

Next we will use the configuration file to create an instance of the signal generator instrument. By default pybench will look in the local directory for the configuration file. If the configuration file is not found, pybench will look in the global configuration directory based on the class property *config_locations*.
```python
siggen = SMA100A.from_config(use_config_file=True)

# Set the frequency to 1 GHz
siggen.frequency = 1e9

# Set the output power to -10 dBm
siggen.level = -10

# Enable the output
siggen.output_enable = True
```

16 changes: 16 additions & 0 deletions main/_sources/frameworks/pytest.md.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# pytest

pybench can be integrated with pytest by either directly using instrument classes or by leveraging the `pytest` fixtures provided by pybench. The fixtures are designed to help manage the lifecycle of the instrument and the data acquisition process. This also includes requiring instruments for tests, or making them interchangeable based on what a user has physical access to.

## CLI options

The following CLI options are available for use with pytest:

- `--confifile`: Path to the configuration file to use for the test run. If not provided, the default configuration file will be used. This is the configuration that defines which instruments are available and their addresses.

## Available fixtures

The following fixtures are available for use in your tests:

- `instrument_addresses`: A fixture that returns a list of all available instruments of those specified in the configuration file.
- `instrument_address_session`: A fixture that returns a session-scoped instrument address. This is useful for tests that require an instrument to be available for the duration of all tests.
24 changes: 23 additions & 1 deletion main/_sources/index.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,40 @@
pybench: Lab Bench Instrument Controls in Python
================================================

pybench is a Python package for controlling lab bench instruments. It is designed to be easy to use and to provide a consistent interface to a wide variety of instruments. pybench primarily uses the VISA standard for instrument communication, but supports other communication methods as well.

The module is designed to also support testing frameworks, such as pytest, and to support modern CI driven development and testing.

.. toctree::
:maxdepth: 1
:caption: Contents:
:caption: User Guide

install.md
example_usage
instruments/index


.. toctree::
:maxdepth: 1
:caption: Frameworks

frameworks/pytest


.. toctree::
:maxdepth: 1
:caption: Special Functionality

config_file

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

Disclaimer
==========

This package is not endorsed by or affiliated with any of the instrument manufacturers. It is a community driven project and is not officially supported by any of the instrument manufacturers.
13 changes: 12 additions & 1 deletion main/_sources/install.md.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
# Dependencies
# Installation

The module is compatible with Python 3.6 and above. It is recommended to use a virtual environment to install the module. To install the module, run the following command:

```bash
python -m venv venv
(Windows) venv\Scripts\activate
(Linux) source venv/bin/activate
pip install pybench
```

The majority of the dependencies are installed via `pip` when installing the module or by using the `requirements.txt` file when using the source repo. However, there are some dependencies that need to be installed manually for certain instruments to work or improve their functionality.

## Keysight

Expand Down
Loading

0 comments on commit 6439650

Please sign in to comment.