FP SDK 5.14. Rapid Data Value Changed Event.




Dear sirs,

Could someone shed some light to the the logic of the rapid data changing event triggering.
I have a PERS variable and have a subscribtion on the data changing. 
Here it is:
        public void SubscribeMethodOnRapidData(string rdName,    Action<ControllerDataToComponent> method)
        {
             _rapidsMap.Add(rdName, method);
            _controller.Rapid.GetRapidData("T_ROB1", "ProgressModule", rdName).ValueChanged += rd_changed;

        }

  private void rd_changed(object sender, DataValueChangedEventArgs e)
        {
            if (sender is RapidData)
            {
                MessageBox.Show("RapidData has changed!");
                string rdName = ((RapidData)sender).Name;
                Action<ControllerDataToComponent> method = _rapidsMap[rdName];
                ControllerDataToComponent sgnToComponent = new ControllerDataToComponent();
                sgnToComponent.dataValue = GetRapidData(rdName).ToString();
                method.Invoke(sgnToComponent);
            }
            else
                MessageBox.Show("sender is not RapidData!");
        }

During the execution the value of the rapid variable changes many times, but I have no event triggering.  Why? What I had missed? It works perfect with the signals...

Thank you in advance...

P.S. I'm using the virtual controller



SAV2012-09-03 06:57:42
Anton Shchepelin,
Russia, Chelyabinsk,
The Research and Production Company "Alpha-Intech",
http://alphajet.ru/

Comments



  • Hi SAV,
    Got your message so here I am image
     
    First here is an example which I ran just now which works, you need three buttons and a TpsLabel, and then the declaration of the ctrl and myRD needs to be at the top of the class declaration.
    [code]

            private void btnSub_Click(object sender, EventArgs e)
            {
                myRD = ctrl.Rapid.GetRapidData("T_ROB1", "Module1", "myNum");
                this.myRD.ValueChanged += myRD_ValueChanged;
            }
            private void myRD_ValueChanged(object sender, DataValueChangedEventArgs e)
            {
                this.Invoke(new EventHandler(ToTheLabel), sender, e);
            }
            private void ToTheLabel(object sender, System.EventArgs e)
            {
                if (this.tpsLabel1.Text == "")
                {
                    this.tpsLabel1.Text = DateTime.Now.ToString() + " : " + myRD.Value.ToString();
                }
                else
                {
                    this.tpsLabel1.Text = this.tpsLabel1.Text + "
    " + DateTime.Now.ToString() +  " : " + myRD.Value.ToString();
                }
            }
            private void btnClear_Click(object sender, EventArgs e)
            {
                tpsLabel1.Text = "";
            }
    [/code]
     
    Regarding your code, first your use of the windows messagebox is a no-no, you should be using the GTPUMessageBox instead.
     
    I'll go through the rest later.
  • Sorry, had to do some other stuff in between. OK lets look at your code.
    1) Can't see your other stuff, so I really can't say regarding your calls like _rapidsMap
    2) In the event [rd_changed] you have code that make UI changes (MessageBox.Show) before the invoke. Wouldn't it be better to just send along the sender and e and then do the strings and sgnToComponent execution in the invoked method. See Working with RAPID data and Controller events and threads
    In my example above you see that I use that in the [myRD_ValueChanged], which invokes [ToTheLabel].
    3) what do you use the delegate for?
    Action<ControllerDataToComponent>
    Can't make sense of that.
  • You was right, it works. The key point was the following: the variable myRd must be not local. 
    Thank you, John. 
    Anton Shchepelin,
    Russia, Chelyabinsk,
    The Research and Production Company "Alpha-Intech",
    http://alphajet.ru/
  • lubosko105
    lubosko105 slovakia
    Hi guys.
    is it possible to fire event also for 'Signal' (I/O system), but not only PERS Rapid variable?
Sign In or Register to comment.