@@ -96,9 +96,11 @@ Table: U2751A固有SCPIコマンド実装ステータス {#tbl:u2751a-commands}
96
96
SCPIコマンドを受け取ったあとの処理はだいたい以下のような感じです。例として、ホストから` ROUTe:CLOSe (@101:103)<CR><LF> ` が送られてきた場合の
97
97
処理を説明します。
98
98
99
+ なお、処理途中でエラーが起きると残りの処理に移行することなく中断し、標準入力を待つ状態に戻ります。
100
+
99
101
#### 1.標準入力で1行取り込んだあとセミコロンで区切り、最初の要素だけをパース処理に回す (main.py) {-}
100
102
101
- [ ] ( micropython/main.py ) {.listingtable nocaption=true from=22 #lst: readline-parse .python}
103
+ [ ] ( micropython/main.py ) {.listingtable from=22 #lst: readline-parse .python}
102
104
103
105
ファイルの先頭で` gets = sys.stdin.readline ` としてエイリアスを宣言しておいて、無限ループ内の` line = gets().strip() ` で
104
106
標準入力から1行取り込んだのち空白文字を切り落とします。` line ` の文字列長が0より大きければパース処理に回します。
@@ -107,7 +109,7 @@ SCPIコマンドを受け取ったあとの処理はだいたい以下のよう
107
109
108
110
#### 2.パラメータ付きコマンドのことを考慮して空白とコロンで切り分ける(MicroScpiDevice.py) {-}
109
111
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}
111
113
112
114
U2751Aではわずか2種類ですが、一部コマンドはパラメータを受けることができます。コマンドとパラメータは空白で区分けされます。
113
115
` mini_lexer() ` がこの部分の処理を行います。最初の空白の直前までをコマンド文字列、残り全部をパラメータ文字列と考えます。
@@ -119,7 +121,7 @@ U2751Aではわずか2種類ですが、一部コマンドはパラメータを
119
121
120
122
#### 3.要素数が合致するコマンドに候補を絞り込む(MicroScpiDevice.py) {-}
121
123
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}
123
125
124
126
` mini_lexer() ` に返されたコマンド文字列のリストの要素数と一致する登録済コマンドを抽出します。コマンドがクエリかどうかは
125
127
リストの最後の要素が"?"で終わっているかどうかで判定します。
@@ -129,9 +131,13 @@ U2751Aではわずか2種類ですが、一部コマンドはパラメータを
129
131
130
132
``` .python
131
133
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
+ ),
133
137
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
+ ),
135
141
query=False, callback=cb_relay_open)
136
142
]
137
143
```
@@ -140,22 +146,22 @@ length_matched = [
140
146
141
147
#### 4.すべてのコマンド文字列が一致した場合はコールバック関数を呼び出す(MicroScpiDevice.py) {-}
142
148
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}
144
150
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}
146
152
147
153
` length_matched ` の各` ScpiCommand ` アイテムについて` keywords ` に登録された` ScpiKeyword ` の全てにマッチするかを調べます。
148
154
全てにマッチする最初の` ScpiCommand ` アイテムに登録されたコールバック関数を呼び出します。一つもマッチがない場合はエラーになります。
149
155
コールバック関数は引数にパラメタ文字列とクエリフラグを受け取ります。
150
156
151
157
#### 5.コールバック関数内でパラメタ文字列のパースやクエリに返答するなどを含む最終的な処理をする(EMU2751A.py) {-}
152
158
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}
154
160
155
161
` ROUTe:CLOSe ` コマンドに割り当てられたコールバック関数` cb_relay_close() ` を呼び出します。内部で` channel_parser() ` を
156
162
呼び出してパラメタ文字列をパースします。
157
163
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}
159
165
160
166
` param ` が文字列でない場合・文字列の先頭と末尾が期待どおりでない場合にはエラーになります。
161
167
@@ -189,25 +195,31 @@ SCPIコマンドを構成するキーワードの定義クラスです。候補
189
195
190
196
SCPIコマンドの定義クラスです。` ScpiKeyword ` のタプルとクエリコマンドを表すフラグ、マッチしたときのコールバック関数へのポインタを登録します。
191
197
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 }
193
199
194
200
## MicroScpiDeviceクラス
195
201
196
- SCPIデバイスの定義クラスです。` mini_lexer() ` がコマンド文字列の分解処理、` parse_and_process() ` がコマンドの走査とコールバック 関数の
197
- 呼び出しを行います。
202
+ SCPIデバイスの定義クラスです。` mini_lexer() ` がコマンド文字列の分解処理、` parse_and_process() ` がコマンドの走査とコールバック関数の
203
+ 呼び出しを行います。「何もしない」コールバック関数として ` cb_do_nothing() ` を用意してあります。
198
204
199
- [ MicroScpiDeviceクラス] ( micropython/MicroScpiDevice.py ) {.listingtable .python from=47 #lst: microscpidevice-class }
205
+ [ MicroScpiDeviceクラス] ( micropython/MicroScpiDevice.py ) {.listingtable .python from=52 #lst: microscpidevice-class }
200
206
201
207
# EMU2751Aモジュール
202
208
203
209
## CrossBarsクラス
204
210
205
- スイッチマトリクスの接点データ管理クラスです。
211
+ スイッチマトリクスの接点データ管理クラスです。接点の指定が単数のときは` single ` に、複数のときは` start ` または` end ` および` range ` に値が入ります。
212
+ ` update() ` 関数は、` single ` /` start ` /` end ` /` range ` を予め設定された最小値・最大値の範囲に丸めたCrossBarオブジェクトを返します。
213
+ 本来はエラーを出すべきですが。
206
214
207
215
[ CrossBarsクラス] ( micropython/EMU2751A.py ) {.listingtable .python from=33 to=76 #lst: crossbars-class }
208
216
209
217
## EMU2751Aクラス
210
218
219
+ EMU2751AはMicroScpiDeviceを継承した、U2751Aエミュレーションのためのクラスです。U2751A固有のSCPIコマンドに応じたScpiCommandオブジェクトと
220
+ コールバック関数を用意するのが主な役目です。はじめにキーワードを登録し(` kw_* ` )、` __init__() ` の中でScpiCommandオブジェクトを定義します。
221
+ [ @tbl : ieee488-commands ] と[ @tbl : u2751a-commands ] で実装済みでないものは、コールバック関数に` cb_do_nothing() ` を指定しています。
222
+
211
223
[ EMU2751Aクラス] ( micropython/EMU2751A.py ) {.listingtable .python from=78 #lst: emu2751a-class }
212
224
213
225
# #include "extra_libs.md"
@@ -217,3 +229,4 @@ SCPIデバイスの定義クラスです。`mini_lexer()`がコマンド文字
217
229
- タルコフのワイプ・パッチ13に間に合うように頑張って書きましたが、間に合いませんでした。今回も前日印刷&trade ; です(12月29日)
218
230
- 本当はForgeFPGA試食本も書きたかったけどこっちの筆が進まんくて間に合わんかったすまん
219
231
- ライブラリの設計はラズピコのメモリ量に頼っている部分があるので、ほかのMicroPythonなマイコンに移植できるかはやってみないとわかりません
232
+ -
0 commit comments