Beginner J
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
Beginner J
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
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(“”,“”,“”);
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.
Thanks Russel!
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
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
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
Is the variable “IsMoving” a PERS? You can only subscribe to change events on PERS data.
That’s it!
Now it works! Thanks a lot!!!
Denis