FP SDK 5.14. Rapid Data Value Changed Event.
                
                    SAV                
                
                     ✭                
            
                        
            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/
Russia, Chelyabinsk,
The Research and Production Company "Alpha-Intech",
http://alphajet.ru/
0  
            Comments
- 
            
Hi SAV,Got your message so here I am
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.John
Developer Center0 - 
            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.
John
Developer Center0 - 
            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/0 - 
            Hi guys.
is it possible to fire event also for 'Signal' (I/O system), but not only PERS Rapid variable?0 
Categories
- All Categories
 - 5.6K RobotStudio
 - 401 UpFeed
 - 21 Tutorials
 - 15 RobotApps
 - 306 PowerPacs
 - 407 RobotStudio S4
 - 1.8K Developer Tools
 - 250 ScreenMaker
 - 2.9K Robot Controller
 - 363 IRC5
 - 81 OmniCore
 - 8 RCS (Realistic Controller Simulation)
 - 853 RAPID Programming
 - 31 AppStudio
 - 4 RobotStudio AR Viewer
 - 19 Wizard Easy Programming
 - 110 Collaborative Robots
 - 5 Job listings
 
