RobotStudio event

PC SDK - exception while reading RAPID data

I'm working with PC SDK 5.14, and i'm trying to make a software in C# which receive and send some data to an ABB Controller.

In my software, i wrote some code to register to an event when one of the rapid value change. Then I read this value and send it to the rest of my code.

[CODE]
private bool registerRapidDataEvents()
{
  RapidData rd =   controller.Rapid.GetTask("T_ROB1").GetModule("LASER")
                             .GetRapidData("LASER_MODE");
  rd.ValueChanged += new EventHandler<DataValueChangedEventArgs>
                                                     (laserLaserMode_ValueChanged);
  rd.Dispose();

  return true;
}

private void laserLaserMode_ValueChanged(object sender, DataValueChangedEventArgs e)
{
  if (this.callbackObject != null && this.controller != null)
  {
     RapidData rd = null;
     try
     {
      rd = controller.Rapid.GetTask("T_ROB1")
                            .GetModule("LASER")
                            .GetRapidData("LASER_MODE");
      IRapidData data = rd.Value;
      if (data is ABB.Robotics.Controllers.RapidDomain.Byte)
      {
         ABB.Robotics.Controllers.RapidDomain.Byte value =                    
                    (ABB.Robotics.Controllers.RapidDomain.Byte)data;
         OnLaserModeChanged((int)value);
       }
   }
   catch (ABB.Robotics.BaseException ex)
   {}
   finally
   {
       if (rd != null)
       rd.Dispose();
    }
  }
}
[/CODE]

My problem is that one exception of type "System.Threading.ThreadAbortException" is send by ABB.Robotics.Adapters.IRC5.dll
This exception occur when I execute, in the event callback function, the line :
[CODE]IRapidData data = rd.Value;[/CODE]

I don't know what I'm doing wrong because I succesfully register the event without any problem.

For debugging purpose I wrote some code in RobotStudio which is running in a virtual robot :
[CODE]
MODULE LASER
   PERS byte LASER_MODE:=1; 

   PROC main()
   While true DO
      IF LASER_MODE<8 THEN
         LASER_MODE := LASER_MODE + 1;
      ELSE
         LASER_MODE := 0;
      ENDIF
      WaitTime 5;
   ENDWHILE
   ENDPROC
ENDMODULE
[/CODE]

Comments

  • Probably not a complete fix, but remove your call to "rd.dispose()" 

    You're going to be using the variable for the duration of the class since you set up an event handler.