Skip to content

Instantly share code, notes, and snippets.

@LongnoseRob
Created May 15, 2021 04:20
Show Gist options
  • Save LongnoseRob/6e48ab2df96ef7ae5fa0083bd6181a12 to your computer and use it in GitHub Desktop.
Save LongnoseRob/6e48ab2df96ef7ae5fa0083bd6181a12 to your computer and use it in GitHub Desktop.
PyVisa lowlevel tests part 1/n
cloned pyvisa and pyvisa-py before
checked out origin/gpib-commands on both
robby@robquad builds]$ cd pyvisa-py/
[robby@robquad pyvisa-py]$ git status
HEAD detached at origin/gpib-commands
nothing to commit, working tree clean
[robby@robquad pyvisa-py]$ cd ..
[robby@robquad builds]$ cd pyvisa
[robby@robquad pyvisa]$ git status
HEAD detached at origin/gpib-commands
nothing to commit, working tree clean
[robby@robquad pyvisa]$ cd ..
creating virtual environment
[robby@robquad builds]$ python -m venv test_pyvisa
[robby@robquad builds]$ source test_pyvisa/bin/activate
(test_pyvisa) [robby@robquad builds]$ python -m pip install ~/builds/pyvisa
Processing ./pyvisa
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Collecting typing-extensions
Using cached typing_extensions-3.10.0.0-py3-none-any.whl (26 kB)
Building wheels for collected packages: PyVISA
Building wheel for PyVISA (PEP 517) ... done
Created wheel for PyVISA: filename=PyVISA-1.11.2.dev5+ga60ddbd-py3-none-any.whl size=184552 sha256=97a97248ccc694e6187507b95390b355c1afc8aec4faf3b87359943e7c635750
Stored in directory: /tmp/pip-ephem-wheel-cache-24sy0bzo/wheels/f4/2f/f0/ac46fe36474009811c51d339a5ef436894d5023a229ee4bec3
Successfully built PyVISA
Installing collected packages: typing-extensions, PyVISA
Successfully installed PyVISA-1.11.2.dev5+ga60ddbd typing-extensions-3.10.0.0
WARNING: You are using pip version 20.2.3; however, version 21.1.1 is available.
You should consider upgrading via the '/home/robby/builds/test_pyvisa/bin/python -m pip install --upgrade pip' command.
(test_pyvisa) [robby@robquad builds]$ python -m pip install ~/builds/pyvisa-py
Processing ./pyvisa-py
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Requirement already satisfied: pyvisa>=1.11.0 in ./test_pyvisa/lib/python3.9/site-packages (from PyVISA-py==0.5.2.dev9+gf41bfae) (1.11.2.dev5+ga60ddbd)
Requirement already satisfied: typing-extensions in ./test_pyvisa/lib/python3.9/site-packages (from PyVISA-py==0.5.2.dev9+gf41bfae) (3.10.0.0)
Building wheels for collected packages: PyVISA-py
Building wheel for PyVISA-py (PEP 517) ... done
Created wheel for PyVISA-py: filename=PyVISA_py-0.5.2.dev9+gf41bfae-py3-none-any.whl size=57215 sha256=2ec9dffcfb869c5137bd251de74cf278864ba29fbf7e9eb12663d067ca33268c
Stored in directory: /home/robby/.cache/pip/wheels/a8/ab/51/33a40b5c0f1ed2fe02462319c219f29820c81fa88f1f34eaa4
Successfully built PyVISA-py
Installing collected packages: PyVISA-py
Successfully installed PyVISA-py-0.5.2.dev9+gf41bfae
WARNING: You are using pip version 20.2.3; however, version 21.1.1 is available.
You should consider upgrading via the '/home/robby/builds/test_pyvisa/bin/python -m pip install --upgrade pip' command.
(test_pyvisa) [robby@robquad builds]$ python -m pip install gpib-ctypes
Collecting gpib-ctypes
Using cached gpib_ctypes-0.3.0-py2.py3-none-any.whl (16 kB)
Installing collected packages: gpib-ctypes
Successfully installed gpib-ctypes-0.3.0
WARNING: You are using pip version 20.2.3; however, version 21.1.1 is available.
You should consider upgrading via the '/home/robby/builds/test_pyvisa/bin/python -m pip install --upgrade pip' command.
(test_pyvisa) [robby@robquad builds]$ python3
Python 3.9.4 (default, Apr 20 2021, 15:51:38)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvisa
>>> from time import sleep
>>>
>>>
>>> rm=pyvisa.ResourceManager()
>>>
>>> #Some info and version gathering
>>> print(rm.list_resources_info())
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
libgpib: invalid descriptor
{'GPIB0::23::INSTR': ResourceInfo(interface_type=<InterfaceType.gpib: 1>, interface_board_number=0, resource_class='INSTR', resource_name='GPIB0::23::0::INSTR', alias=None)}
>>> print(rm.visalib.get_debug_info())
OrderedDict([('Version', '0.5.2.dev9+gf41bfae'), ('ASRL INSTR', ['Please install PySerial (>=3.0) to use this resource type.', "No module named 'serial'"]), ('USB INSTR', ['Please install PyUSB to use this resource type.', "No module named 'usb'"]), ('USB RAW', ['Please install PyUSB to use this resource type.', "No module named 'usb'"]), ('TCPIP INSTR', 'Available '), ('TCPIP SOCKET', 'Available '), ('GPIB INSTR', "Available via Linux GPIB (b'4.3.4')"), ('GPIB INTFC', "Available via Linux GPIB (b'4.3.4')")])
>>> print(rm.visalib.sessions)
{6018158: <PyVisaLibrary('py')>}
>>>
>>>
>>> my_inst = rm.open_resource('GPIB0::23::INSTR')
>>> my_inst.read_termination = '\r\n'
>>> my_inst.write_termination = '\r\n'
>>> print(rm.resource_info('GPIB0::23::INSTR'))
ResourceInfo(interface_type=<InterfaceType.gpib: 1>, interface_board_number=0, resource_class='INSTR', resource_name='GPIB0::23::0::INSTR', alias=None)
>>>
>>> # do a DCV measurement in auto-range and internal(automagic) trigger
>>> print('Measured value {} V'.format(float(my_inst.query('M1RAT1'))))
Measured value 1.26304 V
>>> my_inst.visalib.gpib_command(my_inst.session,command_byte=0x01)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/robby/builds/test_pyvisa/lib/python3.9/site-packages/pyvisa_py/highlevel.py", line 248, in gpib_command
return written, self.handle_return_value(session, st)
File "/home/robby/builds/test_pyvisa/lib/python3.9/site-packages/pyvisa/highlevel.py", line 251, in handle_return_value
raise errors.VisaIOError(rv)
pyvisa.errors.VisaIOError: VI_ERROR_NSUP_OPER (-1073807257): The given session or object reference does not support this operation.
>>> my_inst.close()
CTRL-D
(test_pyvisa) [robby@robquad builds]$ deactivate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment