RobotStudio event

Read/Write Record structure

Options


Dear All,

I am developing an application using PC SDK and C#. We tried to read/write a RECORD variable in Rapid by following the example in RAB manual. We always got system exception. These examples cannot work. Anybody knows how to do that? Many thanks

The RECORD structure in Rapid is:
---------------------------------------
RECORD P3
        num p1;
        num p2;
        num P3;
ENDRECORD

PERS P3 pOrigin = [0, 0, 0];
-------------------------------------

The code in our application is :
---------------------------------
RapidData         rdOrigin;
RapidDataType  rdtOrigin;

double x = 100.0;
double y = 50.0;
double z = 60.0;

rdOrigin  = Controller.Rapid.GetRapidData(taskName, moduleName, "pOrigin");
rdtOrigin = Controller.Rapid.GetRapidDataType(taskName, moduleName, "pOrigin");

UserDefined ud = new UserDefined(rdtOrigin);
ud.Components[0].FillFromString(x.ToString());
ud.Components[1].FillFromString(y.ToString());
ud.Components[2].FillFromString(z.ToString());
rdOrigin.Value = ud;
-------------------------------------------------------------------
When we create variable "ud", we got the exception "Components' threw an exception of type 'System.InvalidOperationException" such that the following operation with components will throw exception then.

newform2010-02-03 18:23:21

Comments

  • Hi,
     

    You missed one line. ( mentioned in RAB Manual under section Reading User Defined Data 

    Please check the folloeing code. Its working fine-


     
    RapidData rdOrigin;
    RapidDataType rdtOrigin;
    try
    {
    double x = 100.0;
    double y = 50.0;
    double z = 60.0;
    ctr.Logon(
    UserInfo.DefaultUser);
    rdOrigin = ctr.Rapid.GetRapidData(
    "T_ROB1", "test1", "pOrigin");
    rdtOrigin = ctr.Rapid.GetRapidDataType(
    "T_ROB1", "test1", "pOrigin");
    UserDefined ud = new UserDefined(rdtOrigin);
    ud = (
    UserDefined)rdOrigin.Value; //You missed this line
    ud.Components[0].FillFromString(x.ToString());
    ud.Components[1].FillFromString(y.ToString());
    ud.Components[2].FillFromString(z.ToString());
    using (Mastership.Request(ctr.Rapid))
    {
    rdOrigin.Value = ud;
    }
    }

    If still having problem , please write

    Regards
    Regards
    Saleem Javed
  • newform
    Options


    Thank you very much for your help.

    I added this line and had a try. When the application run at the newly added line, it still throws an exception "Exception of type 'System.Exception' was thrown."

    I run the application in debug mode and checked the fields of the variable "rdOrigin". The value of "Value" field is "Exception of type 'System.Exception' was thrown.". But the value of its "StringValue" field is "[0,0,0]", which is the initial value we set. Does it mean "rdOrigin" is not created properly?

    I am using RobotWare 5.12 and the IDE is VS2008.

    newform2010-02-04 15:55:56
  • newform
    Options
    Hi,

    I just found that when our application load Rapid program to controller and initialize "rdOrigin". Its all fields are correctly set. When our application start the Rapid program, the contents in its "Value" field becomes "System Exception ...". Therefore, userdefined "ud" variable can not be initialized. Thus, we initialize "ud" whenever "rdOrigin" is initialized. Up to now, our application is running well, though the process is wield a little bit.

    I have another question now. I need read/write speeddata in Rapid. There is no corresponding NET object in RapidDomain. How can read/write a speeddata variable then?

  • Hi ,

    Its good that finally your program is runnin Smile

    For speeddata, you can wrap userdefined data in a .NET Structure by using IRapidData.

    For more details please refer to section "Implement your own struct representing a RECORD" in RAB User's Guide.

     

    Regards
    Regards
    Saleem Javed
  • newform
    Options
    Hi,

    Thank you very much. That is what I tried yesterday. But the FillFromString always throw exception. Right now, I write speed data to userdefined data component by component. It works well.

    Thanks a lot for your help and time. Have a good day!