User avatar
scruss
Posts: 5611
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON

USB Test & Measurement class (usbtmc) driver?

Wed Nov 13, 2013 1:59 pm

Any chance that the usbtmc module could be added to the distro? It's useful for talking to lab instruments. Even my cheapo Rigol oscilloscope talks it.

Some background: It's been so long since I compiled a kernel module, I think I've forgotten how …

cheers,
Stewart
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

Alport
Posts: 3
Joined: Sat Aug 25, 2012 6:48 am

Re: USB Test & Measurement class (usbtmc) driver?

Tue Nov 26, 2013 7:24 pm

Can I also add my support for this request?
I have just got a Rigol scope and have given up trying to get USBTMC on my MacBook Pro.

I was very envious when I just plugged the scope into a friend's Arch Linus laptop and the USBTMC port just opened!!!
Mike

alex.forencich
Posts: 2
Joined: Sat Dec 14, 2013 7:20 pm

Re: USB Test & Measurement class (usbtmc) driver?

Sat Dec 14, 2013 7:24 pm

How about using a pure Python driver such as Python USBTMC? If PyUSB works on the Raspberry Pi, then Python USBTMC should also work.

https://github.com/alexforencich/python-usbtmc

User avatar
scruss
Posts: 5611
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON

Re: USB Test & Measurement class (usbtmc) driver?

Sun Dec 15, 2013 1:29 pm

OoooOOOooo! That looks neat. I'll give it a try. Thanks!
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

Alport
Posts: 3
Joined: Sat Aug 25, 2012 6:48 am

Re: USB Test & Measurement class (usbtmc) driver?

Sun Dec 15, 2013 1:52 pm

Alex,
I would like to try your USBTMC python driver on OSX and then move to the Raspberry.
I have loaded it from Github and can see the Rigol as a connected USB device by consulting Apple's System Information,
but, any chance you can supply some "Getting Started" notes from there, so that I can begin talking to the Rigol scope?
Thanks a lot,
Mike

User avatar
scruss
Posts: 5611
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON

Re: USB Test & Measurement class (usbtmc) driver?

Mon Dec 16, 2013 3:12 am

It works great, Alex!

>>> import usbtmc
>>> instr = usbtmc.Instrument(6833, 1416)
>>> print(instr.ask(“*IDN?”))
Rigol Technologies,DS1102E,DS1EB13490xxxx,00.02.06.00.01

A couple of minor problems:

  • The library seems to need root privileges, despite the udev rule thing.
  • Reading from the ‘scope’s memory chokes on non-UTF8 characters. If I do:
    rawdata = instr.ask(“:WAV:DATA? CHAN1″)[10:]
    I get a length Python error which ends:

    File “/usr/lib/python2.7/encodings/utf_8.py”, line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
    UnicodeDecodeError: ‘utf8′ codec can’t decode byte 0×99 in position 10: invalid start byte
Thanks for letting us know about it!

I wrote a simple install guide for Raspbian: My Raspberry Pi talks to my Oscilloscope | We Saw a Chicken …

cheers,
 Stewart
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

alex.forencich
Posts: 2
Joined: Sat Dec 14, 2013 7:20 pm

Re: USB Test & Measurement class (usbtmc) driver?

Tue Dec 17, 2013 5:42 am

Alport:

Sure. You'll need to know the instrument's USB vendor and product ID numbers. In linux you can get this with lsusb. I'm not sure what the proper procedure is for OS X. Then just need to import usbtmc, create a new instrument object, and you're good to go. The 'hello world' command is usually *IDN?, so try something like this:

>>> import usbtmc
>>> dso = usbtmc.Instrument(vendor, product)
>>> dso.ask('*IDN?')

substituting vendor and product for the correct ID numbers.

scruss-

Can you check on the permissions of the device node? It's possible they didn't get set correctly. Also, did you reboot or log off and log back in and unplug and replug the scope so that the group and permission changes take effect properly?

If you're working with binary data, you need to use read_raw, write_raw, and ask_raw otherwise everything gets run through utf-8 encode and decode. I believe you already asked me about this on github; it's nice to hear that you got it working!

jpkotta
Posts: 1
Joined: Tue Dec 17, 2013 6:47 pm

Re: USB Test & Measurement class (usbtmc) driver?

Tue Dec 17, 2013 6:53 pm

I've been playing with USBTMC stuff lately. Here's the udev rule I use:

Code: Select all

# /etc/udev/rules.d/usbtmc.rules

# USB test and measurement class devices
SUBSYSTEM=="usbmisc", KERNEL=="usbtmc[0-9]", GROUP="users", MODE="0666"
This is on Arch, so you'll probably have to change the group. I think it's much more useful to specify the subsystem than vendor and product IDs for every possible device.

UPDATE:

