Author Topic: multiple outputs on one button  (Read 6615 times)

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: multiple outputs on one button
« Reply #15 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.

AabeckControls

  • Full Member
  • ***
  • Posts: 193
    • View Profile
Re: multiple outputs on one button
« Reply #16 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 #

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: multiple outputs on one button
« Reply #17 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.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: multiple outputs on one button
« Reply #18 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

bachphi

  • Hero Member
  • *****
  • Posts: 642
    • View Profile
Re: multiple outputs on one button
« Reply #19 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
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

AabeckControls

  • Full Member
  • ***
  • Posts: 193
    • View Profile
Re: multiple outputs on one button
« Reply #20 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
« Last Edit: March 07, 2017, 12:26:52 PM by AabeckControls »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: multiple outputs on one button
« Reply #21 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............

AabeckControls

  • Full Member
  • ***
  • Posts: 193
    • View Profile
Re: multiple outputs on one button
« Reply #22 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
« Last Edit: March 07, 2017, 03:44:37 PM by AabeckControls »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: multiple outputs on one button
« Reply #23 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)

AabeckControls

  • Full Member
  • ***
  • Posts: 193
    • View Profile
Re: multiple outputs on one button
« Reply #24 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.
« Last Edit: March 08, 2017, 07:00:30 AM by AabeckControls »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: multiple outputs on one button
« Reply #25 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.

AabeckControls

  • Full Member
  • ***
  • Posts: 193
    • View Profile
Re: multiple outputs on one button
« Reply #26 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?


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: multiple outputs on one button
« Reply #27 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.

AabeckControls

  • Full Member
  • ***
  • Posts: 193
    • View Profile
Re: multiple outputs on one button
« Reply #28 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.

AabeckControls

  • Full Member
  • ***
  • Posts: 193
    • View Profile
Re: multiple outputs on one button
« Reply #29 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.