RobotStudio event

Problem getting RapidData out of routine

Options

Hey I thought I'd better start a new thread for this.

I have a rapid variable(VAR num nStickOut) declared inside a routine named "rWerkstuk01". Problem is that when I try to get the value of the variable I get the volowing error:

"System.Exception ee: SYS_CTRL_E_UNEXPECTED: An error message that has not been successfully been converted to a common return code.

   Error Code:(0xc004ffff)

SYS_CTRL_E_UNEXPECTED: An error message that has not been successfully been converted to a common return code.

   ERROR:rapid.c[6279]:org_code:-1089 new_code:0xc004ffff; AdaptCmdd.cpp[231];

'Url:/{controllername}/RAPID/T_ROB1/CURSUSV01/rWerkstuk01/nStickOutRAB Prop: Valie Arg:';

When I put the same value globaly (declared outside the routine) I can access it fine. What's wrong?

My code:


private
void button1_Click(object sender, EventArgs e)

{

  this.textBox1.Text = string.Empty;

  Controller c = new Controller();

  ABB.Robotics.Controllers.RapidDomain.RapidData rd;

  Task t;

  Module m;

  string strRetVal = string.Empty;

  try

  {

    t = c.Rapid.GetTask("T_ROB1");

    m = t.GetModule("CURSUSV01");

    rd = m.GetRapidData("rWerkstuk01", "nStickOutRAB");

    strRetVal = rd.Value.ToString();

    this.textBox1.Text = this.textBox1.Text + "strRetVal= " + strRetVal;

    if (rd != null)

    {

      rd.Dispose();

      rd = null;

    }

    if (c != null)

    {

      c.Dispose();

      c = null;

    }

  }

  catch (ArgumentNullException ANe)

  {

    this.textBox1.Text = this.textBox1.Text + "ArgumentNullException ee" + ANe;

  }

  catch (System.Exception ee)

  {

  this.textBox1.Text = this.textBox1.Text + System.Exception ee" + ee;

  }

}

Anny help/info/pointing in right direction  would be much appreciated,

Qrius

Comments

  • RussD
    Options

    I was mistaken with what I said earlier about PERS, if you want to subscribe to DataChanged events the value must be PERS.

    But for your immediate problem, it looks correct, but if you declare data in a routine, I think you must run the routine at least once before you can read it, otherwise its state is indeterminate and you get the error you described.

    You should be able to see this in the RAPID Data viewer on the FP, for the following snippet its value will be listed as N/A before the code is executed, and 1 after it is executed.

    MODULE MainModule
     PROC main()
      VAR num myNum;
      
      myNum:=1;
     ENDPROC
    ENDMODULE

    You can read it as follows:

    rd = ctrl.Rapid.GetRapidData("T_ROB1", "MainModule", "main", "myNum")

     

    Russell Drown
  • Qrius
    Options
    Thanks that helps me out alot! Weird though that the routine has to be run first... o well something for the people working on 5.10 to think about image
  • RussD
    Options

    I think it has to do with the way with RAPID code is linked and made ready to run, so I think this is by design.

    It would be pretty inefficient (and radically change the scope rules defined for the RAPID kernel) to allocate memory for every local variable whose scope is only valid within a routine. One might want to have dozens of modules with hundreds of procedures.

    In the sample routine I made above, if you move the program pointer out of the main routine, then myNum is no longer in scope, its value in the Data Viewer returns to N/A, and you are back to the same problem.

    In summary, if you need to access an item repeatedly, you should probably declare it at the module level to ensure that it is allocated when RAPID is being initialized.

    Russell Drown
  • Qrius
    Options

    Thnx,

    Yes you're right I tried it myself and the data inside a routine is only available when the PP is in the routine. Now I just use the module level variables. Or when I really wan't them inside a routine I use PERS data wich is directly available.

    But thnx for all your effort, you really helpt me out here.