📄 c-wtx4.html
字号:
<dl class="margin"><dd><p class="Body"><a name="85603"> </a>Calling target routines is easier than spawning tasks from scratch, because the target server and agent provide support to simplify the process. The central command is <b class="tclProc">wtxFuncCall</b>, which spawns a task on the target and arranges for an event containing the return value to be generated when the task completes. For example, use <b class="routine"><i class="routine">sysClkRateGet</i></b><b>( )</b>to report the system clock rate:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85605"></b><tt class="output">wtxtcl> </tt><b>wtxFuncCall -int [symbol sysClkRateGet] </b><tt class="output">0x358908</tt><b></a></b></pre></dl><dd><p class="Body"><a name="85607"> </a>The call returns a <i class="term">call ID</i>, the ID of the task that is spawned to call the routine. In addition, the agent posts an event to the target server which can be viewed using <b class="tclProc">wtxEventGet</b>,<b class="tclProc"> listEvents</b> (see <a href="c-wtx4.html#85447"><i class="title">Generating and Retrieving Events</i></a>), or <b class="tclProc">eventPoll</b> (see <a href="c-wtx4.html#85429"><i class="title">Checking the Event Queue</i></a>), as shown in the following example:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85617"></b><tt class="output">wtxtcl> </tt><b>wtxEventGet </b><tt class="output">CALL_RETURN 0x358908 0x3c</tt><b></a></b></pre></dl><dd><p class="Body"><a name="85619"> </a>The event string includes both the call ID and the integer return value (0x3c = 60). </p><dd><p class="Body"><a name="85620"> </a>The next example calls <b class="routine"><i class="routine">taskDelay</i></b><b>( )</b> with a delay of 10 seconds (assuming the system clock rate is 60Hz) and then polls at the rate of 1 Hz (every 1000 milliseconds) waiting for the result.</p><dl class="margin"><dd><pre class="Code2"><b><a name="85621"></b><tt class="output">wtxtcl> </tt><b>wtxFuncCall -int [symbol taskDelay] 600 </b><tt class="output">wtxtcl> </tt><b>eventPoll 1000 </b><tt class="output">CALL_RETURN 0x358908 0 0 </tt><b></a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85624">4.4.13 Working With Multiple Connections</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85626"> </a>It is possible to maintain more than one target server connection at once with <b class="command">wtxtcl</b>. To make two connections, issue the <b class="tclProc"></b><b class="command">wtxToolAttach</b> command twice, each time saving the Tcl handle in a variable for convenience.</p><dl class="margin"><dd><pre class="Code2"><b><a name="85628"></b><tt class="output">wtxtcl> </tt><b>set h1 [wtxToolAttach vxsim7] </b><tt class="output">wtxtcl> </tt><b>set h2 [wtxToolAttach mv147] </b><tt class="output">wtxtcl> </tt><b>set h1 </b><tt class="output">vxsim7@aven wtxtcl> </tt><b>set h2 </b><tt class="output">mv147@aven</tt><b></a></b></pre></dl><dd><p class="Body"><a name="85634"> </a>The WTX Tcl API maintains a stack of handles. The most recently opened connection is at the top of the stack, so any WTX commands issued after entering the list of commands in the previous example go to <b class="symbol_lc">mv147</b>. To examine and manipulate the handle stack, use the <b class="tclProc">wtxHandle</b> procedure. With no arguments, it displays the stack (top item first). With an argument, it places the named handle at the top of the stack. Notice that the second command in the following example places <b class="symbol_lc">vxsim7</b> at the top of the stack; further WTX commands are directed there.</p><dl class="margin"><dd><pre class="Code2"><b><a name="85636"></b><tt class="output">wtxtcl> </tt><b>wtxHandle </b><tt class="output">mv147@aven vxsim7@aven wtxtcl> </tt><b>wtxHandle $h1 </b><tt class="output">vxsim7@aven mv147@aven</tt><b></a></b></pre></dl><dd><p class="Body"><a name="85640"> </a>You can also direct any WTX Tcl command to any connected handle without manipulating the stack. The generic <b class="operator">-hwtx</b> option, which takes a handle name argument, directs the WTX command to the named connection. For example, the following example shows a script which prints the BSP name of each connected target. Executing <b class="tclProc">wtxHandle</b> without arguments provides the list of connected targets, and running <b class="command">wtxTsInfoGet</b> with the <b class="operator">-hwtx</b> option queries the correct target. Output is directed to <b class="symbol_lc">stdout</b>.</p><dl class="margin"><dd><pre class="Code2"><b><a name="89752"></b><tt class="output">wtxtcl> </tt><b>foreach handle [wtxHandle] { set info [wtxTsInfoGet -hwtx $handle] puts stdout [lindex $info 4] } </b><tt class="output">SunOS 5.5.1 [sun4u] Motorola MVME2600 - MPC 603p</tt><b></a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="89758">4.4.14 Timeout Handling</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="89760"> </a>Three methods are available for adjusting timeout values. They are listed from the most general to the most specific.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85651">wtxTimeout </a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85652"> </a>This command affects all subsequent WTX requests. The specified value serves as the default for all commands that do not have a different value assigned.</p><dd><p class="Body"><a name="85653"> </a>To get the current timeout setting, issue the following command:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85654"></b><tt class="output">wtxtcl> </tt><b>wtxTimeout </b><tt class="output">30</tt><b></a></b></pre></dl><dd><p class="Body"><a name="85656"> </a>To set a new timeout value, issue the following command:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85657"></b><tt class="output">wtxtcl> </tt><b>wtxTimeout 120 </b><tt class="output">120</tt><b></a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85659">wtxCmdTimeout </a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85660"> </a>This array allows you to set a timeout for any WTX commands you choose. If the entry corresponding to a particular command is not set, the default timeout applies, unless the <b class="operator">-timeout</b> option is used when the command is issued.</p><dd><p class="Body"><a name="85661"> </a>To set up a timeout for all <b class="tclProc">wtxObjModuleLoad</b> commands, issue:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85662"></b><tt class="output">wtxtcl> </tt><b>set wtxCmdTimeout(wtxObjModuleLoad) 2400 </b><tt class="output">240</tt><b></a></b></pre></dl><dd><p class="Body"><a name="85664"> </a>All subsequent object module loads will use a timeout value of 240 seconds.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85665">-timeout </a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85666"> </a>All WTX Tcl commands that involve communicating with the target server can take a <b class="operator">-timeout</b> option. This option affects only the timeout setting for the specific command.</p><dl class="margin"><dd><pre class="Code2"><b><a name="85667"></b><tt class="output">wtxtcl> </tt><b>wtxSymFind -timeout 1 -name errno </b><tt class="output">errno 0x96b3c 0x9 0 0 ""</tt><b></a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85669">4.4.15 Error Handling</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85671"> </a>WTX Tcl has an error handling facility that is designed to take advantage of Tcl's own exception handling features. When a <b class="command">wtxtcl</b> request results in a WTX protocol error, the request generates a Tcl error. Tcl errors initiate a process called <i class="term">unwinding</i>. The procedure that invoked the offending <b class="command">wtxtcl</b> command stops executing, and immediately returns to its parent with the error code returned by the target server. If the parent was called by another procedure, it returns the error code to its parent, and so on. This process can continue indefinitely until the entire stack of procedure invocations is removed or the error is caught by an error handling routine. At each step, a descriptive message is appended to the global variable <b class="symbol_lc">errorInfo</b>. Printing this variable displays a backtrace showing the circumstances leading to the error.</p><dd><p class="Body"><a name="85673"> </a>The next example shows an error occurring in a nested context. A <b class="tclProc">wtxMemRead</b> call specifying an invalid address is embedded in a <b class="keyword">foreach</b> and a <b class="keyword">while</b> loop. When the error is returned, <b class="command">errorInfo</b> prints the value of the error messages.</p><dl class="margin"><dd><pre class="Code2"><b><a name="85674"></b><tt class="output">wtxtcl> </tt><b>foreach x {1 2 3} { while 1 { wtxMemRead 0xeeeeeeee 0x100 } } </b><tt class="output">Error: WTX Error 0x100ca (AGENT_MEM_ACCES_ERROR) wtxtcl> </tt><b>set errorInfo </b><tt class="output">WTX Error 0x100ca (AGENT_MEM_ACCES_ERROR) while executing "wtxMemRead 0xeeeeeeee 0x100" ("while" body line 2) invoked from within "while 1 { wtxMemRead 0xeeeeeeee 0x100 }" ("foreach" body line 2) invoked from within "foreach x {1 2 3} { while 1 { wtxMemRead 0xeeeeeeee 0x100 } }"</tt><b></a></b></pre></dl><dd><p class="Body"><a name="85696"> </a>Tcl's standard exception handling command, <b class="tclProc">catch</b>, can be used with WTX calls. Using <b class="tclProc">catch</b> interrupts the unwinding process, preventing errors from escaping to higher levels and allowing errors to be inspected and acted on.</p><dd><p class="Body"><a name="85697"> </a>While it is sometimes appropriate to examine each error individually, it is also common to take a specific action in response to a particular protocol error regardless of what command caused the error. In addition to the Tcl <b class="tclProc">catch</b> command, <b class="command">wtxtcl</b> provides a means to establish an error handling procedure.</p><dd><p class="Body"><a name="90584"> </a>An error handler is a special Tcl procedure that is invoked when a protocol error occurs. An error handler procedure is invoked with four arguments. These are: the handle name, the command provoking the error, the error message itself, and a tag that can be supplied when the error handler is attached. (For more information see the online reference material under<b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Tornado API Guide>WTX Tcl Library</font></b>.) An error handler procedure must accept these four arguments. Here is a simple error handler that prints its arguments and then resubmits the error to the Tcl interpreter. Except for the printing it has no effect on the application.</p><dl class="margin"><dd><pre class="Code2"><b><a name="90394"></b><tt class="output">wtxtcl> </tt><b>proc myErrorHandler {handle cmd err tag} { puts stdout "handle $handle\ncmd $cmd\nerr $err\ntag $tag" error $err }</a></b></pre></dl><dd><p class="Body"><a name="85698"> </a>Error handler procedures are associated with communication handles, so different connections may have different error handlers in one <b class="command">wtxtcl</b> session. To attach the error handler <i class="textVariable">myErrorHandler</i> to the WTX handle at the top of the handle stack, use the following command:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85699"></b><tt class="output">wtxtcl> </tt><b>wtxErrorHandler [lindex [wtxHandle] 0] myErrorHandler</b><tt class="output"></tt><b></a></b></pre></dl><dd><p class="Body"><a name="85709"> </a>You can test the process by defining this procedure to the interpreter and entering a faulty memory read request as in the following example:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85710"></b><tt class="output">wtxtcl> </tt><b>wtxMemRead 0xeeeeeeee 0x1000 </b><tt class="output">handle vxsim7@aven cmd wtxMemRead 0xeeeeeeee 0x1000 err WTX Error 0x100ca (AGENT_MEM_ACCES_ERROR) tag Error: WTX Error 0x100ca (AGENT_MEM_ACCES_ERROR)</tt><b></a></b></pre></dl><dd><p class="Body"><a name="89837"> </a>The first four lines of output were printed by the handler. The fifth was printed by the <b class="command">wtxtcl</b> main loop in response to the error it received. This is because the error handler resubmits the errors it receives.</p><dd><p class="Body"><a name="85717"> </a>There are several guidelines to observe when writing error handlers: </p></dl><dl class="margin"><p class="listspace"><ul class="Bullet" type="disc"><li><a name="85718"> </a>Errors that are not specifically treated by the handler should be resubmitted intact with the error command. This is because many applications expect to receive errors in certain circumstances, and contain code that checks the result of WTX calls attempting to match the result against expected error codes. </li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="85719"> </a>If an error handler resolves an error by retrying the operation, it should check the command argument to make sure the error was generated by the expected command. </li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="85720"> </a>While it is possible to chain error handlers, this can be complicated. It is better if each application maintains one central error handling procedure.</li></ul></p></dl></dl><a name="foot"><hr></a><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="c-wtx.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-wtx.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-wtx3.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-wtx5.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p></body></html><!---by WRS Documentation (), Wind River Systems, Inc. conversion tool: Quadralay WebWorks Publisher 4.0.11 template: CSS Template, Jan 1998 - Jefro --->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -