= !StreamDevice Tips & Tricks = [http://epics.web.psi.ch/software/streamdevice/doc/ StreamDeviceのオンラインドキュメント]にある[http://epics.web.psi.ch/software/streamdevice/doc/tipsandtricks.html tips & tricks]は非常に有用なんですがいまいちわかり辛いので、多少解かりやすくなるように私なりに書き直してみようと思います。 == たくさんの同じようなプロトコルがある == INP,OUT fieldには引数を使うことができるので、このように書くことも可能。 {{{ field (OUT, "@protocolfile protocol(arg1,arg2,arg3) bus") }}} プロトコルファイル内では 引数に数値(バイナリ)を設定したい場合には'''{{{$1 $2 $3}}}'''、文字列を設定する場合には'''{{{"\$1 \$2 \$3"}}}'''と記述する。 === 例1(文字列を設定) === * db file {{{ field (OUT, "@motor.proto moveaxis(X) motor1") }}} * protocol file {{{ moveaxis { out "move\$1 %.6f"; } }}} この例では、'''{{{\$1}}}'''が文字列'''{{{X}}}'''で置き換わり {{{ moveaxis { out "moveX %.6f"; } }}} と、同じ意味になる。 === 例2(数値を設定) === * db file {{{ field (INP, "@vacuumgauge.proto readpressure(0x84) gauge3") }}} * protocol file {{{ readpressure { out 0x02 0x00 $1; in 0x82 0x00 $1 "%2r"; } }}} この例では、引数 '''{{{0x84}}}''' が '''{{{$1}}}''' に設定されるので、 {{{ readpressure { out 0x02 0x00 0x84; in 0x82 0x00 0x84 "%2r"; } }}} となる。 == デバイスが要らないデータをつけて送ってくる == I/O intr処理で送られてきた文字列と同じ場合だけ処理する。(別にI/O intr処理だけではないが例として) * db file {{{ record (ai, "$(RECORD)") { field (DTYP, "stream") field (INP, "@$(DEVICETYPE).proto read $(BUS)") field (SCAN, "I/O Intr") } }}} * protocol file {{{ read { in "new value = %f"; } }}} この場合、空白も含めてまったく同じ文字列じゃないと処理しないので注意。 == 複数行のデータを送ってくる == 例として、こんな文字列を送ってくるデバイスだとする。 {{{ Here is the value: 3.1415 }}} その場合、'''{{{in}}}'''を複数記述すればいい。 * protocol file {{{ read_value { in "Here is the value:"; in "%f"; } }}}