Changes between Initial Version and Version 1 of epics/streamdevice/tips_and_tricks


Ignore:
Timestamp:
09/04/14 09:58:01 (11 years ago)
Author:
Tetsuya Michikawa
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • epics/streamdevice/tips_and_tricks

    v1 v1  
     1= !StreamDevice Tips & Tricks =
     2
     3[http://epics.web.psi.ch/software/streamdevice/doc/ StreamDeviceのオンラインドキュメント]にある[http://epics.web.psi.ch/software/streamdevice/doc/tipsandtricks.html tips & tricks]は非常に有用なんですがいまいちわかり辛いので、多少解かりやすくなるように私なりに書き直してみようと思います。
     4
     5== たくさんの同じようなプロトコルがある ==
     6
     7INP,OUT fieldには引数を使うことができるので、このように書くことも可能。
     8
     9{{{
     10field (OUT, "@protocolfile protocol(arg1,arg2,arg3) bus")
     11}}}
     12
     13プロトコルファイル内では 引数に数値(バイナリ)を設定したい場合には'''{{{$1 $2 $3}}}'''、文字列を設定する場合には'''{{{"\$1 \$2 \$3"}}}'''と記述する。
     14
     15=== 例1(文字列を設定) ===
     16 * db file
     17 {{{
     18field (OUT, "@motor.proto moveaxis(X) motor1")
     19 }}}
     20
     21 * protocol file
     22 {{{
     23moveaxis {
     24  out "move\$1 %.6f";
     25}
     26 }}}
     27
     28 この例では、'''{{{\$1}}}'''が文字列'''{{{X}}}'''で置き換わり
     29
     30 {{{
     31moveaxis {
     32  out "moveX %.6f";
     33}
     34 }}}
     35
     36 と、同じ意味になる。
     37
     38
     39=== 例2(数値を設定) ===
     40 * db file
     41 {{{
     42field (INP, "@vacuumgauge.proto readpressure(0x84) gauge3")
     43 }}}
     44
     45 * protocol file
     46 {{{
     47readpressure {
     48    out 0x02 0x00 $1;
     49    in 0x82 0x00 $1 "%2r";
     50}
     51 }}}
     52
     53 この例では、引数 '''{{{0x84}}}''' が '''{{{$1}}}''' に設定されるので、
     54
     55 {{{
     56readpressure {
     57    out 0x02 0x00 0x84;
     58    in 0x82 0x00 0x84 "%2r";
     59}
     60 }}}
     61
     62 となる。
     63
     64== デバイスが要らないデータをつけて送ってくる ==
     65
     66 I/O intr処理で送られてきた文字列と同じ場合だけ処理する。(別にI/O intr処理だけではないが例として)
     67
     68 * db file
     69 {{{
     70record (ai, "$(RECORD)") {
     71  field (DTYP, "stream")
     72  field (INP, "@$(DEVICETYPE).proto read $(BUS)")
     73  field (SCAN, "I/O Intr")
     74}
     75 }}}
     76
     77 * protocol file
     78 {{{
     79read {
     80    in "new value = %f";
     81}
     82 }}}
     83
     84 この場合、空白も含めてまったく同じ文字列じゃないと処理しないので注意。
     85
     86
     87== 複数行のデータを送ってくる ==
     88
     89 例として、こんな文字列を送ってくるデバイスだとする。
     90
     91 {{{
     92Here is the value:
     933.1415
     94 }}}
     95
     96 その場合、'''{{{in}}}'''を複数記述すればいい。
     97
     98 * protocol file
     99 {{{
     100read_value {
     101    in "Here is the value:";
     102    in "%f";
     103}
     104 }}}