Button change variabel

This is the main technical forum for discussing problems that were encountered by users while developing PROMOTIC applications, and their possible solutions.

Button change variabel

Postby jeffcoll » Sun 15. Oct 2023 19:57:58

i have a PmgButton.
When I press it I want to set a variable in the PLC to 1.
If i release the button again, the variable should return to 0?

how can i best do this?
jeffcoll
 
Posts: 4
Joined: Fri 23. Jun 2017 23:13:58

Re: Button change variabel

Postby Kazimierz Heczko » Wed 18. Oct 2023 10:48:00

What you want is possible, but is not very simple.
Problem is, that PmgButton has not defined any value like button state (other object pmgButtonTwo has that value).
Because abowe, yuo can do it useing scripting.
When you use scripting, than you can't directly read/write properties of pmaObjects in script in any pmgObjects. You can do this using methods defined in the pmaPanel object, in which relevant button exists.
PmgButton has two events: onButtonDown, onButtonUp. You can use this events to call method of the pmaPanel defined by you, which is called on server and can access to any pmaObject.
Method in pmaPanel can be defined like that:
name: SetVal, parameters: bVal (true/false)
script in the method:
Code: Select all
pMe.Pm("../Data#vars/value").Value = bVal;

Calling this method from the buttons events like this:
Code: Select all
pMe.PmPanel.Methods.SetVal(1); //in the onButtonDown event, in onButtonUp set value 0

When variable "value" has been defined with "Comm" data extension with possibility to writing value to the PLC, then write to this variable can send this value to the PLC.

Note:
In this case operator have to "wait" when value from pmgButton writes into the variable and after that can release this button, in other case value of the variable can be wrote for very short time.
Better solution is using method AddEventTimer of the pmaRoot object, which can automatically reset value after defined time (i.e. 0.5 second).
Than script in button will be only in one event, better is place it in the onButtonUp event:
Code: Select all
pMe.PmPanel.Methods.SetVal(1);

Script in this method should be like that:
Code: Select all
pMe.Pm("../Data#vars/value").Value = 1;

pMe.Root.AddEventTimer(500, 1, pMe.GetPathName(), onTick);

function onTick()
{
pMe.Pm("../Data#vars/value").Value = 0;
}

This solution is better, because operator must not wait for writing value into the PLC, and application automatically resets value after required amount of time.
This will be work in WEB panels too, because request from button to the application will be send only once and setting and resetting value is whole executed in server part of the application.

Hope this helps

Best regards
Kazimierz Heczko
 
Posts: 68
Joined: Thu 13. Dec 2012 9:28:56

Re: Button change variabel

Postby jeffcoll » Wed 18. Oct 2023 12:40:30

do you have an example?

Greetz
Jeffrey
jeffcoll
 
Posts: 4
Joined: Fri 23. Jun 2017 23:13:58

Re: Button change variabel

Postby Kazimierz Heczko » Wed 18. Oct 2023 15:02:07

Example is in attachment.
Best regards
Attachments
btn_exam.zip
Example
(21.11 KiB) Downloaded 191 times
Kazimierz Heczko
 
Posts: 68
Joined: Thu 13. Dec 2012 9:28:56


Return to I don't know how to...

Who is online

Users browsing this forum: No registered users and 1 guest

cron