Python at the workbench - SCPI control of lab instruments - Page 1
Forum section: electronics / projects

author: RoGeorge
author_rank: Super Contributor
timestamp: May 13, 2022, 03:50:24 pm
content: Code:pip install pyvisa-pypython3>>> import pyvisa as visa>>> dp832 = visa.ResourceManager('@py').open_resource('TCPIP::192.168.1.4::INSTR')>>> print (dp832.query("*IDN?"))RIGOL TECHNOLOGIES,DP832A,DP...,00.01.16>>> print(dp832.query(':MEASure:ALL? CH3'))3.1921,0.3004,0.959>>> # press CTRL+D to exit from python3Felt chatty today. These are some sort of personal learning notes. Trying to make a tale for beginners like me.\[ \star \ \star \ \star \]Say you have a power supply, or an oscilloscope, or some other instrument that can be controlled remotely, from a computer. You see weird acronyms in the instrument's user guide, like LXI, VISA, IVI, VXI, SCPI, GPIB, etc. Now what?That means that the instrument can listen to text commands sent from a computer, and can respond to those commands, and send measurements back to the computer when asked. There are many ways to talk SCPI with an instrument, can be through a USB cable, or RS232, or LAN, or WiFi, or GPIB.\[ \star \ \star \ \star \]Let's send some SCPI commands from Python. You have to have:- computer with Python3 installed- a lab instrument that can talk SCPI- a cable to connect the instrument to the PCRight now I'm using a Rigol DP832A power supply connected with a LAN cable, but it can be any other SCPI capable instrument, no matter the brand, or if it's a power supply or an oscilloscope. My OS is Ubuntu, it should work the same from Windows, or Mac, too, but I didn't try.There is no need to install additional programs, or drivers, or NI-VISA, or IVI, or whatever other software you may have received together with the instrument. However, there is a module that has to be added to Python, pyvisa. Open a terminal (a command prompt) and type:Code:pip install pyvisa-pyThat's it, all installed now.(Skipabble gibberish details: 'pyvisa' and 'pyvisa-py' are not the same thing. 'pyvisa' is the frontend, it can use different backend VISA libraries, either the proprietary NI-VISA or the open source backend 'pyvisa-py'. The backend is the component knowing VISA, and how to talk over different LAN, USB or COM. Installing 'pyvisa' alone will only work if a backend is already present. Installing 'pyvisa-py' with pip will also install 'pyvisa')\[ \star \ \star \ \star \]Connect the LAN cable and give a fixed IP to the instrument. Mine has the IP address 192.168.1.4, so whenever this address will appear in the next examples, replace it with the address of your instrument. To be sure it's all working, open a terminal and type:Code:ping 192.168.1.4and the instrument should respond. Just to be sure it's your instrument responding and not some other device, power off the instrument and the ping shouldn't work any more. If all good, power the instrument on, and now let's try from Python.\[ \star \ \star \ \star \]Open a terminal and typeCode:python3# at the python prompt, >>>, type>>> import pyvisa as visa>>> dp832 = visa.ResourceManager('@py').open_resource('TCPIP::192.168.1.4::INSTR')>>> # to send SCPI commands to the DP832 power supply and print the DP832's answer>>> # for example, the ':*IDN?' command asks the instrument to identify itself>>> print (dp832.query("*IDN?"))RIGOL TECHNOLOGIES,DP832A,DP...,00.01.16>>> # I have manually turned on CH3 with some power LEDs connected>>> # now let's read the Voltage, Current and Power measured by the DP832 at its channel 3>>> print(dp832.query(':MEASure:ALL? CH3'))3.1721,0.3004,0.951>>>Those numbers read by Python are the same numbers that were displayed on the DP832's front panel at that moment.\[ \star \ \star \ \star \]Once we have those numbers, we can do whatever we want with them in Python. For example we could save them in a file, or plot them in a chart, or combine them with some other data from some other instruments, or do automated testing, or conduct lab experiments in order to discover the meaning of everything!Works similar for other SCPI instruments, or with USB instead of LAN.

author: Wolfgang
author_rank: Super Contributor
timestamp: May 14, 2022, 07:15:08 pm
content: Hi George,I agree that SCPI is the way to go to control a multi-instrument, multi-vendor lab environment, and using python and VISA makes it simple enough. I prefer this over any LabView, BenchVue or other vendor integration layer. Its stable, its open, its flexible, there are no single vendor restrictions, and the math and engineering libraries of Python are a *lot* better than other stuff.The best thing is that you can create your own SCPI-based instruments and you can control them via Python as well.https://wordpress.com/stats/post/6495/electronicprojectsforfun.wordpress.comRegardsWolfgang

