Developer Portal Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    AddOn define to specific level (ModeForwarder, ModeHander, CommandHandler)

    AddOn define to specific level (ModeForwarder, ModeHander, CommandHandler)

    PKlein
    Long-established Member

    Hello everyone,

    I would like to have your feedback. Would make sense to define addons on a certain level (ModeForwarder, ModeHander, CommandHandler).

    Sometimes it makes sense that I can add an AddOn to the CommandHandler or the ModeHandler.

    At the  MES@AE objects I have AddOn's, where I want the user to only be able to set them to the ModeHandler or CommandHandler. Today I check this at the StartupParams.otd with an additional code. But this checking is for the programmer maybe too late because he already set it to the CommandHandler and gets the error message (tag) at the Twin-Cat, and it increases the export time of the OES/CPS. 

    With a possibility to define addons for certain levels, the programmer would not make the mistake and it could reduce the export time.

    What do you think?

    Thanks for feedback!

    7 REPLIES 7

    nexidator
    Community Moderator
    Community Moderator

    The export code is compiled before execution, so it is really fast. There are thousands of lines of code executed on every export, and the whole code generation doesn't contribute that much to the total export time. What takes longer is reading the existing code from TwinCAT, comparing it to the generated code and updating it if necessary.

    MarvinW
    Long-established Member

    I have a similar use case from time to time. The solution to export some {error '...'} into the PLC code is fine, but I was wondering if it was also possible to generate errors directly in OES somehow which are then listed in the output window. That would make it a bit more convenient for the user, too.

    WScottHicks
    Established Member

    I'm not sure if this is an intended feature or not.  I've tested it in OES4.11, but I assume it works in other version.  I've only used this method for debug statements during object development, but I think it could work in a released version as well.

    One option is to create a Custom.otd and return a text string if the error condition is present.

    You'll need to adjust the error check, and the message returned.  The following  is based on @PKlein original question.  It should be trivial to check for other conditions and display more specific messages.

     

    <%
    if (@this.Parent.NodeType != Bosch.OpCon.Engineering.ControlSystems.HierarchyNodeType.CommandHandler ) 
    {
        return @this.UnitInstance.FullName + " at " + @this.Parent.UnitInstance.FullName + Environment.NewLine +
            ": illegal parent NodeType" + Environment.NewLine +
            "MES@AE AddOn must be on a parent CommandHandler-NodeType" ;
    }
    %>

     

    In the Object.ood file you'll need to add 

     

    <Object>
    	<Common>
    		<Templates>
    			<Custom name="Export\Custom.otd"/>
    		</Templates>
    	</Common>
    </Object>

     

     This will give a message displayed during export similar to the following.

    WScottHicks_0-1679058488573.png

     

    Actually now that I look at this more, a better option is to display the MessageBox ourselves in the custom.otd file.  This way we're not relying on a feature that might not be intended or only exists in certain versions.  You also get more control over the MessageBox. 

     

    <%using System.Windows.Forms from System.Windows.Forms %>
    <%
    if (@this.Parent == null )
    {
    	MessageBox.Show(@this.UnitInstance.FullName + Environment.NewLine + 
    		": illegal parent NodeType" + Environment.NewLine + 
    		"MES@AE AddOn must be on a parent CommandHandler-NodeType",
    		"Error Detected during export",
    		MessageBoxButtons.OK,
    		MessageBoxIcon.Error);
    }
    else if ( @this.Parent.NodeType != Bosch.OpCon.Engineering.ControlSystems.HierarchyNodeType.CommandHandler )
    {
    	MessageBox.Show(@this.UnitInstance.FullName + 
    		" at " + @this.Parent.UnitInstance.FullName + Environment.NewLine + 
    		": illegal parent NodeType" + Environment.NewLine + 
    		"MES@AE AddOn must be on a parent CommandHandler-NodeType ",
    		"Error Detected during export",
    		MessageBoxButtons.OK,
    		MessageBoxIcon.Error);
    }
    else if ( @this.Parent.BaseTypeId != "A467FB1C-013E-11E1-8619-000423132FC8")
    {
    	MessageBox.Show(@this.UnitInstance.FullName + 
    		" at " + @this.Parent.UnitInstance.FullName + Environment.NewLine + 
    		": illegal parent NodeType" + Environment.NewLine + 
    		"MES@AE AddOn must be on a parent Command Handler Template  ",
    		"Error Detected during export",
    		MessageBoxButtons.OK,
    		MessageBoxIcon.Error);
    }
    %>

     

    That seems a little better to me.

    WScottHicks_1-1679058925261.png

    The biggest disadvantage I've seen to this method is that the Export won't finish until the MessageBox is closed.  If you're doing other things during export, it's not difficult for the MessageBox to get behind the main window.  I've read adding  MessageBoxOptions.DefaultDesktopOnly could be one solution to this, but I haven't fully tested.

    Maybe someone else has a method to send these messages to the existing output window, but this is all I can come up with.

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist