Skip to content

Commit e73074e

Browse files
committed
update TITLE.md, add QRcode.png
1 parent 5a3b4f8 commit e73074e

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

images/QRcode.png

564 Bytes
Loading

markdown/TITLE.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ Table: U2751A固有SCPIコマンド実装ステータス {#tbl:u2751a-commands}
9696
SCPIコマンドを受け取ったあとの処理はだいたい以下のような感じです。例として、ホストから`ROUTe:CLOSe (@101:103)<CR><LF>`が送られてきた場合の
9797
処理を説明します。
9898

99+
なお、処理途中でエラーが起きると残りの処理に移行することなく中断し、標準入力を待つ状態に戻ります。
100+
99101
#### 1.標準入力で1行取り込んだあとセミコロンで区切り、最初の要素だけをパース処理に回す (main.py) {-}
100102

101-
[](micropython/main.py){.listingtable nocaption=true from=22 #lst:readline-parse .python}
103+
[](micropython/main.py){.listingtable from=22 #lst:readline-parse .python}
102104

103105
ファイルの先頭で`gets = sys.stdin.readline`としてエイリアスを宣言しておいて、無限ループ内の`line = gets().strip()`
104106
標準入力から1行取り込んだのち空白文字を切り落とします。`line`の文字列長が0より大きければパース処理に回します。
@@ -107,7 +109,7 @@ SCPIコマンドを受け取ったあとの処理はだいたい以下のよう
107109

108110
#### 2.パラメータ付きコマンドのことを考慮して空白とコロンで切り分ける(MicroScpiDevice.py) {-}
109111

110-
[](micropython/MicroScpiDevice.py){.listingtable nocaption=true from=48 to=65 #lst:split-command-parameter .python}
112+
[](micropython/MicroScpiDevice.py){.listingtable from=48 to=65 #lst:split-command-parameter .python}
111113

112114
U2751Aではわずか2種類ですが、一部コマンドはパラメータを受けることができます。コマンドとパラメータは空白で区分けされます。
113115
`mini_lexer()`がこの部分の処理を行います。最初の空白の直前までをコマンド文字列、残り全部をパラメータ文字列と考えます。
@@ -119,7 +121,7 @@ U2751Aではわずか2種類ですが、一部コマンドはパラメータを
119121

120122
#### 3.要素数が合致するコマンドに候補を絞り込む(MicroScpiDevice.py) {-}
121123

122-
[](micropython/MicroScpiDevice.py){.listingtable nocaption=true from=77 to=82 #lst:get-command-candidate .python}
124+
[](micropython/MicroScpiDevice.py){.listingtable from=77 to=82 #lst:get-command-candidate .python}
123125

124126
`mini_lexer()`に返されたコマンド文字列のリストの要素数と一致する登録済コマンドを抽出します。コマンドがクエリかどうかは
125127
リストの最後の要素が"?"で終わっているかどうかで判定します。
@@ -129,9 +131,13 @@ U2751Aではわずか2種類ですが、一部コマンドはパラメータを
129131

130132
``` .python
131133
length_matched = [
132-
ScpiCommand(keywords=(ScpiKeyword(long='ROUTe', short='ROUT'), ScpiKeyword(long='CLOSe', short='CLOS')),
134+
ScpiCommand(keywords=(ScpiKeyword(long='ROUTe', short='ROUT'),
135+
ScpiKeyword(long='CLOSe', short='CLOS')
136+
),
133137
query=False, callback=cb_relay_close),
134-
ScpiCommand(keywords=(ScpiKeyword(long='ROUTe', short='ROUT'), ScpiKeyword(long='OPEN', short='OPEN')),
138+
ScpiCommand(keywords=(ScpiKeyword(long='ROUTe', short='ROUT'),
139+
ScpiKeyword(long='OPEN', short='OPEN')
140+
),
135141
query=False, callback=cb_relay_open)
136142
]
137143
```
@@ -140,22 +146,22 @@ length_matched = [
140146

141147
#### 4.すべてのコマンド文字列が一致した場合はコールバック関数を呼び出す(MicroScpiDevice.py) {-}
142148

143-
[](micropython/MicroScpiDevice.py){.listingtable nocaption=true from=83 #lst:callback-when-all-matched .python}
149+
[](micropython/MicroScpiDevice.py){.listingtable from=83 #lst:callback-when-all-matched .python}
144150

145-
[](micropython/EMU2751A.py){.listingtable nocaption=true from=111 to=112 #lst:get-command-candidate .python}
151+
[](micropython/EMU2751A.py){.listingtable from=111 to=112 #lst:get-command-candidate .python}
146152

147153
`length_matched`の各`ScpiCommand`アイテムについて`keywords`に登録された`ScpiKeyword`の全てにマッチするかを調べます。
148154
全てにマッチする最初の`ScpiCommand`アイテムに登録されたコールバック関数を呼び出します。一つもマッチがない場合はエラーになります。
149155
コールバック関数は引数にパラメタ文字列とクエリフラグを受け取ります。
150156

151157
#### 5.コールバック関数内でパラメタ文字列のパースやクエリに返答するなどを含む最終的な処理をする(EMU2751A.py) {-}
152158

153-
[](micropython/EMU2751A.py){.listingtable nocaption=true from=172 to=186 #lst:callback-function .python}
159+
[](micropython/EMU2751A.py){.listingtable from=172 to=186 #lst:callback-function .python}
154160

155161
`ROUTe:CLOSe`コマンドに割り当てられたコールバック関数`cb_relay_close()`を呼び出します。内部で`channel_parser()`
156162
呼び出してパラメタ文字列をパースします。
157163

158-
[](micropython/EMU2751A.py){.listingtable nocaption=true from=145 to=171 #lst:parse-parameter-string .python}
164+
[](micropython/EMU2751A.py){.listingtable from=145 to=171 #lst:parse-parameter-string .python}
159165

160166
`param`が文字列でない場合・文字列の先頭と末尾が期待どおりでない場合にはエラーになります。
161167

@@ -189,25 +195,31 @@ SCPIコマンドを構成するキーワードの定義クラスです。候補
189195

190196
SCPIコマンドの定義クラスです。`ScpiKeyword`のタプルとクエリコマンドを表すフラグ、マッチしたときのコールバック関数へのポインタを登録します。
191197

192-
[ScpiCommandクラス](micropython/MicroScpiDevice.py){.listingtable .python from=33 to=42 #lst:scpicommand-class}
198+
[ScpiCommandクラス](micropython/MicroScpiDevice.py){.listingtable .python from=33 to=47 #lst:scpicommand-class}
193199

194200
## MicroScpiDeviceクラス
195201

196-
SCPIデバイスの定義クラスです。`mini_lexer()`がコマンド文字列の分解処理、`parse_and_process()`がコマンドの走査とコールバック 関数の
197-
呼び出しを行います。
202+
SCPIデバイスの定義クラスです。`mini_lexer()`がコマンド文字列の分解処理、`parse_and_process()`がコマンドの走査とコールバック関数の
203+
呼び出しを行います。「何もしない」コールバック関数として`cb_do_nothing()`を用意してあります。
198204

199-
[MicroScpiDeviceクラス](micropython/MicroScpiDevice.py){.listingtable .python from=47 #lst:microscpidevice-class}
205+
[MicroScpiDeviceクラス](micropython/MicroScpiDevice.py){.listingtable .python from=52 #lst:microscpidevice-class}
200206

201207
# EMU2751Aモジュール
202208

203209
## CrossBarsクラス
204210

205-
スイッチマトリクスの接点データ管理クラスです。
211+
スイッチマトリクスの接点データ管理クラスです。接点の指定が単数のときは`single`に、複数のときは`start`または`end`および`range`に値が入ります。
212+
`update()`関数は、`single`/`start`/`end`/`range`を予め設定された最小値・最大値の範囲に丸めたCrossBarオブジェクトを返します。
213+
本来はエラーを出すべきですが。
206214

207215
[CrossBarsクラス](micropython/EMU2751A.py){.listingtable .python from=33 to=76 #lst:crossbars-class}
208216

209217
## EMU2751Aクラス
210218

219+
EMU2751AはMicroScpiDeviceを継承した、U2751Aエミュレーションのためのクラスです。U2751A固有のSCPIコマンドに応じたScpiCommandオブジェクトと
220+
コールバック関数を用意するのが主な役目です。はじめにキーワードを登録し(`kw_*`)、`__init__()`の中でScpiCommandオブジェクトを定義します。
221+
[@tbl:ieee488-commands][@tbl:u2751a-commands]で実装済みでないものは、コールバック関数に`cb_do_nothing()`を指定しています。
222+
211223
[EMU2751Aクラス](micropython/EMU2751A.py){.listingtable .python from=78 #lst:emu2751a-class}
212224

213225
# #include "extra_libs.md"
@@ -217,3 +229,4 @@ SCPIデバイスの定義クラスです。`mini_lexer()`がコマンド文字
217229
- タルコフのワイプ・パッチ13に間に合うように頑張って書きましたが、間に合いませんでした。今回も前日印刷&trade;です(12月29日)
218230
- 本当はForgeFPGA試食本も書きたかったけどこっちの筆が進まんくて間に合わんかったすまん
219231
- ライブラリの設計はラズピコのメモリ量に頼っている部分があるので、ほかのMicroPythonなマイコンに移植できるかはやってみないとわかりません
232+
-

0 commit comments

Comments
 (0)