<!doctype HTML public "-//W3C//DTD HTML 4.0 Frameset//EN">

<html>

<!--(==============================================================)-->
<!--(Document created with RoboEditor. )============================-->
<!--(==============================================================)-->

<head>

<title>Developing the Event Handler</title>

<!--(Meta)==========================================================-->

<meta name=generator content="RoboHELP by eHelp Corporation - www.ehelp.com">
<meta name=generator-major-version content=0.1>
<meta name=generator-minor-version content=1>
<meta name=filetype content=kadov>
<meta name=filetype-version content=1>
<meta name=page-count content=0>
<meta name=layout-height content=0>
<meta name=layout-width content=0>
<meta name=date content="08 24, 2001 10:41:31 AM">


<!--(Links)=========================================================-->

<link rel="StyleSheet" href="../../css/main_styles.css">



<!--(Style Sheet)===================================================-->

<style type="text/css">
<!--

body {
	background-image: url("../paper.gif");
	background-repeat: repeat;
	background-attachment: scroll;
}

-->
</style>


</head>

<!--(Body)==========================================================-->


<body class="bodydocs" onLoad="top.pageLoader()" bgcolor="#FFFFFF">


<h1 CLASS=ChapName>Developing the Event Handler</h1>

<p CLASS=Paragraph>This section describes the basic process for developing 
 an Event Handler for Post.</p>

<p CLASS=Paragraph>This section pertains to:</p>

<ul>
	
	<li class=kadov-P-CListBullet><p CLASS=ListBullet>Recommended procedure 
 for developing an Event Handler</p></li>
	
	<li class=kadov-P-CListBullet><p CLASS=ListBullet>Inheritance of Event 
 Handler files</p></li>
	
	<li class=kadov-P-CListBullet><p CLASS=ListBullet>The Post Base 
 File</p></li>
</ul>

<p>&nbsp;</p>

<h1>Recommended Procedure for Developing an Event Handler</h1>

<p CLASS=Paragraph>When creating an Event Handler for Post, it is not 
 necessary to start building from an empty file. NX has provided 
 a number of Event Handler templates for you to use as a starting point 
 when creating the Event Handler for your specific machine tool.</p>

<p CLASS=Paragraph>Start by selecting the Event Handler template with characteristics 
 that most closely match the characteristics of the machine that you are 
 creating the new Event Handler for. The Event Handler templates that are 
 provided contain procedures to process all &quot;standard&quot; motion 
 and event types.</p>

<p CLASS=Paragraph>Review the procedures contained in the template and 
 make sure that there is a procedure for each event that your machine tool 
 will recognize. You will need to develop a procedure for any event that 
 is not already included in the template.</p>

<p CLASS=Paragraph>Review each procedure contained in the template to make 
 sure that it processes the event correctly based on the specific requirements 
 for your particular machine. Modify the existing procedure as necessary.</p>

<p CLASS=Paragraph>Using the procedures in the template as a guide, create 
 procedures for each event that is not included in the template. Start 
 with defining the variables that will be used by the procedure. Use the 
 &quot;global <span style="font-style: italic;">&lt;variable_name&gt;</span>&quot; 
 command to do this. Next initialize those variables with the appropriate 
 &quot;default&quot; value. Use the &quot;set <span style="font-style: italic;">&lt;variable_name</span>&gt; 
 <span style="font-style: italic;">value</span>&quot; command to do this. 
 Next, use &quot;standard&quot; and &quot;NX&quot; extended TCL 
 commands to define how the event is to be processed.</p>

<p CLASS=Paragraph>You will probably need to add new Address and/or Block_Template 
 definitions to the Definition File so that Post will know how to format 
 the output of your procedure when it writes to the Output File. Refer 
 to <a HREF="../def_file/definition_file.html"><span style="font-weight: bold;">Developing 
 the Definition File</span></a> for more information.</p>

<h1><a NAME=event_handler></a>Inheritance of Event Handler Files</h1>

<p CLASS=Paragraph>When developing your Event Handler, you can include 
 one or more event handler files. Post will use procedures contained 
 in the included files unless they are redefined in the current Event Handler, 
 in which case the the included procedures will be overridden. Use the 
 &quot;source &lt;<span style="font-style: italic;">file name</span>&gt;&quot; 
 TCL command to do this.</p>

<p CLASS=Paragraph>In the case where multiple event handler files are &quot;sourced&quot;, 
 a procedure in the second &quot;sourced&quot; file will override a procedure 
 with the same name in the first &quot;sourced&quot; file. Likewise, procedures 
 in a third &quot;sourced&quot; file will override the procedures in the 
 second and so on. Finally, a procedure in the current Event Handler will 
 override all procedures with the same name contained in any of the &quot;sourced&quot; 
 files.</p>

<p CLASS=Paragraph>Using this capability will allow you to quickly and 
 easily develop the Event Handlers for similar postprocessors. By inheriting 
 the procedures from existing event handler files, you only need to define 
 modified, or additional, procedures for the differences.</p>

<p CLASS=Paragraph>A similar capability exists for inheriting existing 
 definition files in the Definition File that you are developing. Refer 
 to <span style="font-weight: bold;"><a HREF="../def_file/definition_file.html#inherit">Inheritance 
 of Definition Files</a></span> for more information.</p>

<p CLASS=Paragraph>The following examples illustrate ways that you can 
 use the inheritance capability.</p>

<h5>Example 1</h5>

<p CLASS=Paragraph>Suppose that you have received a new machine controller 
 with characteristics that are identical to an existing machine controller 
 except that the new controller does not allow the spindle to be turned 
 on while the tool is moving to its initial position after a tool change. 
 The new controller requires that the spindle be turned on in a separated 
 block.</p>

<p CLASS=Paragraph>Creating a new postprocessor for this new controller 
 can be accomplished very easily by &quot;inheriting&quot; all the characteristics 
 of the original Event Handler and Definition files and overriding the 
 block templates and procedures related to turning on the spindle in the 
 new Event Handler and Definiton files.</p>

<h5>Example 2</h5>

<p CLASS=Paragraph>Suppose that your shop uses its own &quot;standard&quot; 
 header information at the beginning of each postprocessor output file. 
 Create a separate file containing &quot;proc MOM_start_of_program&quot; 
 defining you shop's &quot;standard header&quot;. Then &quot;source&quot; 
 this file into each Event Handler that you use.</p>

<p CLASS=Paragraph>Similarly, a &quot;standard&quot; message to the machine 
 operator at specific points in the postprocessed output can be accomplished 
 in the same manner.</p>

<h5>Example 3</h5>

<p CLASS=Paragraph>Once you have completed writing a new Event Handler, 
 you may want to use the NX supplied debugging tool, or one that 
 you have developed, to help with the debugging process.</p>

<p CLASS=Paragraph>You can &quot;inherit&quot; the procedures contained 
 in the debugging tool file into the Event Handler that you are working 
 on. When you have finished the debugging process, you can simply remove, 
 or comment out, the one line &quot;source&quot; command instead of all 
 the lines of code that make up the debug procedure. Refer to Debugging 
 Your Postprocessor for more information.</p>

<h1><a NAME=base_file></a>The Post Base File</h1>

<p CLASS=Paragraph>The Post base file (ugpost_base.tcl) should be included 
 at the top of every Post event handler TCL file. This is accomplished 
 by including a statement similar to the following:</p>

<p CLASS=Input
	style="margin-left: 120px;"><span style="font-size: 11.0pt;">source 
 directory_path/ugpost_base.tcl</span></p>

<p CLASS=Paragraph>The file consists of the data and the procedures that 
 are common to any postprocessor, such as:</p>

<ol>
	
	<li class=kadov-P-CListNum><p CLASS=ListNum>Default G/M codes</p></li>
	
	<li class=kadov-P-CListNum><p CLASS=ListNum>Errors and warnings output.</p></li>
	
	<li class=kadov-P-CListNum><p CLASS=ListNum>Opening the listing file: 
 output file name(extension .lpt).</p></li>
	
	<li class=kadov-P-CListNum><p CLASS=ListNum>Opening the warning file: 
 output file name(extension_warning.out).</p></li>
	
	<li class=kadov-P-CListNum><p CLASS=ListNum>Creation of the Listing 
 file headers and the end information, such as the tool list with their 
 usage, total time, number of warnings.</p></li>
	
	<li class=kadov-P-CListNum><p CLASS=ListNum>Setting the feedrate format 
 as per the mode(per minute, per revolution, inverse time), and the value.</p></li>
	
	<li class=kadov-P-CListNum><p CLASS=ListNum>Handling the PPRINT output 
 to the listing file.</p></li>
	
	<li class=kadov-P-CListNum><p CLASS=ListNum>Any utility functions and 
 data, such as isset, PI.</p></li>
</ol>

<p CLASS=Paragraph>The Post base file should not contain any data or 
 procedures which are specific to any particular postprocessor. Such data 
 and procedures should be implemented in the individual event handlers.</p>

<p CLASS=Paragraph>As a general rule, you are discouraged from modifying 
 the ugpost_base.tcl file. If you desire to create your own library of 
 utility data and functions, you should create a separate include TCL file.</p>

<p CLASS=Paragraph
	style="margin-bottom: 0;">Refer to <a HREF="../base_file/base_file.html"><span 
 style="font-weight: bold;">Post Base File</span></a> for an example 
 of the Post Base file. </p>

</body>

</html>
