Industrial Automation
Industrial Automation | Europe

myKnowledge

Main > Product Type > Automation Systems > HMI > NA
Minimize Text   Default    Enlarge Text
 

Print
E-mail

How To Add Code As An Object Action In NA


Introduction

The NA runs on a .NET platform so it is possible to enhance your HMI functionality by adding VB.NET code to your project. This can be linked to events within your HMI project.

Step 1 – Add the Object Which Triggers An Event

In your HMI project, most page objects are able to trigger an event when they are touched by the user. The most common object to do this is the Button. All button types are able to trigger events when they are touched. For normal use where no bits need to be set, it is best to use the Standard Button.

First drag the button from the Toolbox onto your HMI:

 

Step 2 – Add VB.NET Code To The page


Right click on the page in the Multiview Explorer and choose the ‘View Code Editor’ Option:


This shows a new window that allows you to enter your VB.NET code. You can now create a subroutine in VB.NET. In this example we will add two global variables together and store the answer in another global variable.

As you type, the VB.NET code editor will colour the variable names if it knows them as NA Global Variables, the editor also offers suggestions as you type.

This is a very simple one line subroutine, obviously the power of VB.NET allows very complex VB.NET programs to be created. Subroutines are able to call other methods both within the HMI project and within the .NET framework. 

 Step 3 – Link The Event From Button You Created To The VB.NET Subroutine

 

Now we have created a button and a VB.NET subroutine we can link the two so when you press the button, you run the subroutine.

First we must open the Events and Actions pane by clicking View|Events and Actions:

The Events and Actions pane allows you to see all the events that an object can create and assign an action to them.

 
In the case of a button you have 3 actions; Click, Press and Release. Most of time you should use click which ensures the user has pressed and released the button before the Action is triggered.

Once you have chosen the click Event you must choose what action to perform. There are many Actions and these are covered in a separate 'Understanding NA Page Object Events And Actions' article . For this example we want to call a VB.NET subroutine so we will choose the option ‘Call Subroutine’.

You must now enter the name of the subroutine you wrote in Step 2. As you start typing Sysmac Studio will offer suggestions which you can select if they are correct.

Once the subroutine has been entered, the link is completed and the button will now trigger the subroutine when it is pressed and released (clicked),

The subroutine does not belong to the button so if you delete the button, the subroutine will stay as part of the page. You can also link the subroutine to other objects on the page in the same way. If you delete a page, any subroutines on that page will also be deleted.

See Also:

Introduction to the NA series HMI




Comments (View All Comments / Add Comment)

Related Articles
No related articles found.
Created 2014-07-02
Modified 2015-04-08
Views 6905

 

You are not logged in.