LabRAD とは
https://web.physics.ucsb.edu/~martinisgroup/software.shtml
マルチニスのグループが作ったソフトウェア。実験室での機器操作を自動化するらしいが、いまひとつ、ありがたみがわからない。ただの rpc と、名前解決だよね。
twisted という、非同期 rpc フレームワークを使う。
https://twistedmatrix.com/trac/
古いチュートリアルとプロジェクトページ
https://sourceforge.net/p/labrad/wiki/Home/
プロジェクトは github に移った。https://github.com/labrad
Delphi で書かれたマネージャは、互換性がなくなった。こちらのチュートリアルは、ほぼ途中で放棄されているし、 gui が qt4 を使っているので tutorial/sampleWidget.py などは2021年の今は動かない。
scalabrad を、 centos8 で動かす。
https://github.com/labrad/scalabrad/releases/tag/v0.8.3
java 仮想マシンで動くので、あっさり上がった。
[kanda@centos8 ~]$ /opt/scalabrad-0.8.3/bin/labrad
11:51:19.977 [main] INFO org.labrad.manager.Manager$ - registry location: /home/kanda/.labrad/registry.sqlite, format=sqlite
11:51:20.232 [main] INFO org.labrad.crypto.Certs$ - Generating self-signed certificate for host 'centos8'. certFile=/home/kanda/.labrad/manager/certs/centos8.cert, keyFile=/home/kanda/.labrad/manager/keys/centos8.key
11:51:20.492 [main] INFO org.labrad.crypto.Certs$ - Generating self-signed certificate for host 'localhost'. certFile=/home/kanda/.labrad/manager/certs/localhost.cert, keyFile=/home/kanda/.labrad/manager/keys/localhost.key
11:51:20.604 [main] INFO org.labrad.manager.Manager$ - localhost: sha1=BE:60:66:E0:8D:1E:8C:AF:24:51:0C:CE:7D:84:C6:20:EB:32:47:BF
11:51:20.607 [main] INFO org.labrad.manager.Manager$ - centos8: sha1=36:DA:A8:7D:A7:ED:81:78:E1:92:7A:67:45:1F:10:4B:34:B7:F0:A2
11:51:21.610 [main] INFO org.labrad.manager.MultiheadServer - managers in registry:
11:51:21.899 [main] INFO org.labrad.manager.MultiheadServer - managers in registry:
11:51:21.952 [main] INFO org.labrad.manager.Listener - now accepting labrad connections: port=7682, tlsPolicy=STARTTLS
11:51:21.952 [main] INFO org.labrad.manager.Listener - now accepting labrad connections: port=7643, tlsPolicy=ON
ウェブインタフェースを動かす。
https://github.com/labrad/scalabrad-web
バイナリのリンクが切れている。うーん。
https://github.com/labrad/pylabrad/wiki
>>> import labrad
>>> cxn = labrad.connect('localhost')
Enter username, or blank for the global user (localhost:7682):
Enter LabRAD password (localhost:7682):
>>> cxn
LabRAD Client: 'Python Client (centos8)' on localhost:7682
Available servers:
auth
manager
registry
認証なしでも見えるところはある。じゃなくて、デフォルトが、グローバルユーザで、パスワードは空文字だった。
>>> cxn['manager']
LabRAD Server: Manager (ID=1)
Provides basic support for all labrad connections, including discovery of other servers and lookup of metadata about them.
Settings:
close_connection
..
>>> cxn['manager'].data_to_string([(1, 'This'), (2, 'is')])
'[(+1, "This"), (+2, "is")]'
.labrad の下に sqlite データベースと、 tls キーなどができている。
[kanda@centos8 .labrad]$ sqlite3 -readonly registry.sqlite
sqlite> .tables
dirs keys
sqlite> select * from dirs;
1||
2|1|Servers
3|2|Registry
4|3|Multihead
5|2|Auth
6|5|Multihead
https://twistedmatrix.com/trac/
非同期 rpc だそうな
[kanda@centos8 ~]$ python3 twistedEcho.py
[kanda@centos8 ~]$ telnet localhost 1234
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Hello
Hello
https://github.com/labrad/pylabrad/wiki/Writing-Servers
このへんのチュートリアルと、 test server を読むと、なんとかわかる。
initServer は、yield None しないとだめらしい。
[kanda@centos8 servers]$ python3 myserver.py
2021-10-22 22:00:07+0900 [-] Log opened.
Enter LabRAD password (localhost:7682):
2021-10-22 22:00:08+0900 [LabradProtocol,client] My Server starting...
2021-10-22 22:00:08+0900 [LabradProtocol,client] My Server now serving
>>> cxn = labrad.connect('localhost')
>>> cxn
LabRAD Client: 'Python Client (centos8)' on localhost:7682
Available servers:
auth
manager
my_server <= 見えた。
registry
>>> ms = cxn.my_server
>>> resp = ms.is_true("hello")
>>> resp
True
https://github.com/Kanda-Motohiro/labradapp
10秒後に、 echo する。
実行例
[kanda@centos8 labradapp]$ python3 client.py
Enter username, or blank for the global user (localhost:7682):
Enter LabRAD password (localhost:7682):
hello from 73850 at Sat Oct 23 11:55:29 2021
hello from 73884 at Sat Oct 23 11:55:29 2021
world from 73850 at Sat Oct 23 11:55:39 2021
world from 73884 at Sat Oct 23 11:55:39 2021
flask ウェブサーバから、labrad クライアントを呼ぶ。
下図は、3つの echo サーバを上げて、同期と非同期でたたいたところ。
あかん。非同期の echo を呼ぶと、同期の方も、応答が返らなくなる。fetch の使い方が違うのか?
flask でシングルスレッドで待つためだった。