RobotStudio event

Reading targets from RS station [moved from RobotStudio]

Engineer345
edited October 2013 in Developer Tools
Hi, i have many modules inside my active station in RS, at least three modules have three different targets sets, am trying to read the targets from only one of these modules and export it to my program in C# , i have no problem in reading the targets if i have only one modules with one set, but whenever i try it on the station which has different modules i got an error, and i can not import the targets.
any help in this topic is really appreciated.

Post edited by Jonathan Karlsson on

Comments

  • What exactly is the problem with the station that has multiple modules? It is possible to get all the modules in a station by:

    ABB.Robotics.Controllers.RapidDomain.Task tRob1 = robotCont.Rapid.GetTask("T_ROB1"); //or whatever specififies your task
    modules = tRob1.GetModules().ToList();

    And then just iterate through the modules and use the code that worked for you earlier for each one. Also, this snippet extracts all robottargets regardless of how many modules there are:

     ABB.Robotics.Controllers.RapidDomain.RapidSymbolSearchProperties searchOpt = ABB.Robotics.Controllers.RapidDomain.RapidSymbolSearchProperties.CreateDefaultForData(true);
                robotCont = new Controller(ABB.Robotics.RobotStudio.Controllers.ControllerManager.ControllerReferences[0].SystemId); //or however you can identify your controller, this just grabs the first one

                ABB.Robotics.Controllers.RapidDomain.Task tRob1 = robotCont.Rapid.GetTask("T_ROB1"); //get the task

                    try
                    {
                        foreach (ABB.Robotics.Controllers.RapidDomain.RapidSymbol rsymb in tRob1.SearchRapidSymbol(searchOpt)) //loop through all rapid symbols found in task
                        {
                            if (ABB.Robotics.Controllers.RapidDomain.RapidSymbol.IsData(rsymb)) //check if it is data (we're looking for a robottarget variable)
                            {
                                
                                ABB.Robotics.Controllers.RapidDomain.RapidData tempData = new ABB.Robotics.Controllers.RapidDomain.RapidData(robotCont, rsymb); //convert the symbol to data
                                    
                                 //check if it is a robot target type
                                if ( tempData.Value is ABB.Robotics.Controllers.RapidDomain.RobTarget)
                                    //if so, do whatever you want with it here.
                            }

                        }
                    }
                    catch (Exception ex)
                    {
                        
                    }

    If this doesn't solve the problem please post more specifics.
  • Hello ,
     i think i have problem in the basics ( how to define the controller and modules) because it gives an error that they are not in the contest :
    shall i define the controller by this way ?  Controller robotCont = new Controller(); 
    please see the program below,,it is a copy from what you sent, i opened a class library project in C#  and added the references then copy your program

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Drawing;

    using ABB.Robotics.RobotStudio.Environment;
    using ABB.Robotics.RobotStudio.Stations;
    using ABB.Robotics.RobotStudio;
    using ABB.Robotics.Math;
    using ABB.Robotics;
    using ABB.Robotics.Controllers;
    using ABB.Robotics.Controllers.Discovery;
    using ABB.Robotics.Controllers.RapidDomain;

    using ABB.Robotics.RobotStudio.Controllers;

    namespace Targets_Modules
    {
        public class Class1
        {
            public static void AddinMain()
            // Project.UndoContext.BeginUndoStep("Targets_Modules");
            {
                // Controller robotCont = new Controller();


                Controller robotCont = new Controller();
                ABB.Robotics.Controllers.RapidDomain.RapidSymbolSearchProperties searchOpt = ABB.Robotics.Controllers.RapidDomain.RapidSymbolSearchProperties.CreateDefaultForData(true);
                robotCont = new Controller(ABB.Robotics.RobotStudio.Controllers.ControllerManager.ControllerReferences[0].SystemId); //or however you can identify your controller, this just grabs the first one
                ABB.Robotics.Controllers.RapidDomain.Task tRob1 = robotCont.Rapid.GetTask("IRB4400_60_1.96_249T_ROB1"); //or whatever specififies your task
                modules = tRob1.GetModules().ToList();

                try
                {
                    foreach (ABB.Robotics.Controllers.RapidDomain.RapidSymbol rsymb in tRob1.SearchRapidSymbol(searchOpt)) //loop through all rapid symbols found in task
                    {
                        if (ABB.Robotics.Controllers.RapidDomain.RapidSymbol.IsData(rsymb)) //check if it is data (we're looking for a robottarget variable)
                        {

                            ABB.Robotics.Controllers.RapidDomain.RapidData tempData = new ABB.Robotics.Controllers.RapidDomain.RapidData(robotCont, rsymb); //convert the symbol to data

                            //check if it is a robot target type
                            if (tempData.Value is ABB.Robotics.Controllers.RapidDomain.RobTarget)
                            { //if so, do whatever you want with it here.
                            }
                        }

                    }
                }
                catch (Exception ex)
                {

                }
            }
        }
    }
  • I'm afraid I don't know what you mean by "in the contest"? Could you please provide the full description of the exception that occurs, assuming you mean that an exception occurs?
  • Hello Again,
    i am sorry i wrote it by mistake , i meant in not in the context. please see a snapshot of the error i got , again i opened a class library project, the references are the same as above and the same program as above, the errors are :
    Error 7 The type or namespace name 'ControllerManager' does not exist in the namespace 'ABB.Robotics.Controllers' (are you missing an assembly reference?)
    Error 8 The name 'robotCont' does not exist in the current context
    Error 9 The name 'modules' does not exist in the current context

  • Aah, It can seem a bit confusing but there are 2 "Controllers" namespace, one from ABB.Robotics.Controllers (PC SDK) and one from ABB.Robotics.Robotstudio.Controllers (RobotStudio SDK). Controllermanager is in ABB.Robotics.Robotstudio.Controllers, so you need to add it is a reference as well, not just the PC SDK version.
  • Hello , 
    the problem of is ControllerManager is solved (thanks alot!) according to your suggestion: 
    Error 7 The type or namespace name 'ControllerManager' does not exist in the namespace 'ABB.Robotics.Controllers' (are you missing an assembly reference?)
    but still having the other errors for both the robotCont and modules, shall i define them 
    Error 8 The name 'robotCont' does not exist in the current context
    Error 9 The name 'modules' does not exist in the current context
    ut shall i add something to the code ? or open it in another window ( not as class library) or maybe change the method ... i am tryin different things but i can not connect to the controller, also shall i open the virtual  controller in RS before for example! it seems am missing something! and i dont know what is it... 
  • Yes, you need to open the station/virtual controller in RobotStudio first, as otherwise there will be nothing to choose from. Also, the project type should of course be a class library since the resulting file is the .dll file that should be added to the RobotStudio add-in folder, as per: http://developercenter.robotstudio.com:80/Index.aspx?DevCenter=RobotStudio&OpenDocument&Url=html/08a465af-bdcc-4f65-a647-764c14005d00.htm
  • ok, now i opened my virtual controller which is the same as my station, shall i get more information from the RS 
    like IP Address or something like that to put it in the C# program, 
    and how to define the controller which is called ControllerSFB in robot studio , with RobotCont in C# ? 
    can you please help me 
  • Saharqaadan, you shouldn't need an IP adress if your controller is virtual. The controller references that the control manager has have names, so you could simply:

    foreach (ABB.Robotics.RobotStudio.Controllers.ControllerObjectReference objRef in ABB.Robotics.RobotStudio.Controllers.ControllerManager.ControllerReferences)
                {
                    if (objRef.Name.Equals("ControllerSFB"))
                        robotCont = new Controller(objRef.SystemId);
                }
  • Hello, i still have the problem is there any vedio or something rather than the reference or application manual for pc sdk that i can read regarding the tips of getting the pc sdk working
  • I don't know of any videos I'm afraid. 

    Error 9 The name 'modules' does not exist in the current context

    is simply because you have not declared the modules variable. May I ask what background you have in previous programming?
  • Could you post your code and specify what line your error about robotCont occurs at?
  • Finally Solved, the problem was not even with the Controller, my C# code need ascending order of data to calculate the staff .
    the data were repeated and i did not notice that till today 
    :P
  • Thanks alot 
  • Glad to hear it worked out.