RobotStudio event

Event Handler on a bool

Options

Beginner J<?: prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

I am looking for a solution to trig a event handler on an bool variable in the IRC5 system.

I have tried some code but with no good result.

 

Thanks

Niklas

 

Comments

  • RussD
    Options

    you can use the built in data binding to update your UI (easier) or here is how to do  it programmatically:
     
    RapidData rd;
    rd = _ctrl.Rapid.GetRapidData(
    "<Task>","<Module>","<VarName>");
    if (rd != null)
    {
          rd.ValueChanged += DataValueChangedEventHandler;

    }

    private
    void DataValueChangedEventHandler(object sender, DataValueChangedEventArgs e)
    (
         this.Invoke(new EventHandler(DataChanged), new Object[] { sender, e });
    }

    private
    void DataChanged(Object sender, EventArgs e)
    {
         //do something to update the UI with the value of RapidData
         textbox1.text = rd.Value.ToString();
    }

    As always, remove the event handler and dispose of the RapidData instance when you close your app or are fiinished with them.
    RussD2009-02-03 15:08:47
    Russell Drown

  • Thanks Russel!<?: prefix = o ns = "urn:schemas-microsoft-com:office:office" />
     
    I will try what you suggested.
     
    //Niklas
  • Hello,

    I am also looking for a solution to trig a event handler on an bool variable in the IRC5 system, but I need to implement it in VB.NET.

    I tryed a lot of different thinks but I always get the same errormessage: "Der Vorgang ist aufgrund des aktuellen Zustands des Objekts ungA?ltig." I'm using Windows in german, but the message is something like: "Operatin invalid because of the current state of the object.
    "

    Here is my code:

    Private rd As RapidData = Nothing

    rd = Me.AController.Rapid.GetRapidData("T_ROB1", "MainModule", "isMoving")

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButControllersAddHandler.Click
    Try
    If Not rd Is Nothing Then
    AddHandler rd.ValueChanged, AddressOf Rd_ValueChanged
    End If
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    End Try
    End Sub 'Button1_Click


    Private Sub Rd_ValueChanged(ByVal sender As Object, ByVal e As DataValueChangedEventArgs)
    Me.Invoke(New EventHandler(AddressOf UpdateGUI), New Object(){sender, e})
    End Sub 'Rd_ValueChanged


    Private Sub UpdateGUI(ByVal sender As Object, ByVal e As EventArgs)
    Me.Label1.text = Tool1.Value.ToString()
    End Sub 'UpdateGUI

      

    Thanks for Your help
    Denis

    Ich bin keine Signatur, ich putze hier bloß.
  • RussD
    Options

    The only obvious thing I see is that you had tool1.value.tostring instead of rd.value.toString
     
    Private Sub
    UpdateGUI(ByVal sender As Object, ByVal e As EventArgs)
           
         Me
    .Label1.text = rd.Value.ToString()

    End Sub 'UpdateGUI
    Russell Drown
  • Thanks for your reply.

    You are right, but that's not the problem. When I debug Step-By-Step, I get the exception at this line:

    AddHandler rd.ValueChanged, AddressOf Rd_ValueChanged
    where I want to add a subscription to the ValueChanged event. I can't find the problem.

    Thanks again,
    Denis

    Ich bin keine Signatur, ich putze hier bloß.
  • RussD
    Options
    Is the variable "IsMoving" a PERS? You can only subscribe to change events on PERS data.
    Russell Drown
  • That's it!

    Now it works! Thanks a lot!!!

    Denis

    Ich bin keine Signatur, ich putze hier bloß.