author: RoGeorge
author_rank: Super Contributor
timestamp: May 17, 2022, 11:59:33 am
content: The link doesn't work for me (try your link from a private browser window), you mean this one right?https://electronicprojectsforfun.wordpress.com/That's a very nice blog!I think I've met it already when googled for some RF projects.Same here about NI-VISA, I prefer small and open source components, the NI-VISA thing is a huge install, and I remember it as Windows only. The default backend for pyvisa might be the NI-VISA binaries, if installed, but I didn't check, so just to be sure it's using the pyvisa-py backend, I specify "py" when creating a new ResourceManager.That reminds me of some setup steps required for USB instruments in Linux:An example for controlling a Rigol DS1054z by USB from Python, using Ubuntu and pyvisa.(Make sure the oscilloscope is not in pict bridge mode, set it to "computer", on the oscilloscope buttons press "Utility" -> "IO Setting" -> "USB Device" to mode "Computer").Install the followingCode:pip install pyvisa-pypip install rlcompleter #optional, it helps with TAB autocompletion in interactive modesudo apt install python3-usbConfigure the followingCode:sudo groupadd usbtmcuserssudo usermod -a -G usbtmcusers $USERsudo suecho 'SUBSYSTEM=="usb", MODE="0666", GROUP="usbtmcusers"' >> /etc/udev/rules.d/90-grant-USB-access-for-users-in-group-usbtmcusers.rulesexit# reboot the computerAfter rebooting, plug the oscilloscope by its US cable, and check if all OKCode:lsusb# Bus 003 Device 013: ID 1ab1:04ce Rigol Technologies DS1000Z Seriesgetent group usbtmcusers# usbtmcusers:x:1001:your_usernamels -la /dev/usbtmc0# crw------- 1 root root 180, 0 May 17 14:22 /dev/usbtmc0Test it from Python, in interactive mode:Code:>>> import pyvisa as visa>>> import rlcompleter# double press TAB to reveal available functions from autocomplete# e.g. type "visa." at the ">>>" prompt then press TAB TAB>>> rm = visa.ResourceManager('@py')>>> print( rm.list_resources_info() )>>> print( rm.list_resources() )('USB0::6833::1230::DS1Zyour_serial_number::0::INSTR',)>>> ds1054z = rm.open_resource('USB0::6833::1230::DS1Zyour_serial_number::0::INSTR')>>> print( ds1054z.query('*IDN?') )/home/muuu/.local/lib/python3.8/site-packages/pyvisa_py/protocols/usbtmc.py:115: UserWarning: Unexpected MsgID format. Consider updating the device's firmware. See https://github.com/pyvisa/pyvisa-py/issues/20warnings.warn(RIGOL TECHNOLOGIES,DS1104Z,DS1Zyour_serial_number,00.04.05.SP2# first time might get this warn, it's about the string terminator# warns only once, it doesn't complain at the following commands>>> print( ds1054z.query('*IDN?') )RIGOL TECHNOLOGIES,DS1104Z,DS1Zyour_serial_number,00.04.05.SP2# to find the oscilloscope's SCPI commands, see the rigol ds1000z programming guide site rigolna.com# https://www.rigolna.com/products/digital-oscilloscopes/1000z/# https://beyondmeasure.rigoltech.com/acton/attachment/1579/f-0386/1/-/-/-/-/DS1000Z_Programming%20Guide_EN.pdf# turn channel 2 on, set the hardware frequency counter to channel 2, then read its value# SCPI to send# :CHANnel2:DISPlay ON# :MEASure:COUNter:SOURce CHAN2# :MEASure:COUNter:VALue?#>>> ds1054z.write(':CHANnel2:DISPlay ON')>>> ds1054z.write(':MEASure:COUNter:SOURce CHAN2')>>> ds1054z.query(':MEASure:COUNter:VALue?')'7.0725586e+02\n'>>> # CTRL+D to exitI'm not sure what should I mention how to do it, and what not. The intent is to explain everything as for a newcomer, those not very comfortable with programming, but this makes it all look like a complicated TL;DR.The brief alternative for all the above would be:\[ \star \ \star \ \star \]Connect with a Rigol DS1054z by USB, Python, pyvisa in Ubuntu.(first, from the oscilloscope, press "Utility" -> "IO Setting" -> "USB Device" to mode "Computer")Required computer installs/configure and reboot:Code:pip install pyvisa-pysudo apt install python3-usbsudo groupadd usbtmcuserssudo usermod -a -G usbtmcusers $USERsudo suecho 'SUBSYSTEM=="usb", MODE="0666", GROUP="usbtmcusers"' >> /etc/udev/rules.d/90-grant-USB-access-for-users-in-group-usbtmcusers.rulesrebootTest from Python:Code:import pyvisa as visarm = visa.ResourceManager('@py')print( rm.list_resources() )# ('USB0::6833::1230::DS1Zyour_serial_number::0::INSTR',)ds1054z = rm.open_resource('USB0::6833::1230::DS1Zyour_serial_number::0::INSTR')print( ds1054z.query('*IDN?') )# set the HW counter to CH2 and read the measured frequencyds1054z.write(':CHANnel2:DISPlay ON')ds1054z.write(':MEASure:COUNter:SOURce CHAN2')ds1054z.query(':MEASure:COUNter:VALue?')# '7.0725586e+02\n'Would it be better to keep it short like that?

