RobotStudio event

FPSDK : problem GetRapidDataType

hello all,

i am working with records and want to change them, so i need to get the datatype of the record to define a userdefined object, but when i execute the GetRapidDataType, it is always getting me "null" in return so i cannot declare a userdefined type

i am using Robotstudio 5.14.0.1 with virtual controller and VS2008

i also tried to read the type of a simple num, and it returns me "null"

here is the code:

      RapidDataType rdttest;
            RapidData rdtest;

            rdtest = _controller.Rapid.GetRapidData("T_HMI", "HMI_DATA", "TEST");
            tl_test.Text = rdtest.RapidType.ToString();

            rdttest = _controller.Rapid.GetRapidDataType("T_HMI", "HMI_DATA", "TEST");
            udtest = new UserDefined(rdttest);

when i launch this code, i get in my tpslabel the correct name of the datatype
but rdttest is always "null" so it is giving me null exception on the udtest Cry

please any help ???? it is driving me nuts 

Comments



  • Hi Peter1,
     
    the only thing you are doing wrong is that you are mixing up a RECORD declaration named "TEST" with an instance of the RECORD that according to your code should also be named "TEST".
     
    It is also a good idea to not name your variables "TEST" since that is a reserved word in RAPID syntax.
     
    With the following RAPID code:
     
    [CODE]
    MODULE HMI_DATA

    RECORD TESTRECORD
    num x;
    num y;
    ENDRECORD

    VAR TESTRECORD myTESTRECORD := [1,2];

    ENDMODULE
    [/CODE]
     
    The following C# code works fine.
    First I you ask for the name of the type of the data named "myTESTRECORD", which is "TESTRECORD".
     
    Then you ask for the RapidDataType named "TESTRECORD", get it back and can construct a UserDefined.
     
    I also added a loop that iterates over the components and gets their values.
    In this case it will be "1" and "2".
     
    In the snippet below I'm tracing out the text values to the button text. I was a bit lazy ;).
     
    In your snippet you had a dedicated label.
     
    [CODE]
    private void button1_Click(object sender, EventArgs e)
      {
       Controller _controller = new Controller();
       RapidDataType rdttest;
       RapidData rdtest;
       rdtest = _controller.Rapid.GetRapidData("T_HMI", "HMI_DATA", "myTESTRECORD");
       button1.Text = rdtest.RapidType.ToString();
       rdttest = _controller.Rapid.GetRapidDataType("T_HMI", "HMI_DATA", "TESTRECORD");
       UserDefined udtest = new UserDefined(rdttest);
       IRapidData[] components = udtest.Components;
       foreach (IRapidData component in components)
       {
        button1.Text = component.ToString();
       }
      }

    [/CODE]

     
    Hope this keeps you away from going nuts.
     
    Happy New Year!
     

    Best Regards, Niklas Skoglund
    ABB Robotics

    Developer Center
    RobotStudio Blog