Event Handler on a bool
Niklas
✭
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
0
Comments
-
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:47Russell Drown0 -
Thanks Russel!<?: prefix = o ns = "urn:schemas-microsoft-com:office:office" />
I will try what you suggested.
//Niklas
0 -
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.ClickTry
End Sub 'Button1_ClickIf Not rd Is Nothing Then
Catch ex As ExceptionAddHandler rd.ValueChanged, AddressOf Rd_ValueChanged
End IfMessageBox.Show(ex.Message)
End Try
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ß.0 -
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 'UpdateGUIRussell Drown0 -
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ß.0 -
Is the variable "IsMoving" a PERS? You can only subscribe to change events on PERS data.Russell Drown0
-
That's it!
Now it works! Thanks a lot!!!
Denis
Ich bin keine Signatur, ich putze hier bloß.0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 310 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 785 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 4 Job listings