Author Topic: Python-based instrument control  (Read 44981 times)

0 Members and 1 Guest are viewing this topic.

Offline chaugen1

  • Newbie
  • Posts: 2
  • Country: us
Re: Python-based instrument control
« Reply #50 on: April 18, 2016, 02:39:38 pm »
Sorry to wake up an old thread.  Can start a new one if necessary.

I would love to contribute to this project.  I am working on a driver for the Agilent U2701A USB Modular Oscilloscope and would be happy to share once I have it done and tested.

In the meantime, I need some help.  I have usbtmc installed and it can see the instrument but when I try to ask it for anything, PyUSB throws up a "Error 32: Pipe Error"

Here is output:  first the device as seen from PyUSB:

Code: [Select]
DEVICE ID 0957:2818 on Bus 002 Address 005 =================
 bLength                :   0x12 (18 bytes)
 bDescriptorType        :    0x1 Device
 bcdUSB                 :  0x200 USB 2.0
 bDeviceClass           :    0x0 Specified at interface
 bDeviceSubClass        :    0x0
 bDeviceProtocol        :    0x0
 bMaxPacketSize0        :   0x40 (64 bytes)
 idVendor               : 0x0957
 idProduct              : 0x2818
 bcdDevice              :  0x100 Device 1.0
 iManufacturer          :    0x1 Agilent Technologies
 iProduct               :    0x2 Agilent U2701A/U2702A
 iSerialNumber          :    0x3 MY********
 bNumConfigurations     :    0x1
  CONFIGURATION 1: 100 mA ==================================
   bLength              :    0x9 (9 bytes)
   bDescriptorType      :    0x2 Configuration
   wTotalLength         :   0x61 (97 bytes)
   bNumInterfaces       :    0x1
   bConfigurationValue  :    0x1
   iConfiguration       :    0x0
   bmAttributes         :   0xc0 Self Powered
   bMaxPower            :   0x32 (100 mA)
    INTERFACE 0: Reserved ==================================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x0
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x4
     bInterfaceClass    :    0x0 Reserved
     bInterfaceSubClass :    0x0
     bInterfaceProtocol :    0x0
     iInterface         :    0x0
      ENDPOINT 0x81: Interrupt IN ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x81 IN
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x1
      ENDPOINT 0x1: Interrupt OUT ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x1 OUT
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x1
      ENDPOINT 0x82: Bulk IN ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x82 IN
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0
      ENDPOINT 0x2: Bulk OUT ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x2 OUT
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0
    INTERFACE 0, 1: Reserved ===============================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x0
     bAlternateSetting  :    0x1
     bNumEndpoints      :    0x6
     bInterfaceClass    :    0x0 Reserved
     bInterfaceSubClass :    0x0
     bInterfaceProtocol :    0x0
     iInterface         :    0x0
      ENDPOINT 0x81: Interrupt IN ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x81 IN
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x1
      ENDPOINT 0x1: Interrupt OUT ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x1 OUT
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x1
      ENDPOINT 0x82: Bulk IN ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x82 IN
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0
      ENDPOINT 0x2: Bulk OUT ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x2 OUT
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0
      ENDPOINT 0x83: Isochronous IN ========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x83 IN
       bmAttributes     :    0x1 Isochronous
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x1
      ENDPOINT 0x3: Isochronous OUT ========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x3 OUT
       bmAttributes     :    0x1 Isochronous
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x1

And here is what I get when I try to probe it:

Code: [Select]
>>> import usbtmc
>>> instr = usbtmc.Instrument(0x0957,0x2818)
>>> print(instr.ask("*IDN?"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.linux-x86_64/egg/usbtmc/usbtmc.py", line 607, in ask
  File "build/bdist.linux-x86_64/egg/usbtmc/usbtmc.py", line 587, in write
  File "build/bdist.linux-x86_64/egg/usbtmc/usbtmc.py", line 467, in write_raw
  File "build/bdist.linux-x86_64/egg/usbtmc/usbtmc.py", line 341, in open
  File "build/bdist.linux-x86_64/egg/usbtmc/usbtmc.py", line 677, in clear
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 1043, in ctrl_transfer
    self.__get_timeout(timeout))
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 883, in ctrl_transfer
    timeout))
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 595, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 32] Pipe error
>>>