So udev is pretty confusing. I could set the permissions of the dev node, but it still wouldn't let me use python-usbtmc, presumably because it uses the USB device directly and not the dev node. I ended up with this:

Code: Select all

# /etc/udev/rules.d/usbtmc.rules

# permissions for the dev node
DRIVERS=="usbtmc", GROUP="users", MODE="0666"

# 33220A permissions for libusb
SUBSYSTEM!="usb_device", ACTION!="add", GOTO="usbtmc_rules_end"
SYSFS{idVendor}=="0957", SYSFS{idProduct}=="0407"
MODE="0666", GROUP="users"
LABEL="usbtmc_rules_end"
It seems like you still need to specify every device.

BTW, I tried to use the dev node directly, but the read() call behaves strangely. I found http://www.home.agilent.com/upload/cmc_ ... =US&lc=eng and https://github.com/imrehg/usbtmc/tree/master/agilent, but I could not set the readmode. I wish I understood why they can't just have a normal read().

User avatar
scruss
Posts: 5611
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON

Re: USB Test & Measurement class (usbtmc) driver?

Wed Dec 18, 2013 1:36 pm

alex.forencich wrote:… Also, did you reboot or log off and log back in and unplug and replug the scope so that the group and permission changes take effect properly?
Ah, that would have been it.
If you're working with binary data, you need to use read_raw, write_raw, and ask_raw otherwise everything gets run through utf-8 encode and decode.
Good to know. I'm very impressed with what you can do with USBTMC, even just with some casual messing around. Thanks for writing such an easy to use interface!
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

othane
Posts: 1
Joined: Sun Jan 12, 2014 10:10 pm

Re: USB Test & Measurement class (usbtmc) driver?

Sun Jan 12, 2014 10:30 pm

If anyone is interested compiled the usbtmc.ko driver for "Linux raspberrypi 3.10.23+" which I think is the latest from the repos using steps found here (http://elinux.org/RPi_Kernel_Compilation) and selecting the driver as a module. The binary is attached (usbtmc.ko) so just put this on the pi and "insmod ./usbtmc.ko" and you should get the /dev/usbtmc nodes. You will need to sort out the udev rules and groups as before (but this is not too hard, something like this worked for me:
$ cat /etc/udev/rules.d/usbtmc.rules
# Devices
KERNEL=="usbtmc/*", MODE="0660", GROUP="usbtmc"
KERNEL=="usbtmc[0-9]*", MODE="0660", GROUP="usbtmc"
Also I tried Python USBTMC initially, but found it a little flakey with the Tektronix TDS1012B (I think when waveforms are captured it floods the buffers and makes the pi unresponsive). Hopefully this improves as it is a nice idea, but usbtmc.ko worked better for me.
Attachments
usbtmc.ko.gz
(6.62 KiB) Downloaded 407 times

hognala
Posts: 1
Joined: Mon Oct 27, 2014 10:25 pm

Re: USB Test & Measurement class (usbtmc) driver?

Tue Oct 28, 2014 5:18 pm

Here's the compiled usbtmc.ko from "Linux raspberrypi 3.12.28+" which comes as part of Noobs 1.3.10.

I've also done some work to make the udev rules a little more user-friendly. The attached udev rules will detect any USBTMC device, you don't have to put in Vendor or Device ID's, it will call insmod for the kernel driver, then it changes the permissions so that normal users can access the kernel driver in /dev/usbtmc*

Let me know if you want tweaks to any of this...

Run

Code: Select all

sudo install.sh
Attachments
usbtmc-rpi-3.12.28+.tar.gz
(7.72 KiB) Downloaded 411 times

User avatar
cyrano
Posts: 718
Joined: Wed Dec 05, 2012 11:48 pm
Location: Belgium

Re: USB Test & Measurement class (usbtmc) driver?

Tue Oct 28, 2014 9:32 pm

Alport wrote:I have just got a Rigol scope and have given up trying to get USBTMC on my MacBook Pro.
OT

Have you seen this:
http://www.alauda.ro/2014/09/28/usbtmc- ... pple-os-x/

joosteto
Posts: 2
Joined: Fri Nov 28, 2014 3:40 pm

Re: USB Test & Measurement class (usbtmc) driver?

Fri Nov 28, 2014 3:45 pm

As I found the usbtmc.ko module posted here didn't work for my raspbian image from september 2014, I compiled a new one.
It works for me, on the 2014-09-09-wheezy-raspbian.zip image.
Attachments
usbtmc.ko.gz
(6.99 KiB) Downloaded 365 times

sibir
Posts: 27
Joined: Mon Dec 11, 2017 4:29 pm

Re: USB Test & Measurement class (usbtmc) driver?

Fri Mar 23, 2018 5:22 pm

Which source code did you use?

Return to “Raspberry Pi OS”