2016年8月4日木曜日

LinuxでAgilentの82357Bを使うために part 3: 本編

それでは,まずfirmwareも何もしない状態で82357Bをusbポートに差し込みます。
lsusbしてみます。

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 003: ID 8086:0186 Intel Corp. WiMAX Connection 2400m
Bus 002 Device 003: ID 0957:0518 Agilent Technologies, Inc. 82357B GPIB Interface


きちんと82357BがBus 002にDevice 003,IDが0957:0518として認識されています。
(オレンジと赤の色は私がつけました。)
このBus番号とDevice番号を控えておきます。
ところが,この時にアダプタ本体を見てみると,FAILの赤いLEDが光っています。



suになって,gpib_common.koとagilent_82357a.koのモジュールを組み込みます。
ここで注意しないといけないのは,linux-gpibはカーネルが変わるたびにmakeし直さないといけないということです。そうでないと多分いろいろ面倒なことになります。
なので,カーネルをアップデートなりアップグレードなりしたら必ずlinux-gpibもmakeし直します。
なので,以下のカーネルバージョン番号も,今のカーネルバージョンに合わせて読み替える必要があります。


[root@gpibnote01 Downloads]# insmod /lib/modules/2.6.32-642.el6.i686/gpib/sys/gpib_common.ko 
[root@gpibnote01 Downloads]# insmod /lib/modules/2.6.32-642.el6.i686/gpib/agilent_82357a/agilent_82357a.ko 
[root@gpibnote01 Downloads]# 



dmesgしてみると,きちんと認識されています。


[root@gpibnote01 Downloads]# dmesg
*
*
(中略)
*
*
Linux-GPIB 4.0.3 Driver
agilent_82357a_gpib driver loading
usbcore: registered new interface driver agilent_82357a_gpib
gpib: registered agilent_82357a interface


でも,アダプタを見るとまだ赤いFAILが点灯しています。
lsmodしてみます。

[root@gpibnote01 Downloads]# lsmod | grep agilent
agilent_82357a         16562  0 
gpib_common            27244  1 agilent_82357a
[root@gpibnote01 Downloads]# 


それでは,さっきfirmwareをダウンロードして展開したディレクトリに移動します。

[root@gpibnote01 Downloads]# cd gpib_firmware-2008-08-10
[root@gpibnote01 gpib_firmware-2008-08-10]# ls
README  agilent_82357a  hp_82341  hp_82350a  ni_gpib_usb_b
[root@gpibnote01 gpib_firmware-2008-08-10]# 
[root@gpibnote01 gpib_firmware-2008-08-10]# cd agilent_82357a/

[root@gpibnote01 agilent_82357a]# ls

82357a_fw.hex  README~     lsusb_initial.txt   measat_releaseX1.8.hex

README         firmware.c  lsusb_postload.txt

[root@gpibnote01 agilent_82357a]# 


ここのREADMEを見てみると,やり方が書いてありました。


[root@gpibnote01 agilent_82357a]# cat README
The firmware files can be uploaded to your Agilent 82357A/B adapter
using fxload.  The 82357a_fw.hex file is for the 82357A and the
measat_releaseX1.8.hex file is for the 82357B.

There is apparently a bug in the 82357B firmware which causes the
first firmware upload to an 82357B to fail.  After the first
attempt, the device will disconnect then reconnect (with a
new address), but will still be in an uninitialized state with
device id 518.  Loading the firmware a second time will
cause the device to disconnect again, but this time it when
it comes back it will be fully functional with device id 718.
If you have your OS set up to
automatically load the firmware, you
won't notice this bug, since it will just cause the OS to
automatically load the firmware twice.


Examples:

fxload -D /proc/bus/usb/001/002 -I 82357a_fw.hex 

fxload -t fx2 -D /proc/bus/usb/001/003 -I measat_releaseX1.8.hex


Note the 82357B requires the "-t fx2" command line option of fxload.

If you wish for the firmware to be automatically loaded through hotplug, 
copy the firmware file to the /usr/share/usb/agilent_8237a/ directory
(or wherever the /etc/hotplug/usb/agilent_82357a script expects to find it).


なるほど,二回やらないといけないのですね。
ではまず一回目のfxloadをやってみます。
この時,lsusbで確認したBus番号とDevice番号を使うようにします。

[root@gpibnote01 agilent_82357a]# fxload -t fx2 -D /proc/bus/usb/002/003 -I measat_releaseX1.8.hex 

何も起こりません。しかしこの時,実際は一度引き抜かれてまた挿し直されたと勘違いしているみたいです。
dmesgしてみると,

usb 2-1.2: USB disconnect, device number 3
usb 2-1.2: new high speed USB device number 4 using ehci_hcd
usb 2-1.2: New USB device found, idVendor=0957, idProduct=0518
usb 2-1.2: New USB device strings: Mfr=0, Product=0, SerialNumber=0
usb 2-1.2: configuration #1 chosen from 1 choice


のように出ています。
ここでlsusbしてみると,device numberが一つ上がっています。

[root@gpibnote01 agilent_82357a]# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 003: ID 8086:0186 Intel Corp. WiMAX Connection 2400m
Bus 002 Device 004: ID 0957:0518 Agilent Technologies, Inc. 82357B GPIB Interface
[root@gpibnote01 agilent_82357a]# 


ここでもう一回fxloadでfirmwareをアップロードするのですが,この時Deviceが004に変わっていることに注意しないといけません。

[root@gpibnote01 agilent_82357a]# fxload -t fx2 -D /proc/bus/usb/002/004 -I measat_releaseX1.8.hex 
[root@gpibnote01 agilent_82357a]# 

ここで何か言われていたら,おそらくDevice番号を間違えているのだと思います。
うまくいっていれば何も返事がないはずです。
dmesgしてみると,

usb 2-1.2: USB disconnect, device number 4
usb 2-1.2: new high speed USB device number 5 using ehci_hcd
usb 2-1.2: New USB device found, idVendor=0957, idProduct=0718
usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=5
usb 2-1.2: Product: 82357B ()
usb 2-1.2: Manufacturer: Agilent Technologies, Inc.
usb 2-1.2: SerialNumber: MY49450481
usb 2-1.2: configuration #1 chosen from 1 choice
probe succeeded for path: usb-0000:00:1d.0-1.2
attached to bus interface 0, address 0xf33fa200
agilent_82357a_attach: attached

となって,またdevice number4が引っこ抜かれてdevice number5に変わっています。
ここで注目すべきは,idProductが0718に変わっているというところです。
ちなみに私はすでに/etc/gpib.configに記述がある上に,すでに一連の作業を終えているので,最後の二行のようにもう使える状態になっています。
そうでない場合は,/etc/gpib.confを適切に書き換えて,gpib_configコマンドを管理者権限で行います。
こうなると背面のLEDが緑色に点灯しています。




ibtestをして通信してみました。

[root@gpibnote01 agilent_82357a]# 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]: 16
trying to open pad = 16 on /dev/gpib0 ...

: w
enter a string to send to your device: *idn?
sending string: *idn?

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

ibcnt = 6

: r
enter maximum number of bytes to read [1024]: 100
trying to read 100 bytes from device...
received string: 'LSCI,MODEL330,0,061694
'
Number of bytes read: 24
gpib status is: 
ibsta = 0x2100  < END CMPL >
iberr= 0

ibcnt = 24



*idn?と話しかけて,LSCI,MODEL330,0,061694とお返事をもらいました。









0 件のコメント:

コメントを投稿