RobotStudio event

value change event of Raplid data

Options
Dear All,

We are developing a simple PC application using RAB PC SDK. The process is that:
1. PC application sent data to Raplid program and set "start" flag
2. Rapid program continues to execute a process when "start" flag is true
3. Rapid program increases a "PERS Num" variable by 1 if this process is finished. This value is subscribed by PC application, which informs the PC application that this process is done and step 1 starts again by sending a new data.

The question is that the subscribed event will be fired twice each time. Can anybody figure out why? This may cause communication problem.

Many thanks

Comments

  • kjsv
    Options
    Have you solved this?
    If not, do you get two events if your program is stopped and if you change the rapid variable via FP Data View?

  • newform
    Options
    Hi,

    This problem is not solved up to now.

    During execution, I stop robot program and manually change the value of the flag via FP data view. The value change event is still fired twice. No idea what happened.

    Thank you for your suggestion

  • carlosmtz2000
    Options
    - Is there a chance that you are subscribing twice?



     

    If you could post a simple test program with this behaviour, will be a good start ..

     

    Best Regards
    Carlos Martinez
    ABB
  • newform
    Options
    No,

    I double checked the Rapid program. The flag will be only set once when the process is finished.

    Another example is that I manually change the value of the flag using Flependant. The function at PC application side will be invoked twice as well.

    Is this the protocol of RAB to fire value-change event?

  • carlosmtz2000
    Options

    I did not clarify  :) ..

    Do you tha a simple PC Test app to reproduce the problem? Then people in the forum could compile and test it in a local system.
    Carlos Martinez
    ABB
  • newform
    Options
    Hi,

    Thank you very much for your reply.

    I developed a simple PC application (webwiz/2869/ValueChangeRAB.rar) using RAB 5.11 and VS 2005 (C#). This application is developed only for investigating the issue;

    The objective of this application is to
    1) search robot in local network
    2) connect to selected robot
    3) send a Rapid program (rapid/GetConfig.mod) to connected robot
    4) start the Rapid program
    5) send points to Rapid program one by one and check its reacheability given a configuration data.

    Rapid variable registration and registered event function are in file "ConfigManager.cs". You are able to find (from the list box in GUI or log file in executable path named "runner") that whenever the variable "nPoint" in Rapid program is changed. The registered event function "rdPoint_ValueChanged" in ConfigManager.cs will fired twice.

    Please help. Many thanks

  • newform
    Options
    This is a screenshot of the application for your reference. Thanks again
    image
  • carlosmtz2000
    Options
    Hi,
     

    Interesting app for being only for testing purposes :) ...

     

    Quick comments so you can quickly check this:

     

    (1) The method to register event (RegisterCheckEvents) should check if event handlers have been connected. If you call the method twice, you will connect the event handler twice; then any time there is a change in the RAPID data, you will be called as many times as you connect

    (2) Notice that in the ConfigManager.cs (Line 166 & 167) you connect to the same event handler twice (one through the ValueChanged event, other through the Subscribe method).

     

    Hope this helps. Keep us posted

     

    Saludos

     
    Carlos Martinez
    ABB
  • newform
    Options

    Hi, Carlos,

    Appreciate your help.

    I had thought "subscribe" just set priority level. However, it subscribe the event handler again. So I remove line "166" and only "subscribe" event handler once now while keeping other code the same. But when we request mastership to send point, we get the exception "mastership already held". Anything wrong? Is it because of the "subscribe" function?

    Another stupid question is how I can check if an event handler is connected or not.

    Thanks for your time and help

    newform2009-11-20 18:59:57
  • carlosmtz2000
    Options

    Hola ...

    Even though both interfaces connects internally in the same way, the Subscribe method lets you set the priority, and the ValueChanged event sets the priority to Normal only.

     

    The event mechanism does not interfere with the Mastership.  The problem is that you are requesting the mastership twice. The first one to modify the position, this generates a change and call your event handler  "rdPoint_ValueChanged". Inside this event handler you modify the point again (using SendPoint), which in fact tries to request the mastership for the second time. You can avoid this by asking if you already have the masterhip by using the property IsMaster.

     

    There is no way to monitor if you have subscribed to a variable or not. This is usually maintained at the client side.

     

    PD .. there are no stupid questions ...:)

     

    Best Regards
    Carlos Martinez
    ABB
  • newform
    Options

    Hi,

    I modified the code a little bit to check if mastership has been held. I still have the same problem. Enclosed please find a screen shot. No idea about why. However, it does happen all the time. The program sometimes works well.

    Please help. Sorry for bothering you much.

    image

    newform2009-11-23 17:40:37
  • carlosmtz2000
    Options
    You have two threads running this code at the same time; there is a race condition here, so it seems that both are passing the if at the same time, but onyl one will get the mastership. You can prevent this by using a lock statement.
     

    ex.

     

    lock(this)

    {

    i f( ...)

    }

     

    BR
    Carlos Martinez
    ABB
  • newform
    Options
    Hi,

    Thank you very much for your help.

    I modified my application. Up to now, I didn't get any error message. Hopefully it works. Thanks again for your help.