RobotStudio event

Pull Rapid variable with C#

Options
I post a lot of questions about - how to pull variable value from the module with C#. And I still didn't receive a clear answer. A lot of members of this forum point me in the right direction - thank you all for your examples and support.
I was able to pull a variable from my module but I can not pull the value of that variable. My code:

private NetworkScanner netScan = null;
private ControllerInfo[] ctrlInfo = null;
private Controller aController = null;

// scanning the network for the controllers
NetworkScanner netScan = new NetworkScanner();

// getting all available controllers from the network
// using ControllerInfo[] ctrlInfo
ctrlInfo = netScan.GetControllers();

// can be used like this if you know which controller inside of ctrlInfo[] array.
// using Controller aController
aController = new Controller(ctrlInfo[0]);

//aController = ControllerFactory.CreateFrom(ctrlInfo[0]);

RapidData rd = aController.Rapid.GetRapidData("T_ROB1", "mModule", "variable");

//trying to print the value:
Console.WriteLine(rd.Value);

No output - empty space.
What I'm doing wrong?

Best Answers

  • EugeneB
    EugeneB
    Answer ✓
    Options
    Thanks DenisFR. I send you a message earlier.
    I finally understand how it works. Now I able to pull any variable I want from the module.
    Thank you all ABB forum community.
  • EugeneB
    EugeneB
    Answer ✓
    Options
    I was missing one piece of the of the code: example:

    Module m;
    RapidData r01, r02; // create instance for each variable
    Num v; // will work with num data
    ABB.Robotics.Controllers.RapidDomain.String s; // will work with string data

    // I didn't know how to asosiate Num and String with my module:
    // Now I do.
    r01 = m.GetRapidData("number");
    r02 = m.GetRapidData("name"); // string variable

    // I did't know how to use structures - Num, and String
    // read value
     v = (Num)r01.Value;
     s = (ABB.Robotics.Controllers.RapidDomain.String)r02.Value;