ioctl errorno: 25 在使用 python-gpib 的 GPIB 通信中

Posted

技术标签:

【中文标题】ioctl errorno: 25 在使用 python-gpib 的 GPIB 通信中【英文标题】:ioctl errorno: 25 in GPIB communication using python-gpib 【发布时间】:2015-11-26 19:55:12 【问题描述】:

我正在尝试使用 National Instruments 的 GPIB-USB-HS 适配器与 Tektronix 示波器 TDS 210 通信。我的系统是 Ubuntu 14.04.3,我在此链接中安装了 linux-gpib:Linux GPIB Driver package (source) 和 python-gpib。我像这样重新配置了/etc/gpib.conf:

interface 
    minor = 0   /* board index, minor = 0 uses /dev/gpib0, minor = 1 uses /dev/gpib1, etc. */
    board_type = "ni_usb_b" /* type of interface board being used */
    name = "tds"    /* optional name, allows you to get a board descriptor using ibfind() */
    pad = 0 /* primary address of interface             */
    sad = 0 /* secondary address of interface           */
    master = yes    /* interface board is system controller */
    timeout = TNONE /* timeout for commands */

device 
       minor = 0
       name = "ATTN"
       pad = 0
       sad = 0

lsmod 给我这个:

$ lsmod | grep gpib
ni_usb_gpib            36515  1 
gpib_common            38274  3 ni_usb_gpib

dmesg:

$ dmesg | grep gpib
[ 2173.992039] ni_usb_gpib driver loadingni_usb_gpib: probe succeeded for path: usb-0000:00:1a.0-1.2
[ 2173.992098] usbcore: registered new interface driver ni_usb_gpib
[ 2173.992102] gpib: registered ni_usb_b interface
[ 2173.995077] ni_usb_gpib: attach

但是当尝试使用 ibtest 与示波器通信时,我收到此错误:

gpib status is: 
ibsta = 0x8100  < ERR CMPL >
iberr= 0
EDVR 0: OS error
ibcnt = 25

使用 Python:

import Gpib
tds = Gpib.Gpib(0,0)
tds.write("*IDN?")
---------------------------------------------------------------------------
GpibError                                 Traceback (most recent call last)
<ipython-input-4-e61e6a76ac49> in <module>()
      1 import Gpib
      2 inst = Gpib.Gpib(0,0)
----> 3 inst.write("*IDN?")

/usr/local/lib/python2.7/dist-packages/Gpib.pyc in write(self, str)
     47 
     48         def write(self,str):
---> 49                 gpib.write(self.id, str)
     50 
     51         def write_async(self,str):

GpibError: write() error: Inappropriate ioctl for device (errno: 25)

是否有人已经遇到过类似的问题或知道如何解决?

【问题讨论】:

您是否先尝试与供应商提供的工具进行沟通?在自己编程之前,我发现这非常有用,因为通常需要考虑许多参数,例如每行末尾是否有字符,甚至何时切换某些控制信号。此外,您甚至可能在布线或兼容性方面遇到问题。最后,并非所有设备都支持*IDN? (我有一些古老的设备,我认为他们有 *ID?而不是)。 我认为问题出在 GPIB 配置中...我已经为泰克示波器、锁定、单色仪制作了许多 python 脚本,但始终使用 ttyUSB 或 usbtmc,换句话说,RS232 协议,与并且没有适配器插头......这个错误以前从未发生过。供应商总是试图卖给我 Labview =/。可能是电缆...我会检查的。 *国际化域名?是 Tektronix 和 National Instruments 的通用 SCPI。谢谢! 【参考方案1】:

在 ibtest 和 python 中,我遇到了与您完全相同的错误。我试图让 gpib 在 pi 上工作。我按照教程https://xdevs.com/guide/ni_gpib_rpi/

我通过更改我的 /etc/gpib.conf 来修复它(注意 eos):

interface 
minor = 0  
board_type = "ni_usb_b"
name = "violet"
pad = 0 
sad = 0 
timeout = T30s  
eos = 0xd       /* EOS Byte, was 0xa and I got same errors as you */
set-reos = yes   
set-bin = no    
set-xeos = no   
set-eot = yes   
master = yes    

现在一切正常!

$ sudo gpib_config
$ sudo ibtest
Do you wish to open a (d)evice or an interface (b)oard?
    (you probably want to open a device): d
enter primary gpib address for device you wish to open [0-30]: 3
trying to open pad = 3 on /dev/gpib0 ...
You can:
    w(a)it for an event
    ...
    (w)rite data string
: w
enter a string to send to your device: *idn?
sending string: *idn?

gpib status is:
ibsta = 0x2100  < END CMPL >
iberr= 0

ibcnt = 6
You can:
    w(a)it for an event
    ...      
    (r)ead string

: r
enter maximum number of bytes to read [1024]:
trying to read 1024 bytes from device...
received string: 'AEROFLEX,3920,1000662592,3.7.0,2'
Number of bytes read: 32
gpib status is:
ibsta = 0x2100  < END CMPL >
iberr= 0

ibcnt = 32

在 Python 中,除非我在实例化后调用 clear,否则我会收到错误,然后就可以继续了:

? sudo python
Python 2.7.9 (default, Mar  8 2015, 00:52:26)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Gpib
>>> inst = Gpib.Gpib(0,3)
>>> inst.clear()
>>> inst.write("*idn?")
>>> inst.read(100)
'AEROFLEX,3920,1000662592,3.7.0,2'

如果您仍然无法与乐器对话,请尝试使用字符串 ID?而不是 *IDN?。有些 hp 设备有备用命令语法,它使用不同的命令字符串,查看手册(可能在后面顺便提到),您通常可以使用命令来回切换语法。祝你好运。

【讨论】:

以上是关于ioctl errorno: 25 在使用 python-gpib 的 GPIB 通信中的主要内容,如果未能解决你的问题,请参考以下文章

ioctl接口 -25

ioctl 命令的用户权限检查

Ansible 错误 "ERROR! (25, 'Inappropriate ioctl for device')", "unreachable" 是啥意思?

使用 ioctl 或 netlink 向接口添加和删除 IP 地址

SPI(串行端口通信)问题,卡在 ioctl()

mysql ErrorNo:1449