📄 x-custom3.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><link rel="STYLESHEET" type="text/css" href="wrs.css"><title> Customizing WindView and User Applications </title></head><body bgcolor="FFFFFF"><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="x-custom.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="x-custom.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="x-custom2.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="x-custom4.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p><font face="Helvetica, sans-serif" class="sans"><h3 class="H2"><i><a name="83744">F.3 Customizing the Show Event Dialog Box for User Events</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83748"> </a>As described in <a href="c-datacol4.html#84858"><i class="title">The wvEvent( ) Routine</i></a>, you can generate user events with the <b class="routine"><i class="routine">wvEvent</i></b><b>( )</b> routine.<sup><a href="#foot"><b class="FootnoteMarker">1</b></a></sup> This user event can contain a buffer of data that is logged when the event occurs. You can customize the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Show Event</font></b> dialog box so that it displays this buffer in a format that is appropriate for your needs.</p><dd><p class="Body"><a name="83757"> </a>Suppose you have the following structure that you would like to place in a particular user-defined event buffer:</p><dl class="margin"><dd><pre class="Code2"><b><a name="83758">#include "wvLib.h" #define INFORMATION_EVENT 10 /* user-defined event #10 */ typedef struct { char nodeName [4]; int nodeValue; } EVENT_INFO;</a></b></pre></dl><dd><p class="Body"><a name="83766"> </a>The following example shows how you might use this structure in a call to <b class="routine"><i class="routine">wvEvent</i></b><b>( )</b>:</p><dl class="margin"><dd><pre class="Code2"><b><a name="83767">void postEvent ( char * name, int value ) { EVENT_INFO eventInfo; strncpy (eventInfo.nodeName, name, 4); eventInfo.nodeValue = value; wvEvent (INFORMATION_EVENT, (char *) &eventInfo, sizeof (eventInfo)); }</a></b></pre></dl><dd><p class="Body"><a name="83782"> </a>If <b class="routine"><i class="routine">postEvent</i></b><b>( )</b> is called from an application while WindView is running, you will see the icon for <b class="eventType">user10 </b>in the event log. If you open the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Show Event</font></b> dialog box on that event, you might see something like the left-hand side of <a href="x-custom3.html#86172">Figure F-1</a>. <div class="frame"><h4 class="EntityTitle"><a name="86172"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure F-1: User Event 10</font></a></h4><dl class="margin"><div class="Anchor"><a name="86174"> </a><img class="figure" border="0" src="images/x-customa2.gif"></div></dl></div></p><dd><p class="Body"><a name="83798"> </a>From this, you can see which event it was (number 10), and when and in what context it occurred. </p><dd><p class="Body"><a name="83799"> </a>However, to see the data that was posted with the event, you must define an element of the Tcl array <b class="tclProc">wvUserEventFormat</b> to specify how to unpack and display the buffer <b class="symbol_lc">foruser10</b>. This Tcl definition must be placed in the Tcl initialization file <b class="file">eventbase.tcl</b> introduced in <a href="x-custom2.html#83716"><i class="title">F.2 Customizing WindView Tcl Initialization Files</i></a>. The array index into <b class="tclProc">wvUserEventFormat</b> must match the event number; thus, for user event <i class="textVariable">n</i>, you must define <b class="tclProc">wvUserEventFormat</b><b class="operator">(</b><i class="textVariable">n</i><b class="operator">)</b>.</p><dd><p class="Body"><a name="83804"> </a>The following is an example Tcl specification for the event data just described:</p><dl class="margin"><dd><pre class="Code2"><b><a name="83805">set wvUsrEventFormat(10) { {"node name" string<4>} {"node value" int} }</a></b></pre></dl><dd><p class="Body"><a name="83809"> </a>The example specifies a list of (name, type) pairs for <b class="symbol_lc">user10</b>. This list constitutes a Tcl representation of the <b class="symbol_UC">EVENT_INFO</b> structure shown on the previous page: the field <b class="symbol_lc">"node name"</b> corresponds to <b class="symbol_lc">"char nodeName [4]"</b>, and the field <b class="symbol_lc">"node value"</b> corresponds to <b class="symbol_lc">"int nodeValue"</b>.</p><dd><p class="Body"><a name="83810"> </a>You can use anything for the name of a field (if it contains special characters or spaces, it should be quoted as shown). The types shown in <a href="x-custom3.html#83821">Table F-1</a> can be used.<p class="table"><h4 class="EntityTitle"><a name="83821"><font face="Helvetica, sans-serif" size="-1" class="sans">Table F-1: Field Types for wvUserEventFormat </font></a></h4><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="83825"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Type Label</font></b></div></th><td width="10"> </td><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="83827"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Description</font></b></div></th><td width="10"> </td></tr><tr><td colspan="20"><hr class="tablerule2"></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="83829"> </a><b class="keyword">string</b><i class="textVariable"><k></i> </div></td><td width="10"> </td><td colspan=1 rowspan=1><div class="CellBody"><a name="83831"> </a>String of length no greater than <i class="textVariable">k</i>, where <i class="textVariable">k</i> is an integer. If the string contains a null character, the string is considered to end there, although any remaining bytes are discarded until exactly <i class="textVariable">k</i> characters have been consumed from the user event buffer.</div></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="83833"> </a><b class="keyword">string</b> </div></td><td width="10"> </td><td colspan=1 rowspan=1><div class="CellBody"><a name="83835"> </a>String of indeterminate length. Bytes from the buffer are treated as part of the string until a null character is reached or the buffer is exhausted.</div></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="83837"> </a><b class="keyword">int</b> </div></td><td width="10"> </td><td colspan=1 rowspan=1><div class="CellBody"><a name="83839"> </a>Signed, 4-byte integer. The value is displayed in decimal.</div></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="83841"> </a><b class="keyword">uint</b> </div></td><td width="10"> </td><td colspan=1 rowspan=1><div class="CellBody"><a name="83843"> </a>Unsigned, 4-byte integer. The value is displayed in hexadecimal.</div></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="83845"> </a><b class="keyword">short</b> </div></td><td width="10"> </td><td colspan=1 rowspan=1><div class="CellBody"><a name="83847"> </a>Signed, 2-byte integer. The value is displayed in decimal.</div></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="83849"> </a><b class="keyword">ushort</b> </div></td><td width="10"> </td><td colspan=1 rowspan=1><div class="CellBody"><a name="83851"> </a>Unsigned, 2-byte integer. The value is displayed in hexadecimal.</div></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="83853"> </a><b class="keyword">char</b> </div></td><td width="10"> </td><td colspan=1 rowspan=1><div class="CellBody"><a name="83855"> </a>Character. The value is displayed as a character enclosed in single quotes; for example, 'x'.</div></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="83857"> </a><b class="keyword">byte</b> </div></td><td width="10"> </td><td colspan=1 rowspan=1><div class="CellBody"><a name="83859"> </a>Signed, 1-byte integer. The value is displayed in decimal.</div></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="83861"> </a><b class="keyword">ubyte</b> </div></td><td width="10"> </td><td colspan=1 rowspan=1><div class="CellBody"><a name="83863"> </a>Unsigned, 1-byte integer. The value is displayed in hexadecimal.</div></td><td width="10"> </td></tr><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p></p><dd><p class="Body"><a name="83864"> </a>To see the effect of a new user-event specification, you must restart WindView so that it reads the <b class="file">eventbase.tcl</b> initialization file.</p><dd><p class="Body"><a name="83865"> </a>After <b class="tclProc">wvUsrEventFormat(10)</b> is defined as shown above, an event generated by a call to <b class="routine"><i class="routine">postEvent</i></b><b>( )</b> with arguments "RUN" and 99 looks like the right-hand side of <a href="x-custom3.html#86172">Figure F-1</a> when displayed in the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Show Event</font></b> dialog box. </p><dd><p class="Body"><a name="83869"> </a>Note that the Tcl specification does not imply an alignment for the internal members of the structure. WindView regards the user event buffer as a stream of bytes, and each item in the list consumes a certain number of those bytes. If the structure you send with <b class="routine"><i class="routine">wvEvent</i></b><b>( )</b> has alignment "holes," you must create a <b class="tclProc">wvUsrEventFormat</b> list with the holes made explicit. The following example shows a C structure that is likely to produce an alignment "hole":</p><dl class="margin"><dd><pre class="Code2"><b><a name="83870">struct { char c; short n1; }</a></b></pre></dl><dd><p class="Body"><a name="83871"> </a>The following Tcl definition shows how to allow for the "hole" while unpacking:</p><dl class="margin"><dd><pre class="Code2"><b><a name="83872">set wvUsrEventFormat(11) { {c char} {(padding) ubyte} {n1 short} }</a></b></pre></dl><dd><p class="Body"><a name="83873"> </a>In this example, a padding byte is inserted. This is because in the structure above, a typical C compiler inserts one byte of padding between the <b class="keyword">char</b> value and the <b class="keyword">short</b> value. (The exact amount of padding added depends on both the compiler, and the target architecture you are using.)</p></dl></dl><a name="foot"><hr></a><p class="FootnoteNumberMarker">1: <span class="Footnote"><a name="85483"> </a>You can also set eventpoints with the <b class="routine"><i class="routine">e</i></b><b>( )</b> routine; see <a href="c-datacol4.html#84784"><i class="title">The e( ) Routine</i></a>.</span><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="x-custom.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="x-custom.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="x-custom2.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="x-custom4.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 + -