author: RoGeorge
author_rank: Super Contributor
timestamp: May 19, 2022, 02:54:31 pm
content: Wanna GUI-Click!-Click with SCPI from Python?Download the DVD .iso of Kubuntu 20.04 LTS fromhttps://kubuntu.org/getkubuntu/,and run it in live mode, without installing anything on the current computer. Preferably would be to install VirtualBox on the current computer, and boot the DVD from inside the VirtualBox program, but this is not mandatory.Should work the same for Linux, or Windows, or Mac, when booting the live DVD. This will not mess with the existing computer, and it won't install or change anything permanently on the existing computer.\[ \star \ \star \ \star \]Once the Kubuntu live is running, open a terminal in Kubuntu live (with CTRL+ALT+T) and type (inside the running Kubuntu live in a Terminal - 100% tested and working):Code:sudo apt updatesudo apt install python3-pip idlepip install pysimplegui pyvisa-pyInside Kubuntu live, open IDLE, press CTRL+N to create a new Python3, write the following Python code to test PySimpleGUI, then press F5 to run it (give the file a name when asked to save):Code:import PySimpleGUI as sglayout = [[sg.Button('OK'), sg.Button('Cancel')]]window = sg.Window('GUI App', layout)while True:event, values = window.read()if event == sg.WIN_CLOSED:breakwindow.close()This should open a window with two buttons that can be clicked that does nothing (for now):New skill unlocked, create a window from Python!\[ \star \ \star \ \star \]For more info about PySimpleGUI, visit the PySimpleGUI dot orghttp://pysimplegui.orgpages, or for a step by step video, watchCreating 10 apps in Python with PySimpleGUIby Clear Code.Close the OK/Cancel window, and to add some SCPI functionality, make the following chahttps://www.eevblog.com/forum/programming/exit/?action=dlattach;attach=1490818;imagenges to the python file (inside IDLE):- add a textbox where one can type an SCPI command to be sent to the instrument- add a read-only textbox to display the instrument's reply- rename the previous buttons and change the window layout so they will become buttons for "Send" and "Exit".- for now, the instrument connection will be hardcoded, I've used a Rigol DS1054Z oscilloscope connected by a network cable (mine has the IP address 192.168.1.4, you should use the IP address of your instrument).Code: (Python)import PySimpleGUI as sgimport pyvisa as visaIP_address = '192.168.1.3'rm = visa.ResourceManager()ds1054z = rm.open_resource('TCPIP::' + IP_address + '::INSTR')layout = [[sg.Text('SCPI command:'), sg.Input('*IDN?', key='-SCPI-'), sg.Button('Send')],[sg.Text('Response:'), sg.Input('SCPI answer', key='-ANSWER-', expand_x=True, readonly=True)],[sg.Button('Exit')]]window = sg.Window('Simple SCPI Sender', layout, finalize=True)window['-SCPI-'].bind('<Return>', '_Enter')window['-SCPI-'].bind('<KP_Return>', '_Enter')while True:event, values = window.read()if event == sg.WIN_CLOSED:breakif event == 'Exit':breakif event == 'Send' or event == '-SCPI-' + '_Enter':if values['-SCPI-'][-1] == '?':answer = ds1054z.query(values['-SCPI-'])else:answer = ds1054z.write(values['-SCPI-'])window['-ANSWER-'].update(answer)ds1054z.close()rm.close()window.close()Run it with F5, and a window should pop:If you click 'Send' or press 'Enter' the command written in the textbox will be sent to the instrument (here the DS1054z oscilloscope) and the reply from the instrument will be displayed on the next row:\[ \star \ \star \ \star \]Type and send some other SCPI commands. For example, to interrogate the oscilloscope what is its current timebase setting, send the SCPI command:Code:TIM:SCAL?To set the horizontal timebase to 2ms/div, send the command:Code:TIMebase:MAIN:SCALe 0.002and so on. The response "28" in this case indicates the total length of the sent SCPI command (26 letters plus 2 the <CR><LF> line termination characters).For this Rigol DS1000Z series oscilloscope, the command for the timebase has this format:QuoteThe parts written between square brackets are optional, same the small letters, so either the full length or the short format "TIM:SCAL" will be understood by the oscilloscope.(lookup the programming user guide of your instrument to find supported commands, for the Rigol DS1054Z oscilloscope, the programming guide can be found athttps://beyondmeasure.rigoltech.com/acton/attachment/1579/f-0386/1/-/-/-/-/DS1000Z_Programming%20Guide_EN.pdf)

