Author Topic: Controlling Rigol DP832A PSU with python  (Read 6530 times)

0 Members and 2 Guests are viewing this topic.

Offline kimmokTopic starter

  • Newbie
  • Posts: 5
  • Country: fi
Controlling Rigol DP832A PSU with python
« on: September 01, 2017, 12:09:55 pm »
Trying to build python control for Rigol DP832A PSU with x86 tablet running windows10.

(done before:
-got it working with Win7+NI-VISA+C#
-got it working on x86 tablet with Win10 +NI-VISA+pyvisa+python2)

Now my goal is to get it working by using opensource tools on Win10.

So far:
-clean Win10 installation
-installed python2-7.x
-cmd/ python -m pip install -U pip
-cmd/ pip install pyusb
-cmd/ pip install pyvisa
-cmd/ pip install pyvisa-py

Then python nagged about no backend... (python -m visa info)
so,I:
-installed usblib for DB800 via zadig GUI



I should now have all things in place.

did in python console:
>>> import visa
>>> resources = visa.ResourceManager('@py')
>>> print(resources.list_resources())
(u'USB0::6833::3601::DP8B185350299::0::INSTR',)

So far all works as expected, Rigol is seen on the USB connection.

But this fails:
>>> rigolpsu = resources.open_resource('USB0::6833::3601::DP8B185350299::0::INSTR')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\pyvisa\highlevel.py", line 1644, in open_resource
    res.open(access_mode, open_timeout)
  File "C:\Python27\lib\site-packages\pyvisa\resources\resource.py", line 203, in open
    self.session, status = self._resource_manager.open_bare_resource(self._resource_name, access_mode, open_timeout)
  File "C:\Python27\lib\site-packages\pyvisa\highlevel.py", line 1601, in open_bare_resource
    return self.visalib.open(self.session, resource_name, access_mode, open_timeout)
  File "C:\Python27\lib\site-packages\pyvisa-py\highlevel.py", line 191, in open
    sess = cls(session, resource_name, parsed)
  File "C:\Python27\lib\site-packages\pyvisa-py\sessions.py", line 184, in __init__
    self.after_parsing()
  File "C:\Python27\lib\site-packages\pyvisa-py\usb.py", line 176, in after_parsing
    self.parsed.serial_number)
  File "C:\Python27\lib\site-packages\pyvisa-py\protocols\usbtmc.py", line 236, in __init__
    self.usb_dev.set_configuration()
  File "C:\Python27\lib\site-packages\usb\core.py", line 869, in set_configuration
    self._ctx.managed_set_configuration(self, configuration)
  File "C:\Python27\lib\site-packages\usb\core.py", line 102, in wrapper
    return f(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\usb\core.py", line 148, in managed_set_configuration
    self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
  File "C:\Python27\lib\site-packages\usb\backend\libusb0.py", line 493, in set_configuration
    _check(_lib.usb_set_configuration(dev_handle, config_value))
  File "C:\Python27\lib\site-packages\usb\backend\libusb0.py", line 431, in _check
    raise USBError(errmsg, ret)
usb.core.USBError: [Errno None] libusb0-dll:err [set_configuration] could not set config 1: win error: The parameter is incorrect.



((my third day using python, so, sorry if it's something obvious...)) :-[
 

Offline Dalun

  • Newbie
  • !
  • Posts: 1
  • Country: gb
Re: Controlling Rigol DP832A PSU with python
« Reply #1 on: September 01, 2017, 06:13:22 pm »
Your >>> print(resources.list_resources())
                                                                                 (u'USB0::6833::3601::DP8B185350299::0::INSTR',)
Your >>> rigolpsu = resources.open_resource('USB0::6833::3601::DP8B185350299::0::INSTR')
The 'u' before the string in open_resource('USB... is missing
Try
        >>> rigolpsu = resources.open_resource(u'USB0::6833::3601::DP8B185350299::0::INSTR')

 
This is one of the string handling things of Python 2, it's to do with strings and bytes being the same in Python 2  and thankfully separate types in Python 3. see https://docs.python.org/3/howto/pyporting.html#text-versus-binary-data

Have you considered trying Python 3 as "Short version: Python 2.x is legacy, Python 3.x is the present and future of the language ": https://wiki.python.org/moin/Python2orPython3

PyVISA & PyVISA-Py work well in Python 3
 
The following users thanked this post: kimmok

Offline kimmokTopic starter

  • Newbie
  • Posts: 5
  • Country: fi
Re: Controlling Rigol DP832A PSU with python
« Reply #2 on: September 04, 2017, 07:25:11 am »
With u'USB0::6833::3601::DP8B185350299::0::INSTR'

->
'int' object has no attribute 'interface_type'

+I'll set another setup to try with python3, etc...
 

Offline bd139

  • Super Contributor
  • ***
  • Posts: 23018
  • Country: gb
Re: Controlling Rigol DP832A PSU with python
« Reply #3 on: September 04, 2017, 09:56:54 am »
The first thing I've learned playing with my DG1022Z/DG1054Z is to do this via ethernet / TCP and use SCPI. You can cut and paste a simple line based TCP client and talk to it like that. Much easier than even getting VISA working with USB. I crapped an hour trying to get it to talk to my DG1022Z. The protocol is easier to debug as you can drive it with telnet as well and do any exploration.
 
The following users thanked this post: kimmok

Online RoGeorge

  • Super Contributor
  • ***
  • Posts: 6147
  • Country: ro
Re: Controlling Rigol DP832A PSU with python
« Reply #4 on: September 04, 2017, 10:15:33 am »
Maybe this will help (no VISA or Rigol drivers required):
https://hackaday.io/project/6857-master-your-rigol-from-command-line

And some example in Python (continuously logging the values measured by DP832):
https://github.com/RoGeorge/DP832_charger_logger
 
The following users thanked this post: kimmok

Offline kimmokTopic starter

  • Newbie
  • Posts: 5
  • Country: fi
Re: Controlling Rigol DP832A PSU with python
« Reply #5 on: September 04, 2017, 01:39:40 pm »
Thank you so far.
I got same errors with python3.

Next.
I try to do control over LAN.

Meanwhile:

Would you guys recommend DP832A (and other rigol products) for high reliability needing robustness testing?

I've found Monsoon Inc PowerMonitor pretty good for the price.
(done hunderds of thousands test cycles with it & very little problems)
But it would be nice to get wider voltage range as I need to test 4V, 12V and 24V products.
 

Online RoGeorge

  • Super Contributor
  • ***
  • Posts: 6147
  • Country: ro
Re: Controlling Rigol DP832A PSU with python
« Reply #6 on: September 04, 2017, 02:11:53 pm »
Would you guys recommend DP832A (and other rigol products) for high reliability needing robustness testing?

I've found Monsoon Inc PowerMonitor pretty good for the price.

No, I do not recommend Rigol for high reliability. I know nothing about Inc PowerMonitor, so I can not tell if PowerMonitor is better or worst than Rigol.

All I can tell is that Rigol is not famous for being reliable. They are famous for being cheap and hack-able (you can illegally unlock software options for free), but in my experience Rigol was not reliable, especially for automated testing. In my experience it happened that my DP832 had restarted once while I was logging the data, and the closed control loop that I put for fun in another project (https://rogeorge.wordpress.com/2016/09/23/zero-parts-thermostated-soldering-station/) in order to control the temperature of a soldering iron with a Rigol DP832 power source and a DS1054Z oscilloscope sometimes hanged. So, definitely not reliable. Also, Rigol firmware was buggy for years, and it still is, especially for SCPI control.

Offline bd139

  • Super Contributor
  • ***
  • Posts: 23018
  • Country: gb
Re: Controlling Rigol DP832A PSU with python
« Reply #7 on: September 04, 2017, 02:16:05 pm »
Agreed.

I only use it because it's cheap and adequate for my needs. I'd probably hit Keysight if I wanted anything reliable and not necessarily new product lines.
 

Offline kimmokTopic starter

  • Newbie
  • Posts: 5
  • Country: fi
Re: Controlling Rigol DP832A PSU with python
« Reply #8 on: September 05, 2017, 06:30:49 am »
Thanks again.

We are anyway getting "high voltage powermonitor" to see if it's as good as their previous (<5V) model.
HVolt model can cover our needs up to 15V.

Monsoon Inc has some(~ok) support and in cases when powermonitor "hangs", we have SW means to automatically recover it and continue. It uses USB control interface and it's driver robustness seem to depend on control PC's windows, .NET and setup. (and yes USB in general is crappy/joke as a "standard" etc)
(Also Powermonitor needs extra effort to be usable from python and non-windows control PCs.... am I dreaming of RPis running a farm of test setups...? )

With Rigol, our evaluation time-frame has now passed and I think we will not get these until there is more pressing need to measure 24V devices.
 

Offline bd139

  • Super Contributor
  • ***
  • Posts: 23018
  • Country: gb
Re: Controlling Rigol DP832A PSU with python
« Reply #9 on: September 05, 2017, 07:23:21 am »
I wouldn't consider a Raspberry Pi to be reliable either.

HP enterprise kit is. That means Z/Elite series workstations/desktops.
 
The following users thanked this post: kimmok

Offline kimmokTopic starter

  • Newbie
  • Posts: 5
  • Country: fi
Re: Controlling Rigol DP832A PSU with python
« Reply #10 on: September 05, 2017, 07:36:29 am »
For some reason pyvisa-py is not able to find RIGOL from LAN interface "automagically".

But this works...
Quote
import visa
rm = visa.ResourceManager("@py")
inst = rm.open_resource("TCPIP::192.168.1.5")

inst.query('*IDN?')
-> RIGOL ...

inst.query(':MEAS:CURRent? CH1')
->0.0000

inst.close()


Using pyvisa-py & python2.
 

Offline _joost_

  • Contributor
  • Posts: 16
  • Country: us
Re: Controlling Rigol DP832A PSU with python
« Reply #11 on: March 08, 2018, 03:43:00 pm »
Code: [Select]
inst = rm.open_resource("TCPIP::192.168.1.5")
Thats not very automagic either; you provide a hard coded address. Instead, you can use multicast discovery as implemented in the zeroconf python package. Have a look at this repo for some ideas how that is done:https://github.com/pklaus/ds1054z
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf