2026年1月20日火曜日

Parallels Clientを久しぶりにつかってみた

 バージョン21.0.0をApp Storeからダウンロード。

windowsに繋ぎたいので"新しい接続"から設定しようと思ったのですが,何を入力すればいいのやら。。。IPアドレスか???


結局,スクリーンショットの黄色い丸のところから,『代替RDP接続を設定』にいけばいいだけでした。

「代替」ってワードのせいでここをクリックしていいのかまよってしまったという話でした。






2025年9月18日木曜日

linux-gpibパッケージをインストールした際にpython-bindingがインストールされていればPyVISAは不要なはず。

 題目の通り。

前回のような手順できちんとlinux-gpibパッケージでpython-bindingがインストールできていれば以下で行けるはず。


  1. import gpib
  2. import time
  3. from datetime import datetime
  4. device = gpib.dev(0, 5)
  5. gpib.timeout(device, gpib.T10s)
  6. log_file = "measurement_log.csv"
  7. with open(log_file, "w") as f:
  8.     f.write("Timestamp,Voltage\n")
  9. try:
  10.     while True:
  11.         gpib.write(device, "MEAS:VOLT?\n")
  12.         response = gpib.read(device, 100).decode().strip()
  13.         timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  14.         with open(log_file, "a") as f:
  15.             f.write(f"{timestamp},{response}\n")
  16.         print(f"{timestamp} -> {response} V")
  17.         time.sleep(1)
  18. except KeyboardInterrupt:
  19.     print("測定を中断しました。")
  20. finally:
  21.     gpib.close(device)
  22.     print("GPIBデバイスを閉じました。")


12行目で.decode().strip()をつけないかたち,すなわち


gpib.write(device."*IDN?\n")
print(gpib.read(device, 100))

としてしまうと,結果が,

b'HEWLETT-PACKARD,34401A,0,1.0\n'

みたいになってしまう。なので,

print(gpib.read(device, 100).decode().strip())

とすれば

HEWLETT-PACKARD,34401A,0,1.0
と返ってくる。

よく使う関数をまとめておく。

関数説明
gpib.dev(board_index, pad)デバイスハンドルを取得
gpib.write(device, command)コマンド送信
gpib.read(device, length)応答読み取り
gpib.close(device)デバイスを閉じる
gpib.timeout(device, value)タイムアウト設定(例: gpib.T10s)

2025年8月11日月曜日

xubuntu24でlinux-GPIB(4.3.7)をPython3(3.12.3)から使う際にてこずったこと(python バインディングが重要!)

 まっさらのxubuntu24にgitでlinux-gpibの4.3.7をインストールしたのですが,そのままではなんとpythonから見えないというトラブル発生。

症状としては,

$ python3

Python 3.12.3 (main, Jun 18 2025, 17:59:45) [GCC 13.3.0] on linux

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

>>> import pyvisa as visa

>>> rm=visa.ResourceManager()

>>> print(rm.list_resources())

()

>>> 

のように,リソースがなにもみえない。

ここでそもそもいままでPyVISAがうまく動いてくれていたことに感謝しながら,pyvisaがどの様に計測器を検出しているかを調べてみた。

すると,pyvisaは,pyvisa-pyというバックエンドを明示的に指定しないといけないらしい。

(今までそんなことなかった気がする)

ResourceManagerについて調べてみる。


>>> print(rm)

Resource Manager of Visa Library at /usr/lib/x86_64-linux-gnu/libvisa.so.0.0.0

>>> 

なんか良さげな感じの返事がきたのですが,これではダメらしい。

明示的にpyvisa-pyを指定するためには,'@py'を指定するらしい。

$ python3

Python 3.12.3 (main, Jun 18 2025, 17:59:45) [GCC 13.3.0] on linux

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

>>> import pyvisa as visa

>>> rm=visa.ResourceManager('@py')

>>> print(rm)

Resource Manager of Visa Library at py

>>> 

このように表示されたらOK。

ところが私の環境では,これでもlist_resources()でGPIBが出てこない。

そこで,linux-GPIBパッケージのpythonバインディングがうまくいっていない可能性を疑う。

pythonバインディングがうまく作成されていれば,importできるはず。

$ python3

Python 3.12.3 (main, Jun 18 2025, 17:59:45) [GCC 13.3.0] on linux

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

>>> import  gpib

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

ModuleNotFoundError: No module named 'gpib'

やはり。。。

linux-gpib-users/language/python以下にあるっぽいので,そこを覗いてみる。

~/Downloads/linux-gpib-git/linux-gpib-user/language/python$ ls

Gpib.py   Makefile.am  README       gpibtest.py  srq_board.py

Makefile  Makefile.in  gpibinter.c  setup.py     srq_device.py

ここにあたりをつけて,READMEを読んでみると,

This is a python GPIB interface to use gpib library calls from python language.

(Quick hacked)


27 January 2004 -- added functions gpib.readbin() and gpib.writebin(), as well

as variables gpib.ibsta() and gpib.ibcnt(). -- John Ackermann <jra@febo.com>


Installation:


'make' then 'make install'


とのことだったので,makeしてみたが,どうやらpython3-devがらみで足りないものがあった模様。

python3-devとpython3-setuptoolsをaptでインストールしたら無事にmakeとmake installができた。

その後,実は

$ sudo python3 setup.py install

という処理が必要。

$ python3

Python 3.12.3 (main, Jun 18 2025, 17:59:45) [GCC 13.3.0] on linux

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

>>> import pyvisa as visa

>>> rm = visa.ResourceManager('@py')

>>> ls330=rm.open_resource('GPIB0::16::INSTR')

>>> ls330.write("*IDN?")

7

>>> ls330.read()

'LSCI,MODEL330,0,061694\r\n'

>>> ls330.close()

>>> 

思ったより重いコンダラだった。




MacからVisual Studio Codeを使ってlinuxにSSH接続してXも転送しながら開発(メモ)

 Linux側にVSCodeをインストールするときは,公式サイトの方法を参考にすると良さそう。

MacのVSCodeからlinuxに接続して,Xも通したい時は,まず当然ですがMacとlinuxでsshができる様に,linux側に

$ sudo apt install openssh-server

でsshサーバをインストールし,

$ systemctl enable ssh

してsshが起動時に有効になる様にしてから,XQuartzをインストールしてあるmacから一度

$ ssh -X <ユーザ名>@<接続先のIPアドレス>

で接続を試す。

それから,MacのVSCodeでRemote-SSHをインストールし,以下の様に設定する。

Command + Shift + P

して,

Remote-SSH: Open SSH Configuration File ...

を選んで,

/Users/<自分のユーザ名>/.ssh/config

を選択し,以下の様に記述すればオッケー。


Host <接続先のIPアドレス>
HostName <接続先のホスト名>
ForwardX11 yes
ForwardX11Trusted yes
User <接続先のユーザ名>

gpibドライバをセットアップし直し(xubuntu 24.04)

測定器が増えてきたので別のラップトップにGPIBのセッティングをしなおした。

公式サイトからGitで取得。

$ git clone https://git.code.sf.net/p/linux-gpib/git linux-gpib-git

linux-gpib-gitフォルダ以下のlinux-gpib-userとlinux-gpib-kernelを指示通りコンパイルしインストール。

(-userの方は./configure の前に ./bootstrapが必要になった。)


設定ファイル/etc/gpib.confの編集。

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

つづいて,groupの設定。

$ sudo groupadd gpib

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

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

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

再起動後に,

$ sudo /usr/local/sbin/gpib_config

を実行する。

しかしここでトラブル。

いつものような

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

が出てきてうまくいかない。
modplobeしてもきちんとカーネルモジュールはできているのに。。。

結局,/usr/local/lib/libgpib.so.0を/lib/にシンボリックリンクを貼って解決。

ちなみに,上記作業中,autotoolsとflexとbisonをaptでインストールしないとbuildできなかった。


それから,


gtk-3.0-dev

pkg-config


もaptでインストールした。 

2024年7月22日月曜日

latexのphysicsパッケージ

 いままで一生懸命(というほどでもないけど)\dfrac{\mathrm{d}}{\mathrm{d}t}とかやっていたのですが,\dv{t}一発でいくのですね。。。。


基本的には,\dv[n]{f}{x}のような使い方。

偏微分は\pdv[n]{f}{x}のように。

\dv{x}()も便利そう。

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') 

>>>  

 


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