AdvancedHMI Software

General Category => Support Questions => Topic started by: BLUDOTT on October 27, 2016, 12:51:23 AM

Title: multiple outputs on one button
Post by: BLUDOTT on October 27, 2016, 12:51:23 AM
is there a way to make one button in advanced hmi control 2 to 3 outputs, like for example one pilot light can control 3 internal relays or read ?
Title: Re: multiple outputs on one button
Post by: Rox on October 27, 2016, 01:00:12 AM
here's sample: in every press of a button increment a counter in plc,
if counter = 0 then all off
  elseif counter = 1 then On Output 1
  elseif counter = 2 then ON output 2
  elseif counter = 3 then ON Output 3
if counter > 3 then counter = 0
Title: Re: multiple outputs on one button
Post by: Godra on October 27, 2016, 09:32:45 AM
There are 2 possible ways to perform multiple actions with a single press of a button:

1) Create these actions in your PLC ladder logic. Your ladder logic could control output relays directly or indirectly (attached is a picture showing simple example for ladder logic).

2) In the AdvancedHMI, write the code inside the Click event to perform these actions. In addition, you could use button properties for one of the addresses.

If you double-click the button it will take you to button's Click event, where you can add code similar to this:

Code: [Select]
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        SerialDF1forSLCMicroCom1.Write("B3:0/0", "1")
        SerialDF1forSLCMicroCom1.Write("B3:0/3", "1")
        SerialDF1forSLCMicroCom1.Write("N7:0", "225")
        SerialDF1forSLCMicroCom1.Read("N7:1")
    End Sub


My suggestion: Don't use a code to write directly to Inputs or Outputs of your PLC. Setup your ladder logic instead.
Title: Re: multiple outputs on one button
Post by: BLUDOTT on October 27, 2016, 11:01:16 PM
i guess what i was trying to ask is can the PLCAdressValue take 2 plc modbus adresses ?
Title: Re: multiple outputs on one button
Post by: Godra on October 28, 2016, 03:29:15 PM
From my knowledge, the answer to your question is NO.

You can still achieve the same functionality by following the suggestions from previous post.
Title: Re: multiple outputs on one button
Post by: BLUDOTT on October 28, 2016, 08:20:59 PM
ok thanks
Title: Re: multiple outputs on one button
Post by: Godra on October 29, 2016, 07:43:52 PM
You might check this new control to see if it could be useful:

http://advancedhmi.com/forum/index.php?topic=1503.0
Title: Re: multiple outputs on one button
Post by: BLUDOTT on November 04, 2016, 12:38:20 AM
thank you Godra
Title: Re: multiple outputs on one button
Post by: Archie on March 01, 2017, 06:55:42 AM
Version 3.99v now includes a RecipeButton that can write multiple values on a single click. These values are defined by an INI File. The file contents would be similar to this:

[Button1]
N7:0=99
N7:1=111
N7:2=222
ButtonText=ABC
Title: Re: multiple outputs on one button
Post by: bachphi on March 01, 2017, 09:34:54 AM
"RECIPE" button is what it is designed for. 
I would oppose for its use to control several real world outputs.
If you want to use it, one should pay dear attention to it, especially since it's  in the ini format, anybody can change/add to it.
Title: Re: multiple outputs on one button
Post by: AabeckControls on March 03, 2017, 03:38:17 PM
Sorry if I am bringing up an old issue, but with the recipe button is there a way for the operator to name or rename a recipe listed in the inifile?

 I couldn't find any posts that related to this.
Title: Re: multiple outputs on one button
Post by: Archie on March 03, 2017, 06:02:03 PM
Sorry if I am bringing up an old issue, but with the recipe button is there a way for the operator to name or rename a recipe listed in the inifile?
The text on the button is defined by the ButtonText setting in the INI file at start up:

[Button1]
N7:0=99
N7:1=111
N7:2=222
ButtonText=ABC


If you want the ability to change it at run time, it would require some code to do it.
Title: Re: multiple outputs on one button
Post by: AabeckControls on March 03, 2017, 06:09:10 PM
Archie,

