forked from labgrid-project/labgrid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
driver/pyvisadriver: add driver to support PyVISA
Add driver and resource to support controlling test instruments using the PyVISA package. Signed-off-by: Kasper Revsbech <[email protected]>
- Loading branch information
Showing
11 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
targets: | ||
main: | ||
resources: | ||
PyVISADevice: | ||
type: "TCPIP" | ||
url: "192.168.110.11" | ||
drivers: | ||
PyVISADriver: | ||
name: "PyVisa_device" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture() | ||
def signal_generator(target): | ||
return target.get_driver('PyVISADriver').get_session() | ||
|
||
|
||
def test_with_signal_generator_example(signal_generator): | ||
signal_generator.write('*RST') | ||
|
||
# Setup channel 1 | ||
signal_generator.write('C1:BSWV WVTP,SQUARE,HLEV,5,LLEV,0,DUTY,50') | ||
# Switch on channel 1 | ||
signal_generator.write('C1:OUTP ON,LOAD,HZ,PLRT,NOR') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from importlib import import_module | ||
import attr | ||
|
||
from ..factory import target_factory | ||
from .common import Driver | ||
|
||
|
||
@target_factory.reg_driver | ||
@attr.s(eq=False) | ||
class PyVISADriver(Driver): | ||
"""The PyVISADriver provides a transparent layer to the PyVISA module allowing to get a pyvisa resource | ||
Args: | ||
bindings (dict): driver to use with PyVISA | ||
""" | ||
bindings = {"pyvisa_resource": "PyVISADevice"} | ||
|
||
def __attrs_post_init__(self): | ||
super().__attrs_post_init__() | ||
_py_pyvisa_module = import_module('pyvisa') | ||
self._pyvisa_resource_manager = _py_pyvisa_module.ResourceManager() | ||
self.pyvisa_device = None | ||
|
||
def on_activate(self): | ||
device_identifier = '{}::{}::INSTR'.format(self.pyvisa_resource.type, self.pyvisa_resource.url) | ||
self.pyvisa_device = self._pyvisa_resource_manager.open_resource(device_identifier) | ||
|
||
def on_deactivate(self): | ||
self.pyvisa_device = None | ||
|
||
@Driver.check_active | ||
def get_session(self): | ||
return self.pyvisa_device |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import attr | ||
|
||
from ..factory import target_factory | ||
from .common import Resource | ||
|
||
|
||
@target_factory.reg_resource | ||
@attr.s(eq=False) | ||
class PyVISADevice(Resource): | ||
"""The PyVISADevice describes a test stimuli device controlled with PyVISA | ||
Args: | ||
type (str): device resource type following the pyVISA resource syntax, e.g. ASRL, TCPIP... | ||
url (str): device identifier on selected resource, e.g. <ip> for TCPIP resource | ||
""" | ||
type = attr.ib(validator=attr.validators.instance_of(str)) | ||
url = attr.ib(validator=attr.validators.instance_of(str)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pyvisa==1.10.1 | ||
PyVISA-py==0.4.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from labgrid.resource.pyvisa import PyVISADevice | ||
from labgrid.driver.pyvisadriver import PyVISADriver | ||
|
||
|
||
def test_pyvisa_resource(target): | ||
PyVISADevice(target, name=None, type='TCPIP', url='127.0.0.1') | ||
|
||
|
||
def test_resource_driver(target, mocker): | ||
PyVISADevice(target, name=None, type='TCPIP', url='127.0.0.1') | ||
driver = PyVISADriver(target, name=None) | ||
|
||
mocker.patch('pyvisa.ResourceManager.open_resource', return_value=None) | ||
target.activate(driver) |