Welcome Guest ( Login | Register )



All times are UTC - 7 hours [ DST ]



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Use event or call a method from another class
PostPosted: Fri Apr 06, 2012 5:28 am 

Joined: Mon Feb 06, 2012 8:36 am
Posts: 10

Offline
Good afternoon,

i am using panel T10A and what I'm trying to do looks like this: I have one screen, Screen1, a button, Button1, in it and a tag, Tag1. I need the button to become disabled (Button1.IsEnabled = false) when Tag1 becomes equal to 1. I made two approaches to this.

First:
I created a public method (Disable) for disabling the Button1 in class Screen1 and I tried to call this method from class Tags when the the event Tag1_ValueChange detects that Tag1 is equal to 1. However, I cannot access method Disable from Tags class. This is how I try to call Disable method in class Tags:
Screen1 n = new Screen1();
n.Disable();

Second:
I tried to create an event Tag1_ValueChange in class Screen1 and disable Button1 when Tag1 == 1, however, it does nothing.

Could you help me out with this? If there's totally different solution which works to this, please let me know.

Thank you!


 Profile  
 
 Post subject: Re: Use event or call a method from another class
PostPosted: Fri Apr 06, 2012 8:24 am 

Joined: Tue Mar 13, 2012 9:53 am
Posts: 824

Offline
The easiest way is to use button dynamics. Then you do not need to write any code. First select the button. Then go to the "Dynamics" section of the ribbon. Then click the 'General' button and go to the "IsEnabled" section. In the "IsEnabled" section you can select a tag you want to use to enable/disable the button.

Attachment:
Snap 2012-04-06 at 08.20.21.jpg
Snap 2012-04-06 at 08.20.21.jpg [ 62.99 KiB | Viewed 3713 times ]

_________________
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer


 Profile  
 
 Post subject: Re: Use event or call a method from another class
PostPosted: Tue Apr 10, 2012 12:49 am 

Joined: Mon Feb 06, 2012 8:36 am
Posts: 10

Offline
Thank you, but this solution doesn't have enough functionality for my case.. Because in some cases I need a button to be enabled or disabled when Tag1 AND Tag2 is equal to 1. And I need constant monitoring of these tags state changes, so the best solution would be to use, for example, Tag1_ValueChange event handler. However, I cannot access it from Screen1 class... Could anyone help me?


 Profile  
 
 Post subject: Re: Use event or call a method from another class
PostPosted: Tue Apr 10, 2012 9:21 am 

Joined: Tue Mar 13, 2012 9:53 am
Posts: 824

Offline
I would use the "Dynamics" I described earlier and set it to a Tag that you then change via a script depending on whether or not you want to enable the button.

You may have to turn on the "Always Active" value of the tag if you are not using that particular tag on the screen. Tags are only active when they are on a screen. The "Always Active" option is available when you select "Others" in the "Columns Visible" box on the Tags window.

The value change even can be used like this:

Code:
    public partial class Tags
    {
      
      void Tag1_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
      {
         Enable_Disable();
      }
      
      void Tag2_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
      {
         Enable_Disable();
      }
      
      void Enable_Disable()
      {
         if( Globals.Tags.Tag1.Value == 1 &&
            Globals.Tags.Tag2.Value == 1 )
         {
            //Enable the button
            Globals.Tags.Tag3.Value = 1;
         }
         else
         {
            //Disable the button
            Globals.Tags.Tag3.Value = 0;
         }      
      }
    }
}

_________________
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer


 Profile  
 
 Post subject: Re: Use event or call a method from another class
PostPosted: Mon May 14, 2012 1:22 pm 

Joined: Tue Jan 17, 2012 8:57 am
Posts: 19

Offline
Vilius,

I had a similar issue. The solution I found was to add the following to the screen's script:

In the screen opened event:
Code:
void Screen1_Opened(System.Object sender, System.EventArgs e)
{

   Globals.Tags.Tag1.ValueChange += Enable_Button; // add ValueChange event
   Enable_Button(sender, e); // initialize button state to current tag value

}


In the screen closing event:
Code:
void Screen1_Closing(System.Object sender, System.ComponentModel.CancelEventArgs e)
{

   Globals.Tags.Tag1.ValueChange -= Enable_Button; // remove ValueChange event

}


Finally, the value changed event handler:
Code:
private void Enable_Button(System.Object sender, System.EventArgs e)
{
   Button1.Enabled = Globals.Tags.Tag1.Value;
}

_________________
Bob Livingston
Sr Controls Engineer
FlexEnergy Energy Systems
30 New Hampshire Ave
Portsmouth, NH 03801
USA


 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 7 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron