1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Ubuntu環境でUSB/GPIB変換アダプターを使えるようにする(Agilent Technologies 82357A)

Posted at

概要

計測器のデータをパソコンに取り込むために変換アダプター用意したものの、ドライバがWindows Xpまでしか対応しておらず使えなかった。
そのため、今回はUbuntuで使用できるよう調整を行った。

環境

OS : Ubuntu 22.04.5 LTS
変換アダプタ : Agilent Technologies 82357A

作成手順

  1. PCと変換アダプターを接続する
    接続後以下のコマンドを実行する

    $ lsusb
    

    いくつか出力されるが、以下の項目があれば正常に認識できている。

    Bus 002 Device 005: ID 0957:0007 Agilent Technologies, Inc.
    

    Bus及びDeviceのあとの3桁の数字は環境によって異なる。
    なお、この時点では変換アダプタの表示はFAILが点灯しているのみである。

  2. 作業環境の構築
    インストールの過程でファイルに様々な編集を行うため、あらかじめそれ用の環境を構築しておく。
    今回はドキュメント内に作成する

    $ cd ~/Documents/
    $ mkdir Linux-GPIB
    $ cd ./Linux-GPIB/
    
  3. 必要ファイルのダウンロード
    次のファイルをそれぞれダウンロードし、先ほど作成したLinux-GPIBフォルダの中に入れる。
    https://sourceforge.net/projects/linux-gpib/
    https://linux-gpib.sourceforge.io/firmware/gpib_firmware-2008-08-10.tar.gz
    最終的にフォルダ内に以下のファイルがあれば良い。

    $ ls
    gpib_firmware-2008-08-10.tar.gz  linux-gpib-4.3.7.tar.gz
    
  4. ドライバのインストール
    もしGCC12をインストールしていない場合は、以下のコマンドを実行して先にインストールしておく。

    $ sudo apt install gcc-12
    

    以下のコマンドを順番に実行していき、インストールを行う

    $ tar xzvf linux-gpib-4.3.7.tar.gz
    $ cd ./linux-gpib-4.3.7
    $ tar xzvf linux-gpib-kernel-4.3.7.tar.gz
    $ cd ./linux-gpib-kernel-4.3.7
    $ make
    $ sudo make install
    $ cd ../
    $ tar xzvf linux-gpib-user-4.3.7.tar.gz
    $ cd ./linux-gpib-user-4.3.7
    $ ./configure
    $ make
    $ sudo make install
    

    ※エラーについて

    • 最初のmakeでエラーが出力された場合1
      以下のコマンドを実行し、カーネルヘッダーの完全インストールを行う。

      $ sudo apt update
      $ sudo apt install --reinstall linux-headers-$(uname -r)
      
    • 最初のmakeでエラーが出力された場合2

      warning: the compiler differs from the one used to build the kernel
        The kernel was built by: aarch64-linux-gnu-gcc-13 (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
        You are using:           
            CC [M]  /home/maro11/Linux-GPIB/linux-gpib-4.3.7/linux-gpib-kernel-4.3.7/drivers/gpib/agilent_82350b/agilent_82350b.o
      /bin/sh: 1: gcc-13: not found
      

      上は違う環境ではあるが、コンパイルにおいてgccが見つからず、エラーが出力されることがある。
      この場合は指定されたgccをインストールすれば良い。
      上の場合であれば、gcc-13: not foundとの記述が見られるため、GCC 13をインストールする。

      $ sudo apt install gcc-13
      
    • ./configureにおいてエラーが出力された場合1
      もう一度./configureを実行する。

    • ./configureにおいてエラーが出力された場合2
      上の手順でも再びエラーが出力され、それが以下のエラーである場合はbuild-essentialをインストールすれば良い。

      configure: error: in '/home/maro11/Linux-GPIB/linux-gpib-4.3.7/linux-gpib-user-4.3.7':
      configure: error: no acceptable C compiler found in $PATH
      See 'config.log' for more details
      

      次のコマンドでインストールを行う

      $ sudo apt install build-essential
      

    また、以下のコマンドを実行し一緒にインストールしておく。

    $ sudo apt install python3-dev libboost-dev python3-setuptools
    
  5. ファームウェアの用意
    fxloadを使うため、予めインストールしておく

    $ sudo apt install fxload
    

    あらかじめダウンロードしておいたファームウェアを展開する。

    $ cd ~/Documents/Linux-GPIB/
    $ tar xvzf gpib_firmware-2008-08-10.tar.gz
    $ cd ./gpib_firmware-2008-08-10/agilent_82357a/
    $ ls
    82357a_fw.hex  README~     lsusb_initial.txt   measat_releaseX1.8.hex
    README         firmware.c  lsusb_postload.txt
    
  6. gpib.confの設定
    お好みのエディタで以下のファイルの編集を行う。

    $ sudo vim /usr/local/etc/gpib.conf
    

    今回は以下の通りにした

    gpib.conf
    /***********************************************************************
    				 GPIB.CONF IEEE488 library config file
    							-------------------
    
    copyright            : (C) 2002 by Frank Mori Hess
    						(C) 1994 by C.Schroeter
    email                : fmhess@users.sourceforge.net
    ***************************************************************************/
    /***************************************************************************
     *    
     *   Syntax:
     *
     *         interface { ... } starts new interface board section
     *         device {...} device configuration
     *
     ***************************************************************************/
    
    /* This section configures the configurable driver characteristics
    * for an interface board, such as board address, and interrupt level.
    * minor = 0 configures /dev/gpib0, minor = 1 configures /dev/gpib1, etc.
    */
    
    interface {
    	minor = 0	/* board index, minor = 0 uses /dev/gpib0, minor = 1 uses /dev/gpib1, etc. */
    	board_type = "agilent_82357a"	/* type of interface board being used */
    	name = "agi"	/* optional name, allows you to get a board descriptor using ibfind() */
    	pad = 0	/* primary address of interface             */
    	sad = 0	/* secondary address of interface           */
    	timeout = T3s	/* timeout for commands */
    
    	eos = 0x0a	/* EOS Byte, 0xa is newline and 0xd is carriage return */
    	set-reos = yes	/* Terminate read if EOS */
    	set-bin = no	/* Compare EOS 8-bit */
    	set-xeos = no	/* Assert EOI whenever EOS byte is sent */
    	set-eot = yes	/* Assert EOI with last byte on writes */
    
    /* settings for boards that lack plug-n-play capability */
    	base = 0	/* Base io ADDRESS                  */
    	irq  = 0	/* Interrupt request level */
    	dma  = 0	/* DMA channel (zero disables)      */
    
    /* pci_bus and pci_slot can be used to distinguish two pci boards supported by the same driver */
    /*	pci_bus = 0 */
    /*	pci_slot = 7 */
    
    	master = yes	/* interface board is system controller */
    }
    
    /* This is how you might set up a pcIIa board on /dev/gpib1, uncomment to use. */
    /*******************
    interface {
    	minor = 1
    	board_type = "pcIIa"
    	pad = 0
    	sad = 0
    	timeout = T3s
    
    	eos = 0x0a
    	set-reos = yes
    	set-bin = no
    
    	base = 0x2e1
    	irq  = 7
    	dma  = 1
    
    	master = yes
    }
    *********************/
    
    /* Now the device sections define the device characteristics for each device.
    * These are only used if you want to open the device using ibfind() (instead
    * of ibdev() )
    */
    
    device {
    	minor = 0	/* minor number for interface board this device is connected to */
    	name = "voltmeter"	/* device mnemonic */
    	pad = 7	/* The Primary Address */
    	sad = 0	/* Secondary Address */
    
    	eos = 0xa	/* EOS Byte */
    	set-reos = no /* Terminate read if EOS */
    	set-bin = no /* Compare EOS 8-bit */
    }
    
    device {
    	minor = 0
    	name = "agilent_34401a"
    	pad = 12
    	sad = 0
    }
    

    編集が終わったら保存する。

  7. カーネルモジュールのロード
    以下のコマンドを実行しカーネルモジュールをロードする。

    $ sudo modprobe gpib_common
    $ sudo modprobe agilent_82357a
    

    なお、sudo modprobe gpib_commonについて、パソコンのSecure Bootが有効であると、エラーが出力されるため注意。

  8. fxloadでプラグ
    もし、アダプタを既にに接続しているならば、一度抜き5秒待ってから再び接続する。
    その後、アダプターのBusとDeviceを確認するために以下のコマンドを実行する。

    $ lsusb
    (前略)
    Bus 002 Device 018: ID 0957:0007 Agilent Technologies, Inc.
    (後略)
    

    今回の場合、Busは002、Deviceは018である。
    次のコマンドを、以下のルールに則って実行する。

    $ sudo fxload -t fx -D /dev/bus/usb/(Busの3桁)/(Deviceの3桁) -I ./82357a_fw.hex
    

    今回の場合sudo fxload -t fx -D /dev/bus/usb/002/018 -I ./82357a_fw.hexとなる。

    すると、アダプタのすべてのランプが点灯する。
    もう一度lsusbを実行すると

    $ lsusb
    (前略)
    Bus 002 Device 019: ID 0957:0107 Agilent Technologies, Inc. 82357A (041012-10:21)
    (後略)
    

    上のように出力され、しっかりと認識していることがわかる。

  9. GPIBデバイスファイルの権限の変更
    次のコマンドを実行し、アクセスできるようにする。

    $ sudo chmod 666 /dev/gpib0
    
  10. ライブラリのシンボルリンクの作成

    $ sudo ln -s /usr/local/lib/libgpib.so.0 /lib/libgpib.so.0
    
  11. GPIBの設定の反映
    以下のコマンドを実行し、設定を反映させておく。

    $ sudo /usr/local/sbin/gpib_config
    

    すると、変換アダプタのランプがREADYのみ点灯するようになり、使用できるようになる。

以上で必要なすべての手順は終了である。
お疲れ様でした。

参考文献

https://jf1dir.hatenablog.com/entry/2020/07/14/173515
https://www.linuxquestions.org/questions/linux-software-2/how-to-enable-agilent-82357a-usb-gpib-dongle-and-remain-sane-4175498814/

後日談

Raspberry Piでも使えるか確かめてみたら同じ手順で使用できた。
環境は以下の通りである。

ボード : Raspberry Pi 5
OS : Ubuntu 24.04.3 LTS

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?