I don't mean the text on the button - that is going to say "Recipe"

I mean:
Recipe #1 = Delta Electronics
Recipe #2 = Omega Engineering
Recipe #3 = Beta Instruments
Reci....

If they stop doing the Omega job and want to use Recipe #2 now for a new 'Sigma Works' job can the operator change that name which is in RecipeValues1.txt?
Title: Re: multiple outputs on one button
Post by: Archie on March 03, 2017, 06:29:50 PM
I may not still completely understand. The idea behind the recipe button is to have multiple recipe buttons on a form. Each defined with their own set of parameters and name. For example, add 3 RecipeButtons to the form. Set the IniFileSection property of each button to "Button1", "Button2", and "Button3" respectively.

Then your INI file would contain something like this:

[Button1]
N7:0=99
N7:1=111
ButtonText=Delta
[Button2]
N7:0=22
N7:1=123
ButtonText=Omega
[Button3]
N7:0=44
N7:1=789
ButtonText=Beta

When the operator is ready to change to Omega, he clicks the second button with the Omega text and it will download the associated parameters.
Title: Re: multiple outputs on one button
Post by: AabeckControls on March 03, 2017, 07:32:15 PM
I was thinking the recipe button dropped down a list of recipes to select, but now I would need 255 recipe buttons if I read that correctly.

Each recipe will have 35 integers to write along with a name to display for it is what I was planning on.

Is there another function that would be better than the recipe button?
Title: Re: multiple outputs on one button
Post by: Archie on March 03, 2017, 07:50:48 PM
I was thinking the recipe button dropped down a list of recipes to select, but now I would need 255 recipe buttons if I read that correctly.

Each recipe will have 35 integers to write along with a name to display for it is what I was planning on.

Is there another function that would be better than the recipe button?
The Recipe button would definitely not be very good for that many recipes. I can't think of any way to gracefully handle that many recipes without writing some code. A custom control with a drop-down list may be in order.
Title: Re: multiple outputs on one button
Post by: AabeckControls on March 03, 2017, 08:52:26 PM
Archie,

Here is my recipe entry screen. I got entering and reading all the parameters and recipe numbers already, just I need a way of the HMI recording a unique name for each.
Then on my MainForm I was hoping to have a drop down or popup list to select one of the created recipes, either by a button or when they click on the recipe #
Title: Re: multiple outputs on one button
Post by: Archie on March 03, 2017, 09:28:11 PM
With so many recipes and so many parameters per recipe, I would really approach this as a database application. You can use a Master-Detail of relationship of 2 tables. Creating the tables, then using a Data Source, your recipe editor page creation would then become a simple drag and drop.

A ComboBox to select a recipe would also be a drag and drop form the Data Source. At that point you would need to write about 20 lines of code to use a table and table adapter to read the recipe and transfer it to the Database.
Title: Re: multiple outputs on one button
Post by: Archie on March 03, 2017, 09:56:19 PM
Here is a good video that walks you through the process of creating a database application:

https://www.youtube.com/watch?v=3w2JkLcp-UA
Title: Re: multiple outputs on one button
Post by: bachphi on March 04, 2017, 08:18:21 PM
I was thinking of using Controllogix, but using DB is a good idea too. 

The below link is more up to date with recent VS version, make a strong case for recipes with combo drop down and code:

https://www.youtube.com/watch?v=NLs44hxV514&t=551s (https://www.youtube.com/watch?v=NLs44hxV514&t=551s)
Title: Re: multiple outputs on one button
Post by: AabeckControls on March 07, 2017, 12:08:48 PM
Bachphi,

The video you posted was very helpful - but the link goes to the middle of the video (=551s starts at 551 seconds into it)

Now I have my database for recipes (which looks like it will allow thousands of recipes) but now I need to know how to get the integers from the database entries to the PLC when the Save/Select button is pressed.

I suppose this will need to write lines of code to save each textbox to a specific integer on the PLC (SLC5/05) in the button line of code - I just need to know where and the syntax
Recipe Number write to N10:0
Pre Heat Temperature write to N10:5
(34 more.....)

Also, I just thought On the MainForm screen I would like to show the recipe name field from the database for the current selected recipe

And I am going to hide the Recipe FormChange button if the press is in cycle so the operator can't change the recipe in the middle of a cycle
Title: Re: multiple outputs on one button
Post by: Archie on March 07, 2017, 01:16:15 PM
PLC<-->DB can be one of the most challenging things to do in AdvancedHMI because you have to do it all in code. If you are using ADO.NET and a Datasource, it will make it much easier. There are 3 components you must understand in order to grasp the concept and make your life easier.

1) Database (either a file or SQL  Server) - This is where the data is stored rententatively
2) Dataset is a disconnected copy of data from the database. It acts like a temporary holding place for accessing the data from code. The Dataset can contain multiple tables.
3) TableAdapter - This is the tool that transfers data to and from the Dataset and Database

When you create a Data Source in your project, it defines the DataSet and TableAdpaters that match your database. You will need to create an instance of both the DataSet and TableAdpaters in order to use them in code. This can be done by dragging them from the Toolbox onto the form.

I will continue this in another post............
Title: Re: multiple outputs on one button
Post by: AabeckControls on March 07, 2017, 02:13:00 PM
Archie,

Thanks. I already created the Dataset as the video showed.

Now I need the TableAdapter to figure out.
           I just checked and it is already on the page. but the code only says: 
                Me.RecipeTableTableAdapter.Fill(Me.RecipeDataSet11.RecipeTable)

I already presumed it would need 36 (or 72, 108, 144?) lines of code to move the 36 integers to the PLC.

Plus - as I write this I am installing Visual Studio Community 2017 on one computer, if it works good it will be on all 4
Title: Re: multiple outputs on one button
Post by: Archie on March 07, 2017, 05:49:58 PM
When you create a Data Source, the TableAdapters are given a default method of Fill. Using this method will read all of the table contents from the database and put it in the DataSet's corresponding table. Once the DataSet is populated, you can then retrieve the values as if they were variables. For example:
Code: [Select]
RecipeDataSet.RecipTable(0).Time1
This will retrieve the value from the column named Time1 that is in Row 0. So if we now want to write that to the PLC:
Code: [Select]
EthernetIPforCLXCom1.Write("MyTag", RecipeDataSet.RecipTable(0).Time1)
Since a database field can be null, as a safeguard you should check that before doing anything with the value:
Code: [Select]
If NOT RecipeDataSet.RecipTable(0).IsTime1Null then EthernetIPforCLXCom1.Write("MyTag", RecipeDataSet.RecipTable(0).Time1)
Title: Re: multiple outputs on one button
Post by: AabeckControls on March 08, 2017, 06:56:51 AM
Archie,

More thanks.

So it will take 2 lines - retrieve the integer and write to the PLC (none of the fields can be null)

However this will be going to a SLC5/05 so do I replace the "MyTag" with N10:20, or will another line be required to deal with direct addressing for each integer?

****
And - there seems to be a bug in Visual Studio Community 2017 installation - it gets to installing the debugger JustInTime and freezes. This happened twice on my main home computer, then I cancelled and started the install on my secondary home computer (also Windows 10 X64) and when I woke up this morning it was stopped at the same place after 10 hours.
Title: Re: multiple outputs on one button
Post by: Archie on March 08, 2017, 07:45:26 AM
In your case the line of code would look like this:
Code: [Select]
If NOT RecipeDataSet.RecipTable(0).IsTime1Null then EthernetIPforSLCMicroCom1.Write("N7:10", RecipeDataSet.RecipTable(0).Time1)

When I installed VS2017, it only took about 5 minutes. I selected the Desktop application set of packages.
Title: Re: multiple outputs on one button
Post by: AabeckControls on March 08, 2017, 08:03:13 AM
Archie,

