Skip to content

Commit

Permalink
Add R&S scope and some doc
Browse files Browse the repository at this point in the history
Signed-off-by: Travis Collins <[email protected]>
  • Loading branch information
tfcollins committed May 23, 2024
1 parent 22c8f80 commit c9f8a31
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 8 deletions.
6 changes: 6 additions & 0 deletions bench.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
powersupply:
address: "TCPIP::192.168.10.31::inst0::INSTR"
type: E36233A
specan:
address: "TCPIP::192.168.10.21::inst0::INSTR"
type: N9040B
23 changes: 20 additions & 3 deletions bench/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class Common:
config_locations = [".", "/etc/"]
"""Paths to search for config"""

use_py_resource_manager = True
"""Use @py resource manager"""

use_config_file = False
"""Use config file to get address for instrument(s)"""

Expand Down Expand Up @@ -80,10 +83,10 @@ def _post_init_(self):
def __del__(self):
"""Close the instrument on object deletion"""
self._teardown = True
if hasattr(self, "_instr"):
if hasattr(self, "_instr") and self._instr:
self._instr.close()
self.address = None
if hasattr(self, "_rm"):
if hasattr(self, "_rm") and self._rm:
self._rm.close()

def connect(self):
Expand All @@ -93,7 +96,12 @@ def connect(self):
if not self.address:
self._find_device()
else:
self._instr = pyvisa.ResourceManager().open_resource(self.address)
common_log.info(f"Using address {self.address}")
if self.use_py_resource_manager:
self._rm = pyvisa.ResourceManager("@py")
else:
self._rm = pyvisa.ResourceManager()
self._instr = self._rm.open_resource(self.address)
self._connected = True
self._instr.timeout = 15000
self._instr.write("*CLS")
Expand All @@ -103,6 +111,15 @@ def connect(self):
f"Device at {self.address} is not a {self.id}. Got {q_id}"
)

def disconnect(self):
if not self._connected:
print("Not connected. Not doing anything")
return
self._instr.close()
self._instr = None
self._rm.close()
self._rm = None

def _find_dev_ind(self, rm):
all_resources = rm.list_resources()
for res in all_resources:
Expand Down
10 changes: 5 additions & 5 deletions bench/keysight/e36233a.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,26 @@ def current(self, value):
def output_enabled(self):
"""Enable output of channel (True) or disable output (False)"""
self._set_channel()
return self.parent._instr.query("OUTP:STAT?")
return bool(self.parent._instr.query("OUTP:STAT?"))

@output_enabled.setter
def output_enabled(self, value):
def output_enabled(self, value) -> bool:
self._set_channel()
value = 1 if value else 0
self.parent._instr.write(f"OUTP:STAT {value}")

@property
def operational_mode(self):
def operational_mode(self) -> str:
"""Get or set the operational mode of the channel. Options are:
OFF: Channel is off
SER: Channel is in series mode
PAR: Channel is in parallel mode
"""
self._set_channel()
return self.parent._instr.query("OUTP:PAIR?")
return str(self.parent._instr.query("OUTP:PAIR?")).replace("\n","")

@operational_mode.setter
def operational_mode(self, value):
def operational_mode(self, value: str):
self._set_channel()
if value not in ["OFF", "SER", "PAR"]:
raise Exception("Invalid operational mode. Must be one of: OFF, SER, PAR")
Expand Down
1 change: 1 addition & 0 deletions bench/rs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .sma100a import SMA100A
44 changes: 44 additions & 0 deletions bench/rs/sma100a.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import logging

import pyvisa
from bench.common import Common

class SMA100A(Common):
"""Rohde & Schwarz SMA100A Signal Generator"""

id = "SMA100A"
"""Substring returned by IDN query to identify the device"""

def _post_init_(self, address: str = None, use_config_file=False) -> None:
pass

@property
def frequency(self):
"""Get Frequency in Hz"""
return float(self._instr.query('SOUR:FREQ:CW?'))

@frequency.setter
def frequency(self, value:float):
"""Set Frequency in Hz"""
self._instr.write(f'FREQ {value}')

@property
def level(self):
"""Get output power level in dBm"""
return float(self._instr.query('SOUR:POW:POW?'))

@level.setter
def level(self, value):
"""Set output power level in dBm"""
self._instr.write(f'POW {value}')

@property
def output_enable(self):
"""Get output state"""
return bool(self._instr.query('Output1:STATe?'))

@output_enable.setter
def output_enable(self, value:bool):
"""Set output state (True == On, False == Off)"""
value = "1" if value else "0"
self._instr.write(f'Output1:STATe {value}')
1 change: 1 addition & 0 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pybench: Lab Bench Instrument Controls in Python
:maxdepth: 1
:caption: Contents:

install.md
instruments/index


Expand Down
6 changes: 6 additions & 0 deletions doc/source/install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Dependencies

## Keysight

Its recommended you install the IO Libraries and Drivers to communicate with instruments.
- [IO Libraries Suite Downloads](https://www.keysight.com/us/en/lib/software-detail/computer-software/io-libraries-suite-downloads-2175637.html)

0 comments on commit c9f8a31

Please sign in to comment.