如何将泰克 TDS10001B 连接到 Ubuntu?

如何将泰克 TDS10001B 连接到 Ubuntu?

我正在尝试将 Tektronix TDS1001B 连接到 Ubuntu Precise。我已成功将示波器连接到运行 TekVISA OpenChoice 的 Windows XP 计算机,因此硬件可以正常工作。

有没有关于如何将这种范围连接到 Linux 的教程?

在 Ubuntu Precise 上,我关注了本教程。我已经安装了python-gpib_3.2.11-0.2ubuntu7_i386.deb以及libgpib0_3.2.11-0.2ubuntu7_i386.deb。我matlab也安装了。当我运行这个python代码,我得到:

root@laptop:~# dmesg -c
[  296.744133] usb 3-1: new full-speed USB device number 2 using uhci_hcd
[  296.918061] generic-usb 0003:0699:036B.0005: hiddev0,hidraw4: USB HID v1.00 Device [Tektronix, Inc. Tektronix TDS1001B] on usb-0000:00:1a.0-1/input0
[  297.504214] usb 3-1: USB disconnect, device number 2
[  299.432087] hub_port_connect_change: 30 callbacks suppressed
[  299.432099] hub 3-0:1.0: connect-debounce failed, port 1 disabled
[  299.732161] usb 3-1: new full-speed USB device number 3 using uhci_hcd
[  299.947136] usbcore: registered new interface driver usbtmc
root@laptop:~# lsmod | grep usbtmc
usbtmc                 17996  0 
root@laptop:~# ls -lah /dev/usbtmc0 
crw------- 1 root root 180, 176 Feb 17 22:36 /dev/usbtmc0
root@laptop:~# cat /dev/usbtmc0 
cat: /dev/usbtmc0: Connection timed out
root@laptop:~# python tds-2012.py
failed to open configuration file
Traceback (most recent call last):
  File "tds-2012.py", line 34, in <module>
    gpib.find('scope')
gpib.error: Find Error: can't find device!

知道如何找出我的示波器的名称吗?是否有命令行库gpib?知道如何运行本教程吗?

答案1

我找到了一个解决方案。首先,忘记 libgpib0:您需要使用内置于 Ubuntu 内核的 usbtmc。插入示波器后,确保您拥有 usbtmc 内容,如我的第一篇帖子中所述:

root@laptop:~# dmesg -c
[  296.744133] usb 3-1: new full-speed USB device number 2 using uhci_hcd
[  296.918061] generic-usb 0003:0699:036B.0005: hiddev0,hidraw4: USB HID v1.00 Device [Tektronix, Inc. Tektronix TDS1001B] on usb-0000:00:1a.0-1/input0
[  297.504214] usb 3-1: USB disconnect, device number 2
[  299.432087] hub_port_connect_change: 30 callbacks suppressed
[  299.432099] hub 3-0:1.0: connect-debounce failed, port 1 disabled
[  299.732161] usb 3-1: new full-speed USB device number 3 using uhci_hcd
[  299.947136] usbcore: registered new interface driver usbtmc
root@laptop:~# lsmod | grep usbtmc
usbtmc                 17996  0 
root@laptop:~# ls -lah /dev/usbtmc0 
crw------- 1 root root 180, 176 Feb 17 22:36 /dev/usbtmc0

请注意,您可以写入和读取 /dev/usbtmc0:

echo "*IDN?" > /dev/usbtmc0
cat /dev/usbtmc0

你应该得到类似这样的结果:

TEKTRONIX,TDS 1001B,C062368,CF:91.1CT FV:v22.01

你可能必须这样做:

chmod a+w /dev/usbtmc0

然后,我更新并修复了python脚本:

--- tds-2012.py 2013-02-23 11:26:54.902570542 -0800
+++ tds-2012.py 2013-02-23 11:40:59.506758703 -0800
@@ -21,8 +21,7 @@
 #   in /etc/gpib.conf.


-from Gpib import *
-from matplotlib.matlab import *
+from matplotlib.pyplot import *
 from string import *
 from time import *
 from struct import *
@@ -30,9 +29,23 @@
 # how long to sleep after issuing a write
 sleeptime = 0.01

-# set up GPIB comms and clear device
-scope = gpib.find('scope')
-gpib.clear(scope)
+class gpib_usbtmc:
+   def __init__(self):
+       self.usbtmc = open("/dev/usbtmc0", "r+")
+
+   def write(self, wathever, string):
+       self.usbtmc.write(string + "\n")
+
+   def read(self, whatever, size):
+       return self.usbtmc.readline().strip()
+
+   def readbin(self, whatever, size):
+       return self.usbtmc.readline()
+
+scope = 0
+gpib = gpib_usbtmc()
+#gpib.write(scope, '*IDN?')
+#print "ID: ", gpib.read(scope, 128)

 # set SRQ operation
 gpib.write(scope,'DESE 1')
@@ -172,7 +185,7 @@
 axis([0,points,-5*voltsdiv,5*voltsdiv])
 xlabel(sweep_string)
 ylabel(volt_string)
-set(gca(), 'xticklabels', [])
+setp(gca(), 'xticklabels', [])
 if not gca().is_first_col():
    set(gca(), 'yticklabels', [])
 if not gca().is_last_row():

整个脚本现在如下所示:

#!/usr/bin/env python

# found on <http://www.febo.com/geekworks/data-capture/tds-2012.html>: <ftp://ftp.febo.com/pub/n8ur_programs/tds-2012.py>

# tds-2012.py
# version 0.1 -- 27 Jan 2004
#
# Plot display of Tektronix TDS-2012 (or other TDS-10xx or TDS-20xx DSO)
#
# Copyright 2004 by John R. Ackermann  N8UR ([email protected])
# Licensed under the GPL version 2 or later; see the file COPYING
# included with this distribution.  I request, but do not require, that
# any modifications that correct bugs or errors, or increase the program's
# functionality, be sent via email to the author at the address above.
#
# Current status:
# Version 0.1 -- first version, and first ever Python program.  Note that
#   binary read requires updated linux-gpib python bindings (post version
#   3.1.99).  If you don't have that version, you can convert to use an
#   ASCII data read as commented below.  Assumes that "scope" is defined 
#   in /etc/gpib.conf.


from matplotlib.pyplot import *
from string import *
from time import *
from struct import *

# how long to sleep after issuing a write
sleeptime = 0.01

class gpib_usbtmc:
    def __init__(self):
        self.usbtmc = open("/dev/usbtmc0", "r+")

    def write(self, wathever, string):
        self.usbtmc.write(string + "\n")

    def read(self, whatever, size):
        return self.usbtmc.readline().strip()

    def readbin(self, whatever, size):
        return self.usbtmc.readline()

scope = 0
gpib = gpib_usbtmc()
#gpib.write(scope, '*IDN?')
#print "ID: ", gpib.read(scope, 128)

# set SRQ operation
gpib.write(scope,'DESE 1')
gpib.write(scope,'*ESE 1')
gpib.write(scope,'*SRE 32')

# turn off response headers and set waveform output to default binary
# it seems like these need to be sent separately and not concatenated
gpib.write(scope,'head 0')

# for ASCII dump, send 'dat ASCII' instead
gpib.write(scope,'dat INIT')
sleep(sleeptime)

# get instrument settings
gpib.write(scope,'ch1:scale?')
sleep(sleeptime)
voltsdiv = float(gpib.read(scope,80))
if voltsdiv >= 1:
    volt_string = '%i V / div' % (voltsdiv)
else:
    volt_string = '%i mv / div' % (voltsdiv * 1000)

gpib.write(scope,'hor:mai:sca?')
sleep(sleeptime)
tmp = float(gpib.read(scope,80))
rawsweep = tmp
if tmp >= 1:
    sweep_val = tmp
    sweep_suf = "S"
if tmp < 1:
    sweep_val = tmp * 10e2
    sweep_suf = "mS"
    if tmp < 0.001:
        sweep_val = tmp * 10e5
        sweep_suf = "uS"
        if tmp < 0.000001:
            sweep_val = tmp * 10e8
            sweep_suf = "nS"
