Python中的USBTMC

问题描述 投票:2回答:2

我想通过USB与我的Clarke-Hess Phase Meter 6000A对话。我为此目的使用https://github.com/python-ivi/python-usbtmc/tree/master/usbtmc。现在,当我连接USB电缆并做lsusb时,它会产生,

总线001设备027:ID 0403:b972 Future Technology Devices International,Ltd

作为我公认的设备,所以我只是使用usbtmc并得到以下错误:

Enter image description here

Code

>>> import usbtmc
>>> inst = usbtmc.Instrument(0x0403,0xb972)
Find USBTMC instrument
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "usbtmc/usbtmc.py", line 229, in __init__
    raise UsbtmcException("Device not found", 'init')
usbtmc.usbtmc.UsbtmcException: Device not found [init]

但是当我查看usbtmc.py时,我发现在list_devices()中,usb.util.find_descriptor()与参数一起使用,如USBTMC_bInterfaceClass = 0xFE,以及USBTMC_bInterfaceSubClass = 3,这使得它无法检测到具有描述符的设备作为bInterfaceClass和bInterfaceSubClass = 0xff。

然后我将USBTMC_bInterfaceClass和USBTMC_bInterfaceSubClass更改为0xff,然后它产生:

Enter image description here

Code

>>> import usbtmc
>>> inst = usbtmc.Instrument(0x0403,0xb972)
Find USBTMC instrument
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "usbtmc/usbtmc.py", line 283, in __init__
    self.get_capabilities()
  File "usbtmc/usbtmc.py", line 299, in get_capabilities
    timeout=self.timeout)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 971, in ctrl_transfer
    self.__get_timeout(timeout))
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 819, in ctrl_transfer
    timeout))
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 552, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 32] Pipe error

至少,在这种情况下,它检测到我的设备,但它引发了一些其他错误。

我该如何解决这个问题?该手册称该设备与类似GPIB的命令完全兼容。事实上,我已经用GPIB测试了设备,它运行正常。

python usb
2个回答
1
投票

看一眼

usbtmc.list_devices()

要么

usbtmc.find_device()

前者不需要参数。后者定义为here


1
投票

@Olaf,你是对的。它将被用作使用PySerial的串行设备。以下是它的工作原理,我遇到的问题以及解决方案。

  1. 我通过USB线连接设备,并做了lsusbroot@pelcon:~# lsusb Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 004: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller Bus 001 Device 003: ID 0cf3:3004 Atheros Communications, Inc. Bus 001 Device 006: ID 0403:b972 Future Technology Devices International, Ltd Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 003 Device 002: ID 174f:114f Syntek Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub`
  2. 接下来,我检查了设备的检测结果: root@pelcon:~# ls -al /dev/ttyUSB* ls: cannot access /dev/ttyUSB**: No such file or directory
  3. 然后我调查了这个问题并发现“在最近的内核中(肯定是14.04 LTS),ftdi_sio模块不再接受产品和供应商选项。”在Can't open port /dev/ttyUSB0
  4. 我还检查了dmesg | tail,它显示我检测到FTDI USB,但它已断开连接。
  5. 然后我做了两件事: 一个。用内容/etc/udev/rules.d/99-axe027.rules创建ATTR{idProduct}=="b972", ATTR{idVendor}=="0403", RUN+="/sbin/modprobe -q ftdi_sio product=0xb972 vendor=0x0403"。我重新开始并再次做了dmesg | tail。但它仍未被发现。步骤在Can't program with USB adapter except through sudo nautilus ubuntu中给出 湾然后我进一步搜索,这次我找到了Attaching USB-Serial device with custom PID to ttyUSB0 on embedded,我在那里: 拔掉设备插头 modprobe ftdi_sio echo 0403 b972 >/sys/bus/usb-serial/drivers/ftdi_sio/new_id 插入设备 5。 ls -al /dev/ttyUSB* crw-rw---- 1 root usbtmc 188, 0 Jul 23 11:33 /dev/ttyUSB0 6。 dmesg | tail [ 1162.348082] usb 1-1.2: Product: 6000A Phase Meter [ 1162.348086] usb 1-1.2: Manufacturer: clarke-hess [ 1162.348089] usb 1-1.2: SerialNumber: 187 [ 1162.350801] ftdi_sio 1-1.2:1.0: FTDI USB Serial Device converter detected [ 1162.350837] usb 1-1.2: Detected FT232BM [ 1162.350840] usb 1-1.2: Number of endpoints 2 [ 1162.350842] usb 1-1.2: Endpoint 1 MaxPacketSize 64 [ 1162.350844] usb 1-1.2: Endpoint 2 MaxPacketSize 64 [ 1162.350846] usb 1-1.2: Setting MaxPacketSize 64 [ 1162.351284] usb 1-1.2: FTDI USB Serial Device converter now attached to ttyUSB0`

所以,这样我的设备就被检测到了,我能够通过PySerial与它通信:

import serial, time
se = serial.Serial('/dev/ttyUSB0', 115200, timeout=1)
print('Open USB serial connection:')
print '\t', se

print se.portstr    # Confirm which port was really used
se.write("*IDN?\n")
data = se.readline()
time.sleep(2)
print data
se.close()

它输出为:

打开USB串行连接:

Serial<id=0xb329574c, open=True>(port='/dev/ttyUSB0', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False)

/ dev / ttyUSB0

CLARKE-HESS,6000A,187,1.07

© www.soinside.com 2019 - 2024. All rights reserved.