author: dagema
author_rank: Contributor
timestamp: May 19, 2022, 09:44:39 pm
content: Hi, has anyone been able to get it to work on Windows10? When I try it, I get the following errors:C:\Users\donnie>pip install pyvisa-pyCollecting pyvisa-pyDownloading PyVISA_py-0.5.3-py3-none-any.whl (59 kB)---------------------------------------- 59.0/59.0 kB 774.3 kB/s eta 0:00:00Collecting pyvisa>=1.12.0Using cached PyVISA-1.12.0-py3-none-any.whl (175 kB)Collecting typing-extensionsUsing cached typing_extensions-4.2.0-py3-none-any.whl (24 kB)Installing collected packages: typing-extensions, pyvisa, pyvisa-pyWARNING: The scripts pyvisa-info.exe and pyvisa-shell.exe are installed in 'C:\Users\donnie\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\Scripts' which is not on PATH.Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.Successfully installed pyvisa-1.12.0 pyvisa-py-0.5.3 typing-extensions-4.2.0C:\Users\donnie>python3Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license" for more information.>>> import pyvisa as visa>>> EEZ = visa.ResourceManager('@py').open_resource('TCPIP::10.2.2.50::INSTR')Traceback (most recent call last):File "C:\Users\donnie\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyvisa_py\tcpip.py", line 74, in after_parsingself.interface = vxi11.CoreClient(File "C:\Users\donnie\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyvisa_py\protocols\vxi11.py", line 202, in __init__super(CoreClient, self).__init__(File "C:\Users\donnie\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyvisa_py\protocols\rpc.py", line 768, in __init__pmap = TCPPortMapperClient(host, open_timeout)File "C:\Users\donnie\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyvisa_py\protocols\rpc.py", line 748, in __init__RawTCPClient.__init__(self, host, PMAP_PROG, PMAP_VERS, PMAP_PORT, open_timeout)File "C:\Users\donnie\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyvisa_py\protocols\rpc.py", line 457, in __init__self.connect((open_timeout / 1000.0) + 1.0)File "C:\Users\donnie\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyvisa_py\protocols\rpc.py", line 491, in connectraise RPCError("can't connect to server")pyvisa_py.protocols.rpc.RPCError: can't connect to serverDuring handling of the above exception, another exception occurred:Traceback (most recent call last):File "<stdin>", line 1, in <module>File "C:\Users\donnie\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyvisa\highlevel.py", line 3284, in open_resourceres.open(access_mode, open_timeout)File "C:\Users\donnie\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyvisa\resources\resource.py", line 278, in openself.session, status = self._resource_manager.open_bare_resource(File "C:\Users\donnie\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyvisa\highlevel.py", line 3209, in open_bare_resourcereturn self.visalib.open(self.session, resource_name, access_mode, open_timeout)File "C:\Users\donnie\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyvisa_py\highlevel.py", line 167, in opensess = cls(session, resource_name, parsed, open_timeout)File "C:\Users\donnie\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyvisa_py\sessions.py", line 325, in __init__self.after_parsing()File "C:\Users\donnie\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyvisa_py\tcpip.py", line 78, in after_parsingraise errors.VisaIOError(constants.VI_ERROR_RSRC_NFOUND)pyvisa.errors.VisaIOError: VI_ERROR_RSRC_NFOUND (-1073807343): Insufficient location information or the requested device or resource is not present in the system.>>>A ping to the EEZ power supply at 10.2.2.50 responds, and the EEZ Studio can send and recieve SCPI commands to it without problems.I have never used Python before, so I have no idea what is causing the errors.Any suggestions?Thanks

author: RoGeorge
author_rank: Super Contributor
timestamp: May 20, 2022, 01:18:22 am
content: What instrument is the one you try to connect?Look in its programing guide documentation and find if it is VISA or LXI compliant.I don't have Windows. On a clean Windows install it should work. Might be some installation conflict, or the python paths were added at the end instead of being added first, or some other Windows settings are cutting the access, I don't know.Type at a command prompt 'pyvisa-info', maybe you get some clue. One of the lines should read "TCPIP INSTR: Available" and another line "TCPIP SOCKET: Available".Could also be that the instrument responds to other resource string format.https://pyvisa.readthedocs.io/en/1.8/names.htmlThe easiest way would be to install VirtualBox, download Kubuntu 20.04 LTS and create a virtual machine with Kubuntu (inside VirtualBox), and try from there (because it was tested and known as working). Ubuntu is as easy to use as Windows, and you can have both Windows 10 and Kubuntu 20.04 running at the same time. Kubuntu will be just like any other program running inside a window, it won't overwrite the existing Windows10 install.

author: dagema
author_rank: Contributor
timestamp: May 23, 2022, 05:53:40 pm
content: Thank you for your reply. I am trying to connect to an EEZ H24005 dual channel power supply. I have attached a screenshot of the device in use with it's SCPI interface application EEZ Studio. I installed Python3 on a fresh Ubuntu 20.04 installation, then PIP, then pyvisa:donnie@UD5:~$ sudo apt install python3-pip Passwort für donnie:Paketlisten werden gelesen... FertigAbhängigkeitsbaum wird aufgebaut.Statusinformationen werden eingelesen.... FertigDie folgenden zusätzlichen Pakete werden installiert:libpython3-dev libpython3.8-dev python-pip-whl python3-devpython3-setuptools python3-wheel python3.8-devVorgeschlagene Pakete:python-setuptools-docDie folgenden NEUEN Pakete werden installiert:libpython3-dev libpython3.8-dev python-pip-whl python3-dev python3-pippython3-setuptools python3-wheel python3.8-dev0 aktualisiert, 8 neu installiert, 0 zu entfernen und 4 nicht aktualisiert.Es müssen 6.864 kB an Archiven heruntergeladen werden.Nach dieser Operation werden 25,5 MB Plattenplatz zusätzlich benutzt.Möchten Sie fortfahren? [J/n]Holen:1http://de.archive.ubuntu.com/ubuntufocal-updates/main amd64 libpython3.8-dev amd64 3.8.10-0ubuntu1~20.04.4 [3.952 kB]Holen:2http://de.archive.ubuntu.com/ubuntufocal/main amd64 libpython3-dev amd64 3.8.2-0ubuntu2 [7.236 B]Holen:3http://de.archive.ubuntu.com/ubuntufocal-updates/universe amd64 python-pip-whl all 20.0.2-5ubuntu1.6 [1.805 kB]Holen:4http://de.archive.ubuntu.com/ubuntufocal-updates/main amd64 python3.8-dev amd64 3.8.10-0ubuntu1~20.04.4 [514 kB]Holen:5http://de.archive.ubuntu.com/ubuntufocal/main amd64 python3-dev amd64 3.8.2-0ubuntu2 [1.212 B]Holen:6http://de.archive.ubuntu.com/ubuntufocal/main amd64 python3-setuptools all 45.2.0-1 [330 kB]Holen:7http://de.archive.ubuntu.com/ubuntufocal/universe amd64 python3-wheel all 0.34.2-1 [23,8 kB]Holen:8http://de.archive.ubuntu.com/ubuntufocal-updates/universe amd64 python3-pip all 20.0.2-5ubuntu1.6 [231 kB]Es wurden 6.864 kB in 15 s geholt (473 kB/s).Vormals nicht ausgewähltes Paket libpython3.8-dev:amd64 wird gewählt.(Lese Datenbank ... 230393 Dateien und Verzeichnisse sind derzeit installiert.)Vorbereitung zum Entpacken von .../0-libpython3.8-dev_3.8.10-0ubuntu1~20.04.4_amd64.deb ...Entpacken von libpython3.8-dev:amd64 (3.8.10-0ubuntu1~20.04.4) ...Vormals nicht ausgewähltes Paket libpython3-dev:amd64 wird gewählt.Vorbereitung zum Entpacken von .../1-libpython3-dev_3.8.2-0ubuntu2_amd64.deb ...Entpacken von libpython3-dev:amd64 (3.8.2-0ubuntu2) ...Vormals nicht ausgewähltes Paket python-pip-whl wird gewählt.Vorbereitung zum Entpacken von .../2-python-pip-whl_20.0.2-5ubuntu1.6_all.deb ...Entpacken von python-pip-whl (20.0.2-5ubuntu1.6) ...Vormals nicht ausgewähltes Paket python3.8-dev wird gewählt.Vorbereitung zum Entpacken von .../3-python3.8-dev_3.8.10-0ubuntu1~20.04.4_amd64.deb ...Entpacken von python3.8-dev (3.8.10-0ubuntu1~20.04.4) ...Vormals nicht ausgewähltes Paket python3-dev wird gewählt.Vorbereitung zum Entpacken von .../4-python3-dev_3.8.2-0ubuntu2_amd64.deb ...Entpacken von python3-dev (3.8.2-0ubuntu2) ...Vormals nicht ausgewähltes Paket python3-setuptools wird gewählt.Vorbereitung zum Entpacken von .../5-python3-setuptools_45.2.0-1_all.deb ...Entpacken von python3-setuptools (45.2.0-1) ...Vormals nicht ausgewähltes Paket python3-wheel wird gewählt.Vorbereitung zum Entpacken von .../6-python3-wheel_0.34.2-1_all.deb ...Entpacken von python3-wheel (0.34.2-1) ...Vormals nicht ausgewähltes Paket python3-pip wird gewählt.Vorbereitung zum Entpacken von .../7-python3-pip_20.0.2-5ubuntu1.6_all.deb ...Entpacken von python3-pip (20.0.2-5ubuntu1.6) ...python3-setuptools (45.2.0-1) wird eingerichtet ...python3-wheel (0.34.2-1) wird eingerichtet ...libpython3.8-dev:amd64 (3.8.10-0ubuntu1~20.04.4) wird eingerichtet ...python3.8-dev (3.8.10-0ubuntu1~20.04.4) wird eingerichtet ...python-pip-whl (20.0.2-5ubuntu1.6) wird eingerichtet ...libpython3-dev:amd64 (3.8.2-0ubuntu2) wird eingerichtet ...python3-dev (3.8.2-0ubuntu2) wird eingerichtet ...python3-pip (20.0.2-5ubuntu1.6) wird eingerichtet ...Trigger für man-db (2.9.1-1) werden verarbeitet ...donnie@UD5:~$ pip install pyvisa-pyCollecting pyvisa-pyDownloading PyVISA_py-0.5.3-py3-none-any.whl (59 kB)|████████████████████████████████| 59 kB 474 kB/sCollecting typing-extensionsDownloading typing_extensions-4.2.0-py3-none-any.whl (24 kB)Collecting pyvisa>=1.12.0Downloading PyVISA-1.12.0-py3-none-any.whl (175 kB)|████████████████████████████████| 175 kB 759 kB/sInstalling collected packages: typing-extensions, pyvisa, pyvisa-pyWARNING: The scripts pyvisa-info and pyvisa-shell are installed in '/home/donnie/.local/bin' which is not on PATH.Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.Successfully installed pyvisa-1.12.0 pyvisa-py-0.5.3 typing-extensions-4.2.0donnie@UD5:~$ python3Python 3.8.10 (default, Mar 15 2022, 12:22:08)[GCC 9.4.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import pyvisa as visa>>> EEZ = visa.ResourceManager('@py').open_resource('TCPIP::10.2.2.50::5025::SOCKET')>>> print (EEZ.query("*IDN?"))Traceback (most recent call last):File "<stdin>", line 1, in <module>File "/home/donnie/.local/lib/python3.8/site-packages/pyvisa/resources/messagebased.py", line 648, in queryreturn self.read()File "/home/donnie/.local/lib/python3.8/site-packages/pyvisa/resources/messagebased.py", line 486, in readmessage = self._read_raw().decode(enco)File "/home/donnie/.local/lib/python3.8/site-packages/pyvisa/resources/messagebased.py", line 442, in _read_rawchunk, status = self.visalib.read(self.session, size)File "/home/donnie/.local/lib/python3.8/site-packages/pyvisa_py/highlevel.py", line 519, in readreturn data, self.handle_return_value(session, status_code)File "/home/donnie/.local/lib/python3.8/site-packages/pyvisa/highlevel.py", line 251, in handle_return_valueraise errors.VisaIOError(rv)pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.>>> print (EEZ.query("*IDN?"))Traceback (most recent call last):File "<stdin>", line 1, in <module>File "/home/donnie/.local/lib/python3.8/site-packages/pyvisa/resources/messagebased.py", line 648, in queryreturn self.read()File "/home/donnie/.local/lib/python3.8/site-packages/pyvisa/resources/messagebased.py", line 486, in readmessage = self._read_raw().decode(enco)File "/home/donnie/.local/lib/python3.8/site-packages/pyvisa/resources/messagebased.py", line 442, in _read_rawchunk, status = self.visalib.read(self.session, size)File "/home/donnie/.local/lib/python3.8/site-packages/pyvisa_py/highlevel.py", line 519, in readreturn data, self.handle_return_value(session, status_code)File "/home/donnie/.local/lib/python3.8/site-packages/pyvisa/highlevel.py", line 251, in handle_return_valueraise errors.VisaIOError(rv)pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.>>>From the EEZ Studio setup I surmised that I need add the socket port 5025 to the TCP/IP call to address the unit. Doing that, I seem to reach the unit with pyvisa, but the *IDN? command does not seem to get any response.Your intro led me to believe this was a seemingly simple and generic method to talk SCPI, but it no longer appears to me to simple nor generic as I have not been able to get it to work on either Windows or Linux. I guess my expectations were too high.Kind regards,Donnie

author: RoGeorge
author_rank: Super Contributor
timestamp: May 23, 2022, 06:28:09 pm
content: It looks like the instrument can only use SOCKET to connect, and not INSTR.That instrument might not be fully compatible with pyvisa. (I assume you can ping the instrument from Ubuntu, right?) Might be because the instrument is not ready yet for VISA (saying this because I've noticed it only accepts a single connection - my Rigol instruments can have multiple socket connections open at the same time), or it might be some other simple setting that has to be changed, as for example using a different string terminator, or increasing the timeout to give the instrument more time to reply, I don't know.I don't have an EEZ instrument to debug the communication, but the EEZ power supplies happens to have a thread on this forum, open by one of the designers. Userprasimixmight be able to tell what settings are needed for your EEZ instrument, so to make it talk with pyvisa. You may want to ask him for help connecting to the instrument from python/pyvisa here:https://www.eevblog.com/forum/testgear/eez-studio-for-accessing-your-(scpi)-instruments/PS:For the future, please copy/paste console text/debugging messages between the "code" tags, so the text will be contained.

author: iMo
author_rank: Super Contributor
timestamp: September 10, 2023, 05:33:38 pm
content: Hi, out of curiosity I've been trying to talk to the ~15years old Rigol DS-1062CA scope, supporting (according to the DS) VISA on USB.There is none LAN in this rig. My OS Win7 64b. My python here is 3.8.I installed DS1000 driver via zadig (WinUSB), thus I see "DS1000 Series" usb device when connecting the scope and it says driver is ok. I've installed pyvisa-py and it went ok, it seems.Now, I tried to install python3-usb, but there is not such thing for Win7.Instead there is "pyusb" lib - should I install that package?Code:C:\Windows\system32>pythonPython 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license" for more information.>>> import pyvisa as visa>>> rm = visa.ResourceManager('@py')>>> print( rm.list_resources() )C:\Users\me\AppData\Local\Programs\Python\Python38\lib\site-packages\pyvisa_py\tcpip.py:408: UserWarning: TCPIP:instr resource discovery is limited to the default interface.Install psutil: pip install psutil if you want to scan all interfaces.OK, I've installed the pyusb and tried the demo:Code:import usb.coreimport usb.util# find our devicedev = usb.core.find(idVendor=0x1A1B, idProduct=0x0588)# was it found?if dev is None:raise ValueError('Device RIGOL not found')# set the active configuration. With no arguments, the first# configuration will be the active onedev.set_configuration()# get an endpoint instancecfg = dev.get_active_configuration()intf = cfg[(0,0)]ep = usb.util.find_descriptor(intf,# match the first OUT endpointcustom_match = \lambda e: \usb.util.endpoint_direction(e.bEndpointAddress) == \usb.util.ENDPOINT_OUT)assert ep is not None# write the dataep.write('*IDN?')Code:C:\Users\me\Desktop\Rigol Python>py test1.pyTraceback (most recent call last):File "test1.py", line 9, in <module>raise ValueError('Device RIGOL not found')ValueError: Device RIGOL not found

author: iMo
author_rank: Super Contributor
timestamp: September 10, 2023, 07:16:30 pm
content: I've reinstalled the WinUSB driver to libusb one (latest zadig) and pyusb sees it now..Code:import usb.coreimport usb.utilfor dev in usb.core.find(find_all=True):print(dev)Code:C:\Users\me\Desktop\Rigol Python>py test2.pyDEVICE ID 1ab1:0588 on Bus 000 Address 001 =================bLength : 0x12 (18 bytes)bDescriptorType : 0x1 DevicebcdUSB : 0x110 USB 1.1bDeviceClass : 0x0 Specified at interfacebDeviceSubClass : 0x0bDeviceProtocol : 0x0bMaxPacketSize0 : 0x40 (64 bytes)idVendor : 0x1ab1idProduct : 0x0588bcdDevice : 0x100 Device 1.0iManufacturer : 0x1 Rigol TechnologiesiProduct : 0x2 DS1000 SERIESiSerialNumber : 0x3 XXXXXXXXXXXXXXXXXxbNumConfigurations : 0x1CONFIGURATION 1: 2 mA ====================================bLength : 0x9 (9 bytes)bDescriptorType : 0x2 ConfigurationwTotalLength : 0x27 (39 bytes)bNumInterfaces : 0x1bConfigurationValue : 0x1iConfiguration : 0x0bmAttributes : 0xc0 Self PoweredbMaxPower : 0x1 (2 mA)INTERFACE 0: Application Specific ======================bLength : 0x9 (9 bytes)bDescriptorType : 0x4 InterfacebInterfaceNumber : 0x0bAlternateSetting : 0x0bNumEndpoints : 0x3bInterfaceClass : 0xfe Application SpecificbInterfaceSubClass : 0x3bInterfaceProtocol : 0x1iInterface : 0x0ENDPOINT 0x1: Bulk OUT ===============================bLength : 0x7 (7 bytes)bDescriptorType : 0x5 EndpointbEndpointAddress : 0x1 OUTbmAttributes : 0x2 BulkwMaxPacketSize : 0x40 (64 bytes)bInterval : 0x0ENDPOINT 0x82: Bulk IN ===============================bLength : 0x7 (7 bytes)bDescriptorType : 0x5 EndpointbEndpointAddress : 0x82 INbmAttributes : 0x2 BulkwMaxPacketSize : 0x40 (64 bytes)bInterval : 0x0ENDPOINT 0x83: Interrupt IN ==========================bLength : 0x7 (7 bytes)bDescriptorType : 0x5 EndpointbEndpointAddress : 0x83 INbmAttributes : 0x3 InterruptwMaxPacketSize : 0x8 (8 bytes)bInterval : 0x1

author: RoGeorge
author_rank: Super Contributor
timestamp: September 10, 2023, 07:38:47 pm
content: I don't use neither Windows nor USB connection, can not reproduce that error, or advice how to fix it, sorry.Might be easier to install Ubuntu (or other Linux) inside a VirtualBox (or alike VM player), then try again from Linux. You'll need to pass the USB from the host (Windows) machine to the guest (Linux) machine after the Linux machine is started (with right click on the VM USB small icon in the bar of the VM).I remember somebody was complaining about DS1054Z having some bugs in the USB packets. Maybe your DS-1062 doesn't.If all fails, on Windows you can install NI-VISA (it's free to download and install), then configure 'pyvisa' to use standard 'VISA' library (from NI) instead of 'pyvisa-py' ('pyvisa-py is only mocking a VISA library, it is not as complete as the real thing).

author: zapta
author_rank: Super Contributor
timestamp: September 10, 2023, 11:28:37 pm
content: > Felt chatty today. These are some sort of personal learning notes.Just a side note, you may want to take a look at Jupyter Notebooks. It's a great tool for exploring and publishing python snippets like these ones.https://jupyter.org/

author: moffy
author_rank: Super Contributor
timestamp: September 10, 2023, 11:43:31 pm
content: If anyone is looking for some C/C++ code I ran across this snippet at:https://www.codeproject.com/Articles/869421/Interfacing-Rigol-Oscilloscopes-with-CCode:#include "VISA\WinNT\Include\visa.h"#define NUM_CMDS 10#define CMD_SIZE 64static ViSession rmSession, scopeSession;static ViFindList resourceList;static ViUInt32 numResources;static ViStatus status;static char usbResource;// Execute each command in a listvoid run_commands(char commands){int i;for (i = 0; i < NUM_CMDS; i++){status = viWrite(scopeSession, (ViBuf)commands, 512, VI_NULL);if (status != VI_SUCCESS){printf("Error executing %s\n", commands);exit(-1);}}}void CRigolDlg::OnBnClickedScopemem(){// The list of commandsstatic char cmds ={ ":CHAN1:RANG 4\n",":CHAN1:BWL 20M\n",":TIM:MAIN:SCAL 0.001\n",":WAV:MODE RAW\n",":WAV:SOUR CHAN1\n",":WAV:STAR 1\n",":WAV:STOP 800000\n",":SING\n",":RUN\n",":TFOR\n" };// Open session with the resource managerviOpenDefaultRM(&rmSession);// Find USB resourcesviFindRsrc(rmSession, "USB?*INSTR", &resourceList, &numResources, usbResource);// Open session to the resourceviOpen(rmSession, usbResource, VI_NULL, VI_NULL, &scopeSession);// Configure the device and start measurementrun_commands(cmds);// Wait for the scope's measurementSleep(1000);// Read the responseviWrite(scopeSession, (ViBuf)":STOP\n", 512, VI_NULL);viWrite(scopeSession, (ViBuf)":WAV:DATA?\n", 512, VI_NULL);viReadToFile(scopeSession, "wave.dat", 800000, VI_NULL);// Close the session to the resourceviClose(scopeSession);viClose(rmSession);}I managed to add it to a Visual Studio 2022 project and get it to compile successfully, but as yet untested.To quote from the article:"On their website, Rigol Technologies provides a driver package for each of their oscilloscopes. If you install it ona Windows computer, the C:\Program Files (x86) directory will hold a directory called IVI Foundation. Thiscontains the libraries and header files needed to build the applications described in this article.A particularly important file is visa32.lib, which is located in IVI Foundation\VISA\WinNT\lib\msc. The functionsin this library make it possible to interface compliant test instruments. These functions are declared in visa.h,which is located in IVI Foundation\VISA\WinNT\include."You need to have an #include "... visa.h" statement as well as adding the "visa32.lib" library to the linker and everything should compile successfully.

author: iMo
author_rank: Super Contributor
timestamp: September 11, 2023, 06:50:11 am
content: After installing NI 's Ultrascope with driver from batronix' site I can connect and partially operate the scope, but half of things does not work. I can see the IVI directory with the visa.h in it as moffy indicated, however.I'll try under Ubu with RoGeorge's, we will see what happens..

author: iMo
author_rank: Super Contributor
timestamp: September 11, 2023, 07:37:55 am
content: Ok, now in my oldie Ubu 18.04 (in Vbox 6.1.22 under Win7) with python3.7.5 (I have several python versions installed from past, a big mess)..Code:>>> print( ds1054z.query('*IDN?') )Rigol Technologies,DS1062CA,XXXXXXXXXXXXXX,04.01.00>>> print( ds1054z.query(':MEASure:VPP?') )4.480000e-02>>> print( ds1054z.query(':MEASure:VPP?') )4.600000e-02>>> print( ds1054z.query(':MEASure:VPP?') )4.960000e-02>>> print( ds1054z.query(':MEASure:VPP?') )4.520000e-02Good guide!

author: RoGeorge
author_rank: Super Contributor
timestamp: September 11, 2023, 07:41:12 am
content: Congrats!

author: iMo
author_rank: Super Contributor
timestamp: September 11, 2023, 08:41:35 pm
content: It is running in my Win7, it seems.All you have to do is:1. install the "NI-VISA Run-Time Engine 17.0" I've downloaded in my case from Batronix site for my DS1062CA, for example2. you will see 2 new items installed - "VISA Shared Components" and "VISA.NET Shared Components", it installs the USB driver as well3. after you plug in Rigol into the USB you will get "USB Test and Measurement Device (IVI)" in the Device Manager4. and the test python will be for example (a red "Rmt" appears in the right top corner of the Rigol's display and the scope's keys get locked):Code:C:\Windows\system32>pythonPython 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license" for more information.>>> import pyvisa as visa>>> import sys>>>>>> rm = visa.ResourceManager()>>>>>> instruments = rm.list_resources()>>>>>> usb = list(filter(lambda x: 'USB' in x, instruments))>>>>>> if len(usb) != 1:... print('Bad instrument list', instruments)... sys.exit(-1)...>>> scope = rm.open_resource(usb, timeout=20, chunk_size=1024)>>>>>> print(scope.query('*IDN?'))Rigol Technologies,DS1062CA,DSXXXXXXXXXXXX,04.01.00>>>>>> print(scope.query(':MEASure:VPP?') )5.400000e-03>>>

author: RoGeorge
author_rank: Super Contributor
timestamp: September 12, 2023, 07:08:08 am
content: Well done! In Windows the genuine VISA dll files might be preferable, they have some features that were not ported to the pure python implementation (the VISA standard itself includes some specific C features, an interpreter like Python won't be able to mock those requirements, though those are not essential for SCPI control).I've read Agilent and Tektronix have their own VISA libs, never went into details about the Windows version of VISA, don't know which provider would be preferable. National Instrument (NI) is considered the "official" provider of VISA for Windows, though some years ago the installer was adding a lot of other components aside from the VISA libs, such that the install was GB size instead of kB.No idea how it is now. I've heard the nowadays LabVIEW (which includes the VISA libs and the graphic programming language LabVIEW) is now free for home use. Labview can be very productive (e.g. one can do an oscilloscope on the PC side in minutes - adding a screen/plot a knob or some indicators is as easy as any drag and a drop, and those components can communicate with real hardware).Free LabVIEW might worth a try to make your own SCPI tools if you use mostly Windows in the LAB. LabVIEW used to have a mode where one can turn a VI (Virtual Instrument, .vi is the extension of a LabVIEW drawing, or "code" file) into a standalone executable that can run without the need of installing LabVIEW. The funny thing is such a standalone distributable VI (a Windows exe) can run in Linux, too, with WineHQ.For example this soundcard signal generator/oscilloscope/spectrum analyzer:https://www.zeitnitz.eu/scope_enwas built with LabVIEW as a standalone installer (for Windows) but with WineHQ it also work in Linux.WineHQ only translates Windows OS system call into Linux OS calls, it does not create a virtual machine and does not need a windows license. While many Windows programs and games will run just fine in Linux, or Mac, or FreeBSD with the help of WineHQ (e.g. LTspice, or Starcraft) some might not.

author: moffy
author_rank: Super Contributor
timestamp: September 12, 2023, 07:58:09 am
content: Thanks RoGeorge for all the info, I'll have to check out the LabView for home use.

author: vampir
author_rank: Newbie
timestamp: July 18, 2025, 08:53:34 am
content: Hello everyone,since I cannot send personal messages, I am replying to this thread.I am owning an Rigol DS1062CA and would like to communicate with it preferred via USB, or via RS232.Since it has still an old Firmeware <03.08.xx it is not responding to the communication requests.Is there an possibility th get a newer firmeware, where the communication is working?@iMo:I cannot find the firmeware Version V04.xx.xx for the rigol DS1062ca scope.Where did you got this / can you provide it to me?Best regardsvampir

author: mk_
author_rank: Regular Contributor
timestamp: July 18, 2025, 09:47:45 am
content: start a new thread....