sweep_val = '%.f' % sweep_val
sweep_string = sweep_val + ' ' + (sweep_suf) + " / div"

# acquire
gpib.write(scope,'acquire:state on')
sleep(sleeptime)

# get the waveform preamble
gpib.write(scope,'wfmpre?')
sleep(sleeptime)
tmp = gpib.read(scope,256)
preamble = split(tmp,';')
# number of points in trace
points = int(preamble[5])
# volts per bit (-127 to +128)
voltsbit = float(preamble[12])

# get the curve
gpib.write(scope,'curv?')
sleep(sleeptime)

# binary data read and convert to list
tmp = gpib.readbin(scope,4096)

# for ASCII read, use 'gpib.read(scope,16384)' instead of the above, and 
# delete the next two lines.  You'll need to use 'split' to convert the 
# comma-delimited values returned in 'tmp' to a list of values called
# 'tmplist', and you may need to adjust the offsets used in the 'for' loop 
# to end up with the proper number of points

formatstring = '%ib' % (len(tmp))
tmplist = unpack(formatstring,tmp)

trace = []
# there's a newline at the end of the data, thus the strange slice
for x in tmplist[len(tmplist)-points-1:-1]:
    trace.append(int(x)*voltsbit)

# get some measurements, just for fun
tmp = 9.9E37
gpib.write(scope,'measu:imm:typ PK2;:measu:imm:sou CH1')
sleep(sleeptime)
gpib.write(scope,'measu:imm:val?')
sleep(sleeptime)
tmp = float(gpib.read(scope,80))
if tmp != 9.9E37:
    peak_string = 'Pk-Pk: %.3f V' % (tmp)
else: peak_string = ''

gpib.write(scope,'measu:imm:typ MEAN;:measu:imm:sou CH1')
sleep(sleeptime)
gpib.write(scope,'measu:imm:val?')
tmp = float(gpib.read(scope,80))
if tmp != 9.9E37:
    mean_string = 'Mean: %.3f V' % (tmp)
else: mean_string = ''

gpib.write(scope,'measu:imm:typ PERI;:measu:imm:sou CH1')
sleep(sleeptime)
gpib.write(scope,'measu:imm:val?')
tmp = float(gpib.read(scope,80))
if tmp >= 1:
    period_val = tmp
    period_suf = "S"
if tmp < 1:
    period_val = tmp * 10e2
    period_suf = "mS"
    if tmp < 0.001:
        sweep_val = tmp * 10e5
        sweep_suf = "uS"
        if tmp < 0.000001:
            period_val = tmp * 10e8
            period_suf = "nS"
if tmp != 9.9E37:
    period_string = 'Period: %.3f' % (period_val) + ' ' + period_suf
else: period_string = ''

gpib.write(scope,'measu:imm:typ FREQ;:measu:imm:sou CH1')
sleep(sleeptime)
gpib.write(scope,'measu:imm:val?')
tmp = float(gpib.read(scope,80))
if tmp < 1e3:
    freq_val = tmp
    freq_suf = "Hz"
if tmp < 1e6:
    freq_val = tmp / 10e2
    freq_suf = "kHz"
if tmp >= 1e6:
    freq_val = tmp / 10e5
    freq_suf = "MHz"

if tmp != 9.9E37:
    freq_string = 'Freq: %.3f' % (freq_val) + ' ' + freq_suf
else: freq_string = ''

# plot
plot(trace)
axis([0,points,-5*voltsdiv,5*voltsdiv])
xlabel(sweep_string)
ylabel(volt_string)
setp(gca(), 'xticklabels', [])
if not gca().is_first_col():
    set(gca(), 'yticklabels', [])
if not gca().is_last_row():
    set(gca(), 'xticklabels', [])
grid(1)

text(0.03*points,-4.9*voltsdiv, peak_string)
text(0.03*points,-4.4*voltsdiv, mean_string)
text(0.72*points,-4.93*voltsdiv, freq_string)
text(0.72*points,-4.4*voltsdiv, period_string)

show()

而且它正在工作!是的,你可以感谢我 ;-)

相关内容