Two question - where in the code would those lines go - I am thinking in the Save button section right after the saving of the recipe to the table?

 Try
            Me.Validate()
            Me.RecipeTableBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.RecipeDataSet11)
            MessageBox.Show("The Recipe Has Been Saved", "Information", MessageBoxButtons.OK)
            RecipeTableBindingSource.AddNew() 
** Here **If NOT RecipeDataSet.RecipTable(0).IsNumberNull then EthernetIPforSLCMicroCom1.Write("N7:10", RecipeDataSet.RecipTable(0).Number)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
** Or Here **If NOT RecipeDataSet.RecipTable(0).IsNumberNull then EthernetIPforSLCMicroCom1.Write("N7:10", RecipeDataSet.RecipTable(0).Number)

    End Sub

Then on MainForm I want to show the recipe number (integer from PLC)  and also the name, how would I pull the name from the table that matches the recipe number to display it?

Title: Re: multiple outputs on one button
Post by: Archie on March 08, 2017, 08:07:31 AM
You will probably want to add a "Download Recipe" button to your form or use the SelectionIndexChanged on a ComboBox. I wouldn't use the same recipe editor page.
Title: Re: multiple outputs on one button
Post by: AabeckControls on March 09, 2017, 07:48:43 AM
Archie,

I will try to se if I can do that.

Also, I can't install Visual Studio Community 2017 on any of my computers - there is a bug in the JustInTime debugger that halts if AVG anti-virus is installed, and other anti-virus's, even if it is disabled completely. They say a fix is in the works.
Title: Re: multiple outputs on one button
Post by: AabeckControls on March 09, 2017, 01:14:28 PM
Archie,

I got everything in with no errors and rebuilt for a 'Load This Recipe' button as you showed.

Now I need to know how to pull the name from the database to display it on MainForm by reading the recipe number from N10:0 - without the operator being able to change the recipe without going to the recipe screen.
Title: Re: multiple outputs on one button
Post by: Archie on March 09, 2017, 02:35:52 PM
Are you using a ComboBox to select the recipe?
Title: Re: multiple outputs on one button
Post by: AabeckControls on March 09, 2017, 08:48:56 PM
Yes, on the recipe screen I am using the ComboBox with a Load This Recipe button.

What  I want to do is display the recipe name only on MainForm without the operator being able to select another recipe (the recipe FormChangeButton is hidden when in cycle to prevent It being changed)
Title: Re: multiple outputs on one button
Post by: Archie on March 09, 2017, 09:08:40 PM
From the DataSource, change the recipe name column to a ComboBox by clicking the icon to the right of the name. Then drag that onto the form. It will do everything for you to populate the ComboBox.

When you created your database table, did you create an ID column?
Title: Re: multiple outputs on one button
Post by: AabeckControls on March 10, 2017, 06:47:18 PM
I renamed the ID to Number, and it is still the key item.
Title: Re: multiple outputs on one button
Post by: Archie on March 11, 2017, 08:16:48 PM
I renamed the ID to Number, and it is still the key item.
I figured it would be easier to give an example instead of trying to explain all of the intricacies, so I upload a RecipeDBSample :

https://sourceforge.net/projects/advancedhmi/files/advancedhmi/3.5/SampleProjects
Title: Re: multiple outputs on one button
Post by: AabeckControls on March 11, 2017, 09:54:54 PM
Archie,

That's a nice example, but I already have a recipe entry that works.

What I am looking for is to pull the field "Name" based on the recipe number selected that is in integer N10:0 to display the name on a screen where the operator can not change the recipe.
Title: Re: multiple outputs on one button
Post by: Archie on March 11, 2017, 10:21:52 PM
Add a DataSubscriber to look at N10:0

In the DataChanged event something like this:

        Label1.Text = RecipeDataSet.RecipeMaster.FindByRecipeId(e.Values(0)).Name
Title: Re: multiple outputs on one button
Post by: AabeckControls on March 12, 2017, 07:49:57 AM
Archie,

Thanks - that works great