Anyone have any thoughts on this?
Thanks so much.
 

Offline douardda

  • Regular Contributor
  • *
  • Posts: 82
  • Country: fr
Re: Python-based instrument control
« Reply #51 on: April 18, 2016, 05:48:11 pm »
For realtime plots I think the new plotting library being developed mainly by the continuum.io folks ... http://bokeh.pydata.org

Bokeh has client server architecture and realtime plotting appears to be on the agenda for improvements. This should I hope (I've not used it yet) allow the GUI of the plot operate independently of the data acquisition.
People looking for plotting libraries for python might be  interested in  pyqtgraph also http://www.pyqtgraph.org/ i haven't really used it  for now but it looks very  powerful

David


Envoyé de mon GT-N7105 en utilisant Tapatalk

 

Offline bson

  • Supporter
  • ****
  • Posts: 2265
  • Country: us
Re: Python-based instrument control
« Reply #52 on: April 18, 2016, 09:14:16 pm »
Anyone have any thoughts on this?

The datasheet says USBTMC (GPIB tunneled over USB) but googling seems to suggest Agilent actually uses an FTDI serial port.  If so you may need to add a device rule for that vid,pid to configure a serial port (canonically named /dev/ttyUSB<n>).  If that works, use the serial port to talk to it, issuing the same SCPI commands or whatever it accepts.  The drawback with this scheme is the device can't issue SRQs or otherwise asynchronously request the host's attention.
« Last Edit: April 18, 2016, 09:15:55 pm by bson »
 

Offline chaugen1

  • Newbie
  • Posts: 2
  • Country: us
Re: Python-based instrument control
« Reply #53 on: April 18, 2016, 11:58:51 pm »
Thanks for the feedback.  I took a look and there is in fact no new device that shows up when I plug in the o-scope and check ls /dev.  Out of curiosity, I took it apart and the USB controller is actually NXP ISP1583BS.

Do any of you know if this controller is USBTMC compatible/capable?
 

Offline bson

  • Supporter
  • ****
  • Posts: 2265
  • Country: us
Re: Python-based instrument control
« Reply #54 on: April 19, 2016, 01:25:16 am »
Perhaps you need a rule for it to create /dev/usbtmc for that vid,pid and a usbtmc driver?  Not sure what the python code does and if it expects a driver.

Did you follow the instructions for configuring udev? https://github.com/python-ivi/python-usbtmc

What if you do "lsusb -t" to view the device tree, do you see the driver for it?  Is the kernel usbtmc driver loaded (lsmod)?  If not, try loading it after adding the device udev rules.  Or try unloading it if it is.
« Last Edit: April 19, 2016, 01:31:27 am by bson »
 

Offline KSP

  • Regular Contributor
  • *
  • Posts: 98
  • Country: gb
Re: Python-based instrument control
« Reply #55 on: October 03, 2016, 12:00:14 pm »
Sorry to revive this thread once more, and sorry again if this is a repeat question as I have not trawled through all three pages of this thread  :-[ But does python-ivi require you to write ivi drivers for all devices used, or is it possible for an existing ivi-c or ivi-com driver to be used?

I've had a little success with ivi-com drivers using the 'comtypes' module, but it is in no way seamless
 

Offline alex.forencichTopic starter

  • Frequent Contributor
  • **
  • Posts: 397
  • Country: us
    • Alex Forencich
Re: Python-based instrument control
« Reply #56 on: February 15, 2017, 05:26:13 am »
Sorry to wake up an old thread.  Can start a new one if necessary.

I would love to contribute to this project.  I am working on a driver for the Agilent U2701A USB Modular Oscilloscope and would be happy to share once I have it done and tested.

In the meantime, I need some help.  I have usbtmc installed and it can see the instrument but when I try to ask it for anything, PyUSB throws up a "Error 32: Pipe Error"

Here is output:  first the device as seen from PyUSB:

Code: [Select]
DEVICE ID 0957:2818 on Bus 002 Address 005 =================
 bLength                :   0x12 (18 bytes)
 bDescriptorType        :    0x1 Device
 bcdUSB                 :  0x200 USB 2.0
 bDeviceClass           :    0x0 Specified at interface
 bDeviceSubClass        :    0x0
 bDeviceProtocol        :    0x0
 bMaxPacketSize0        :   0x40 (64 bytes)
 idVendor               : 0x0957
 idProduct              : 0x2818
 bcdDevice              :  0x100 Device 1.0
 iManufacturer          :    0x1 Agilent Technologies
 iProduct               :    0x2 Agilent U2701A/U2702A
 iSerialNumber          :    0x3 MY********
 bNumConfigurations     :    0x1
  CONFIGURATION 1: 100 mA ==================================
   bLength              :    0x9 (9 bytes)
   bDescriptorType      :    0x2 Configuration
   wTotalLength         :   0x61 (97 bytes)
   bNumInterfaces       :    0x1
   bConfigurationValue  :    0x1
   iConfiguration       :    0x0
   bmAttributes         :   0xc0 Self Powered
   bMaxPower            :   0x32 (100 mA)
    INTERFACE 0: Reserved ==================================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x0
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x4
     bInterfaceClass    :    0x0 Reserved
     bInterfaceSubClass :    0x0
     bInterfaceProtocol :    0x0
     iInterface         :    0x0
      ENDPOINT 0x81: Interrupt IN ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x81 IN
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x1
      ENDPOINT 0x1: Interrupt OUT ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x1 OUT
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x1
      ENDPOINT 0x82: Bulk IN ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x82 IN
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0
      ENDPOINT 0x2: Bulk OUT ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x2 OUT
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0
    INTERFACE 0, 1: Reserved ===============================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x0
     bAlternateSetting  :    0x1
     bNumEndpoints      :    0x6
     bInterfaceClass    :    0x0 Reserved
     bInterfaceSubClass :    0x0
     bInterfaceProtocol :    0x0
     iInterface         :    0x0
      ENDPOINT 0x81: Interrupt IN ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x81 IN
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x1
      ENDPOINT 0x1: Interrupt OUT ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x1 OUT
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x1
      ENDPOINT 0x82: Bulk IN ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x82 IN
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0
      ENDPOINT 0x2: Bulk OUT ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x2 OUT
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0
      ENDPOINT 0x83: Isochronous IN ========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x83 IN
       bmAttributes     :    0x1 Isochronous
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x1
      ENDPOINT 0x3: Isochronous OUT ========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x3 OUT
       bmAttributes     :    0x1 Isochronous
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x1

And here is what I get when I try to probe it:

Code: [Select]
>>> import usbtmc
>>> instr = usbtmc.Instrument(0x0957,0x2818)
>>> print(instr.ask("*IDN?"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.linux-x86_64/egg/usbtmc/usbtmc.py", line 607, in ask
  File "build/bdist.linux-x86_64/egg/usbtmc/usbtmc.py", line 587, in write
  File "build/bdist.linux-x86_64/egg/usbtmc/usbtmc.py", line 467, in write_raw
  File "build/bdist.linux-x86_64/egg/usbtmc/usbtmc.py", line 341, in open
  File "build/bdist.linux-x86_64/egg/usbtmc/usbtmc.py", line 677, in clear
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 1043, in ctrl_transfer
    self.__get_timeout(timeout))
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 883, in ctrl_transfer
    timeout))
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 595, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 32] Pipe error
>>>


Anyone have any thoughts on this?
Thanks so much.

The U2701A should be USBTMC capable.  However, it needs to be initialized first.  If it comes up with idProduct 0x2818, it's in some sort of firmware update mode.  The Agilent drivers then check the firmware version, possibly update it, then send a command to reset into the actual firmware.  In this case, idProduct will be 0x2918 and it will operate as a USBTMC device.  This needs to be emulated when the Agilent drivers are not present.  At least, this is extrapolating from the U2723A that I have; I figure all of the Agilent instruments of that style all operate the same way. 

Support for the U2701A/U2702A is currently in the works, see: https://github.com/python-ivi/python-usbtmc/issues/31 .  I'm waiting on a wireshark trace with the boot sequence. 
Python-based instrument control: Python IVI, Python VXI-11, Python USBTMC
 

Offline LEDPaul

  • Newbie
  • Posts: 4
  • Country: no
Re: Python-based instrument control
« Reply #57 on: April 05, 2018, 02:02:04 pm »
Just started to learn about Python-IVI. So far I wrote my own stuff, but to redo everything for each new machine is not really efficient. So probably better to use Python-IVI. Next machine I will add is probably the Agilent/Keysight 34465A DMM. It has some functions that  the older models do not have, or I have not found it yet, or the support was not written yet. So I need to learn to expand it. I have some other machines that I probably can convert, but that will be later.

