2023年5月4日木曜日

NI-GPIBドライバ(LabView)のM1&M2mac(apple silicon)対応状況

NIから 2023年4月27日に最新の情報が更新されましたが,相変わらずです。

macOS 13  (x86_64)と書いてあるので,intelチップのみの対応と考えられます。

まぁ,おそらくカーソルを合わせておかないと処理が極端に遅くなる問題にも対応できていないと思いますので,しばらくはlinux上で測定を進めます。

linuxもかなり便利になってきて,x11vncなどを使えばデスクトップを共有できるし,smb,最近ではgoogle driveにも対応できるので,しばらくはlinuxで不便は感じないかと。

2023年3月15日水曜日

xubuntu22.04でsambaを使ってホームディレクトリを共有

 昨日から今日で測定用のxubuntuをdo-release-upgradeして20.04から22.04にしました。

データを共有するためにsambaをインストール

$ sudo apt install samba

設定ファイル/etc/smb.confに以下を付け加える。

[<ユーザ名>]

path = /home/<ユーザ名>

browsable = yes

writable = yes

guest ok = no

read only = no

もちろん,<ユーザ名>のところは共有したいユーザ名。

最後に,パスワード設定

$ sudo smbpasswd -a username <ユーザ名>

求められるがままにパスワードを設定する。

その後,

$ sudo systemctl restart smbd nmbd

うまくアクセスできたら,起動時に有効になるように,

$ sudo systemctl enable smbd nmbd


あとは,macならFinderでコマンドキー+Kで移動メニューを表示して,smb://<ipアドレス>/<ユーザ名>へ接続。

先ほどのユーザ名とパスワードで接続できます。





2023年3月14日火曜日

x11vncをXubuntu20.04にインストールし,windowsのrdpやmacの画面共有のようにディスプレイに表示された画面をそのままコントロール

 Ubuntuにx11vncを入れる場合は,lightdmをインストールして云々とやる必要があるが,xubuntuはそもそもlightdmなのでその必要がない。


x11vncをインストールした後,パスワードファイルを生成する。


$ sudo x11vnc -storepasswd /etc/x11vnc.pass

[sudo]  <username> のパスワード: 

Enter VNC password: 

Verify password:    

Write password to /etc/x11vnc.pass?  [y]/n y

Password written to: /etc/x11vnc.pass


その後,自動起動のためのファイルを作成。


~$ sudo vi /etc/systemd/system/x11vnc.service



内容はこんな感じ


~$ more /etc/systemd/system/x11vnc.service 

[Unit] 

Description=Start x11vnc at startup. 

After=multi-user.target

[Service] 

Type=simple 

ExecStart=/usr/bin/x11vnc -auth guess -noxrecord -noxfixes -noxdamage -rfbauth /etc/x11vnc.pass -forever -xkb -loop -shared -repeat -rfbport 5900 -o /var/log/x11vnc.log


[Install] 

WantedBy=multi-user.target


起動はsystemctlで。

自動起動するためには,systemctlでenableを指定。


$ sudo systemctl enable x11vnc

Created symlink /etc/systemd/system/multi-user.target.wants/x11vnc.service → /etc/systemd/system/x11vnc.service.


無事リンクが貼られて自動起動の準備ができた模様。

確認する。

$ ls -l /etc/systemd/system/multi-user.target.wants/

合計 0

lrwxrwxrwx 1 root root 40  3月 14 18:48 ModemManager.service -> /lib/systemd/system/ModemManager.service

lrwxrwxrwx 1 root root 42  3月 14 18:48 NetworkManager.service -> /lib/systemd/system/NetworkManager.service

lrwxrwxrwx 1 root root 35  3月 14 18:48 anacron.service -> /lib/systemd/system/anacron.service

lrwxrwxrwx 1 root root 40  3月 14 18:48 avahi-daemon.service -> /lib/systemd/system/avahi-daemon.service

lrwxrwxrwx 1 root root 45  3月 14 18:48 blueman-mechanism.service -> /lib/systemd/system/blueman-mechanism.service

lrwxrwxrwx 1 root root 41  3月 14 18:48 console-setup.service -> /lib/systemd/system/console-setup.service

lrwxrwxrwx 1 root root 32  3月 14 18:48 cron.service -> /lib/systemd/system/cron.service

lrwxrwxrwx 1 root root 40  3月 14 18:48 cups-browsed.service -> /lib/systemd/system/cups-browsed.service

lrwxrwxrwx 1 root root 29  3月 14 18:48 cups.path -> /lib/systemd/system/cups.path

lrwxrwxrwx 1 root root 33  3月 14 18:48 dmesg.service -> /lib/systemd/system/dmesg.service

lrwxrwxrwx 1 root root 39  3月 14 18:48 grub-common.service -> /lib/systemd/system/grub-common.service

lrwxrwxrwx 1 root root 48  3月 14 18:48 grub-initrd-fallback.service -> /lib/systemd/system/grub-initrd-fallback.service

lrwxrwxrwx 1 root root 38  3月 14 18:48 irqbalance.service -> /lib/systemd/system/irqbalance.service

lrwxrwxrwx 1 root root 38  3月 14 18:48 kerneloops.service -> /lib/systemd/system/kerneloops.service

lrwxrwxrwx 1 root root 38  3月 14 18:48 lm-sensors.service -> /lib/systemd/system/lm-sensors.service

lrwxrwxrwx 1 root root 47  3月 14 18:48 networkd-dispatcher.service -> /lib/systemd/system/networkd-dispatcher.service

lrwxrwxrwx 1 root root 36  3月 14 18:48 ondemand.service -> /lib/systemd/system/ondemand.service

lrwxrwxrwx 1 root root 36  3月 14 18:48 pppd-dns.service -> /lib/systemd/system/pppd-dns.service

lrwxrwxrwx 1 root root 36  3月 14 18:48 remote-fs.target -> /lib/systemd/system/remote-fs.target

lrwxrwxrwx 1 root root 33  3月 14 18:48 rsync.service -> /lib/systemd/system/rsync.service

lrwxrwxrwx 1 root root 35  3月 14 18:48 rsyslog.service -> /lib/systemd/system/rsyslog.service

lrwxrwxrwx 1 root root 41  3月 14 18:48 secureboot-db.service -> /lib/systemd/system/secureboot-db.service

lrwxrwxrwx 1 root root 52  3月 14 19:04 snapd.aa-prompt-listener.service -> /lib/systemd/system/snapd.aa-prompt-listener.service

lrwxrwxrwx 1 root root 42  3月 14 18:48 snapd.apparmor.service -> /lib/systemd/system/snapd.apparmor.service

lrwxrwxrwx 1 root root 44  3月 14 18:48 snapd.autoimport.service -> /lib/systemd/system/snapd.autoimport.service

lrwxrwxrwx 1 root root 44  3月 14 18:48 snapd.core-fixup.service -> /lib/systemd/system/snapd.core-fixup.service

lrwxrwxrwx 1 root root 58  3月 14 18:48 snapd.recovery-chooser-trigger.service -> /lib/systemd/system/snapd.recovery-chooser-trigger.service

lrwxrwxrwx 1 root root 40  3月 14 18:48 snapd.seeded.service -> /lib/systemd/system/snapd.seeded.service

lrwxrwxrwx 1 root root 33  3月 14 18:48 snapd.service -> /lib/systemd/system/snapd.service

lrwxrwxrwx 1 root root 31  3月 14 19:21 ssh.service -> /lib/systemd/system/ssh.service

lrwxrwxrwx 1 root root 44  3月 14 18:48 systemd-resolved.service -> /lib/systemd/system/systemd-resolved.service

lrwxrwxrwx 1 root root 36  3月 14 18:48 thermald.service -> /lib/systemd/system/thermald.service

lrwxrwxrwx 1 root root 31  3月 14 19:04 tlp.service -> /lib/systemd/system/tlp.service

lrwxrwxrwx 1 root root 42  3月 14 18:48 ua-reboot-cmds.service -> /lib/systemd/system/ua-reboot-cmds.service

lrwxrwxrwx 1 root root 44  3月 14 18:48 ubuntu-advantage.service -> /lib/systemd/system/ubuntu-advantage.service

lrwxrwxrwx 1 root root 31  3月 14 18:48 ufw.service -> /lib/systemd/system/ufw.service

lrwxrwxrwx 1 root root 47  3月 14 18:48 unattended-upgrades.service -> /lib/systemd/system/unattended-upgrades.service

lrwxrwxrwx 1 root root 36  3月 14 18:48 whoopsie.service -> /lib/systemd/system/whoopsie.service

lrwxrwxrwx 1 root root 42  3月 14 18:48 wpa_supplicant.service -> /lib/systemd/system/wpa_supplicant.service

lrwxrwxrwx 1 root root 34  3月 14 20:14 x11vnc.service -> /etc/systemd/system/x11vnc.service


ちゃんと一番最後にいる。

ここで気付いたのですが,先ほどつくったx11vnc.serviceファイルは/etcじゃなくて/libの下に作るべきだったのかもしれません。










2023年2月10日金曜日

Pythonをつかった実験データのリアルタイムな可視化にはpy-gnuplotがよいか

今までGtk+-2.0,gthread-2.0とCで書いていたGPIBを使った測定プログラム,さすがに時代遅れ感が否めないのでGtk+-3.0に書き換えました。

どうせ書き換えるならPythonにしてしまえばいいのですが,細かいことが気になってなかなか踏み切ることができずにいます。


その一つがリアルタイムグラフ表示。


Pythonでグラフといえばmatplotlibなのですが,いまいち遅い。

データ点がふえてきたときに負荷が大きくなる気がしています。

点が増えるたびにnumpyでいちいち丸ごとデータファイルから配列をつくって,プロットしたら測定して。。。を同じプロセスの中でやったら,測定まで遅くならないか心配で。


その点,今はCからパイプでgnuplotを呼び出して,別プロセスでグラフを書かせているので,たとえグラフ処理が遅くなったとしても,測定は別プロセスの別スレッドで回っているので,影響は少ないかと思っています。


それをpythonでやるならsubprocessをimportしてPIPEでgnuplotを呼び出して同じことをすればいいのですが,先人の知恵がないかとぐぐっていると,どうやらGnuplot.pyとかpy-gnuplotとか,そういったパッケージがあることを見つけたので,試してみました。


Gnuplot.pyは古かったので,py-gnuplotをためすことに。

環境としては,macOS BigSurとxubuntu22.04。

それぞれPythonのバージョンは3.10.9と3.10.6。

まずは


     $ pip3 install py-gnuplot


でインストール。


% python3

Python 3.10.9 (main, Dec 15 2022, 18:33:08) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> from pygnuplot import gnuplot

>>> g=gnuplot.Gnuplot()

>>> g.cmd('plot sin(x)')

>>> g.cmd('set xlabel "Temperature [K]"')

>>> g.cmd('replot')

>>> 



g=gnuplot.Gnuplot()でgnuplotを起動して,g.cmd()でgnuplotに送りたいコマンドを送ると,gnuplotをコマンドラインでつかっているのとほとんど同じ感覚で使えます。

Pythonぽく使いたかったら,

>>> command='set ylabel "Resistance [Ohm]"'

>>> g.cmd(command)

>>> g.cmd('replot')

>>> 



のようにすることもできる。


>>> g.cmd('set xlabel font "Arial,20"')

>>> g.cmd('set ylabel font "Arial,20"')

>>> g.cmd('set xtic font "Arial,16"')

>>> g.cmd('set ytic font "Arial,16"')

>>> g.cmd('replot') 

>>>  

 


いくらでも調整できます。








2023年1月27日金曜日

Ubuntu20.04上でPyVISAをつかって測定器と通信

 環境はUbuntu 20 04.5

Python: 3.8.10

pip: 20.0.2

pip install pyvisaで実行しようとするも上手く動かない。

"Value Error: Could not locate a VISA implementation. Install either the IVI binary or pyvisa-py."

と言われる。どうやらpyvisa-pyを使わないといけない様子。

そこで言われた通り, pip install pyvisa-pyを実行してみる。

しかし,またimportまではできるものの,ResourceManagerを開こうとすると今度は

"NotImplementedError: Service discovery requires the zeroconf package to be installed."

と怒られる。

そこで素直にpip install zeroconf をして実行すると,今度は実行できるものの,以下のようにlist_resources()で大量の"libgpib: invalid descriptor"というエラーが。。。


しかし,サポートページによると,


とのことだったので,気にせず実行してみたところ大丈夫でした。



2023年1月16日月曜日

Ubuntu20.04(正確にはxubuntu)でGPIB通信

 何度もやっているのでさらっとできると思い込んでいましたが,なんだかんだで5時間くらいかかってしまいました。


環境: Ubuntu 20.0405 LTS

GPIBアダプタ: NI USB HS+

まず,linux-gpibパッケージをインストール。

現時点でのバージョンはlinux-gpib-4.3.5。

ダウンロードして解凍すると,いままでと様子がちがう。。。。

新たにlinux-gpib-kernel−4.3.5.tar.gzとlinux-gpib-user-4.3.5.tar.gzという二つのファイルが現れた。


なんじゃこれと思いながら,まずは両方解凍。

READMEやらなにやら読むこと数分。

どうやらkernel関係のモジュールをmakeしたあとでuser以下の設定ファイル類をインストールするという手順らしい。

まずはkernel。

こちらは単にmakeしてsudo make installでオッケー。

次にuser。

linux-gpib-user-4.3.5ディレクトリに移動し,


    $ ./configure --sysconfdir=/etc

    $ make

    $sudo make install


で完了。

次に,設定ファイル/etc/gpib.confを編集。

変えたのは一箇所だけ。

minor=0の次の行をboard_type = "ni_usb_b"になおすだけ。

ここにどんなtypeを入れればいいかは公式サイトに書いてある。


つづいて,groupの設定。

$ sudo groupadd gpib

でグループを作り,/etc/groupの最後の行に追加されたgpibの部分に以下のように自分のuser名を入れるだけ。

gpib:x:1001:<ユーザー名>

ここまでできたらシステムを再起動。

再起動後に,

$ sudo /usr/local/sbin/gpib_config

を実行する。

これはどうやら私の環境では毎回やらないとダメかもしれない。

udevの設定がうまくできればやらなくていいはず。

これで完成。


2023/03/15追記

上の手順の最後,

$ sudo /sbin/ldconfig

を忘れると,

error while loading shared libraries: libgpib.so.0: cannot open shared object file: No such file or directory

とか言われます。

2022年12月6日火曜日

Apple siliconのNI488.2ドライバが一向に開発される気配がないのでLinuxにもどろうか(事前調査)

 2022年12月時点で,NIがmacOSはx84_64しかサポートしていないので,intel mac を新品で買えない現状では研究室の維持が難しくなってしまう。


さらに,最近のmacOSではウインドウをアクティブにしておかないと,処理が遅くなるようなので,これも測定に悪影響を及ぼす恐れがある。

うっかり測定用プログラムが走っているウインドウ以外をクリックしてしまったりすると,測定プログラムがアイドル状態とみなされてしまうのだろう。


LinuxからmacOSに移った理由の一つが,VNCでのぞいたり場合によっては測定条件を変更したりしたいから。

RDPやmacの画面共有(これは所詮VNCだけど)と違って,サーバ側をLinuxにしてVNC接続すると,別のXが立ち上がるようになっている(複数人で使えるように)。

しかし,測定で使用する場合,今まさにディスプレイで表示しているものをそのまま表示して欲しいので,それではちょっと困る。


しかし!最近救世主のようなVNCサーバに出会えた。

X11VNCとかいうやつらしい。

VNC用のパスワードを発行して,現在デスクトップで表示されているものをそのまま共有できるらしい。

そこらへんにころがっているちょっと古いDOS/V機で十分いける!


そこで,ひさびさにLinux-GPIBのウェブサイトを覗いてみる。

すると,

The 4.x.x and later series kernels are also supported by the packages in the linux-gpib for 3.xx and 2.6.x kernels folder.
The latest stable release (linux-gpib-4.3.5) has been tested on linux version 5.19.0-rc7 from kernel.org 

と書いてある。

先日入れたxubuntu22.04のカーネルを調べるために,uname -rしてみると,5.15.0-56-genericとのこと。


条件的には大丈夫そう。

でもなるべくコンダラひきたくない。


これも続きは後日。