RobotStudio event

ProgramPositionEventArgs problem in PC SDK.

YeonkyuJeong
edited October 2018 in Developer Tools
Hello eveybody!

I have ProgramPositionEventArgs Problem.

My development environment is,

OS : Windows 10
Develop Tool : Visual Studio 2015
ABBRobot : IRB 120
SDK version : RobotStudio 6.07 

My code is,

public event ChangePosition_Delegate CP_Delegate = null;
private event EventHandler<ProgramPositionEventArgs> progpos_events;

this.scanner = new NetworkScanner();
this.scanner.Scan();
progpos_events = new EventHandler<ProgramPositionEventArgs>(this.PositionChangeEvent);

ControllerInfoCollection controllers = scanner.Controllers;

...

tRob = controller.Rapid.GetTask("T_ROB1");
tRob.ProgramPointerChanged += progpos_events;

public void PositionChangeEvent(object sender, ProgramPositionEventArgs _position)
        {
            CP_Delegate(_position.Time.Millisecond.ToString());            
        }

then,

What is the program problem,

ProgramPosition event continue to occur...

ABB Robot move not! but, don't stop event. 

Help me. please!

Comments

  • Micky
    Micky ✭✭✭
    Hi,

    maybe you have to use the Invoke method, like as follows:

    public void PositionChangeEvent(object sender, ProgramPositionEventArgs _position)
            {
                    if (this.InvokeRequired)
                    {
                        this.Invoke(new ProgramPositionEventHandler(PositionChangeEvent), sender, _position);
                        return;
                    }
                   CP_Delegate(_position.Time.Millisecond.ToString());            
            }

    Best regards
    Micky              






  • DeepakP
    DeepakP
    edited October 2018
    It's not clear what issue you are facing. If you just want to process time/position whenever the program pointer changes, below would be a cleaner approach- 

    public delegate void ChangePosition_Delegate(string input);
    
    public class MonitorProgramPosition
    {
        private Controller _robot;
        private ChangePosition_Delegate CP_Delegate = delegate (string input) { Console.WriteLine(input); };  // Just print input to console for testing
        
        // Event handler
        public void PositionChangeEvent(object sender, ProgramPositionEventArgs e)
        {
            CP_Delegate(e.Time.Millisecond.ToString());
        }
    
        // Connect to controller and subscribe to event
        public MonitorProgramPosition(Guid robotGUID)
        {
            _robot = new Controller(robotGUID);
            _robot.Rapid.GetTask("T_ROB1").ProgramPointerChanged += PositionChangeEvent;
        }
    
        // Just keeps program open till any button is pressed
        public void Wait()
        {
            Console.ReadLine();
            _robot.Rapid.GetTask("T_ROB1").ProgramPointerChanged -= PositionChangeEvent;
            _robot.Logoff();
            _robot.Dispose();
        }
    }
    
    class Program
    {
        static void Main(string[] args)
        {
            var ppMonitor = new MonitorProgramPosition(Guid.Parse(<YourRobotGUID>));
            ppMonitor.Wait();
        }
    }<br>
  • Thank you! Micky, DeepakP. I will try!