Is this the place to best ask questions on Pyhthon-IVI or do that better on github?

Also if anyone has some more complex examples on hot to use a dmm in python-ivi I would love to see that.
 

Offline alm

  • Super Contributor
  • ***
  • Posts: 2840
  • Country: 00
Re: Python-based instrument control
« Reply #58 on: April 08, 2018, 10:09:16 am »
I attached a script that I used to collect measurements from a DMM through Python-IVI at different integration times, so I could determine the noise (is it better to average 100 measurements with 1 s integration time, or 10 measurements with 10 s integration time?). This is the general pattern I have been using: in init_func() I set up whatever instruments I want to use and set their range, function, etc, and in loop_func() I collect the measurements. If I need to do something else, I only have to modify these two functions.
 
The following users thanked this post: LEDPaul

Offline LEDPaul

  • Newbie
  • Posts: 4
  • Country: no
Re: Python-based instrument control
« Reply #59 on: April 23, 2018, 03:18:40 pm »
I mannaged to get my 34465A working with python-ivi. I can measure the current at 200us interval and read 1000 or even 50k samples. To be able to do this I added some functions to python-IVI locally. Below the user code to read the current:

Code: [Select]
dmm = ivi.agilent.agilent34465A("USB0::0x2A8D::0x0101::MYxxxxxxxx::0::INSTR")
dmm.configure('dc_current', 10e-3, 1e-9)
dmm.advanced.auto_zero = 'once'
dmm.advanced.aperture_time = 200e-6
dmm.trigger.delay = 0.0
dmm.trigger.source = 'bus'
dmm.trigger.multi_point.configure(trigger_count=1,
                                  sample_count=1000,
                                  sample_trigger='TIM',
                                  sample_interval=200e-6)
dmm.measurement.initiate()
dmm.send_software_trigger()
sleep(1000 * 200e-6)
res = dmm.measurement.fetch_multi_point(1000 * 200e-6, 1000)

code for the 34465A can be found here: https://github.com/phsdv/python-ivi
« Last Edit: April 25, 2018, 12:20:04 pm by LEDPaul »
 
The following users thanked this post: nugglix, alm

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 6145
  • Country: ro
Re: Python-based instrument control
« Reply #60 on: January 02, 2021, 06:46:08 pm »
Just installed python-ivi and python-vxi11 these days from https://github.com/python-ivi/python-ivi
and it works great, thank you!   :D

Also, found yesterday another repository https://github.com/alexforencich/python-ivi/
And yet another branch with a pull request for Rigol oscilloscope drivers (I am not very good with git/github):
https://github.com/ianrrees/python-ivi/

I am looking for python-ivi drivers for Rigol DS1104Z (DS1000Z) oscilloscope and Rigol DG4202 (DG4000) generator.

Not sure if there are any working python-ivi drivers for the above Rigol osc and generator, or which one to use.  I have other questions, too, mainly regarding finding the latest python-ivi drivers, summarized in a separate topic:
https://www.eevblog.com/forum/metrology/software-for-automated-testing-(scpi)/msg3397446/#msg3397446

Any hints, please?
« Last Edit: January 02, 2021, 06:48:00 pm by RoGeorge »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf