Load form from signal change
I am getting frustrated. I need to load a new form when a signal changes in the IRC5. I can not use the SignalBindingSource because I have to bind a visible control to it in order to see it change. And I can not get the standard signals to show my form. Here is a code example.
private void _sigSystemState_Changed(object sender, ABB.Robotics.Controllers.IOSystemDomain.SignalChangedEventArgs e)
//Update the GUI if the signal GI_001 changes in the controller
{
CalibrationView2 _CalibrationView2 = new CalibrationView2();
_CalibrationView2.ShowMe(this);
}
private void button1_Click(object sender, EventArgs e)
{
CalibrationView2 _CalibrationView2 = new CalibrationView2();
_CalibrationView2.ShowMe(this);
}
The button example works fine but the SignalBindingSouces change event is on another thread? Exact error: "Controls created on one thread cannot be parented to a control on a different thread."
Comments
-
Hi Shane,I tend to over-explained the stuff ... please let me know if I am goind to much in detail, I will do my best in next posts . So here it comesOnly the UI threads are allow to execute code that will modify the user interface.Inside a Teach Pendant application, there is only one UI thread running at all time. All the events coming for the IRC5 (either by the BindingSource or a Changed event of a RapidData or Signal) comes in a different thread. Hence, what we need to do is to call the UI thread from your executing thread. Here it comes some sample code:
void MySignal_Changed(object sender, SignalChangedEventArgs e)<?: prefix = o ns = "urn:schemas-microsoft-com:office:office" />
{
// We are running in a non-ui thread, so it is not allowed to make changes in the user interface. Lets invoke the UI thread
// In order to invoke the UI thread, we need to use a control that was created in the UI thread.
// In most of the cases, the form in which you are runnning was created in the UI tread, so lets use that one.
// We will assume that 'this' makes reference to the form
this.Invoke(new SignalChangedEventHandler(MySignal_Changed_UI), sender, e);
}
void MySignal_Changed_UI(object sender, SignalChangedEventArgs e)
{
// This code will be running in the UI thread as long as it comes from an invoke
// Here, you can open your view
CalibrationView2 _CalibrationView2 = new CalibrationView2();
_CalibrationView2.ShowMe(this);
}
Hope this helps to explain the behaviour.
Saludos ... CarlosCarlos Martinez
ABB0 -
Carlos,
That is exactly what I needed! Thanks for taking the time and effort to, as in your words, over-explain stuff. It really is appreciated.I will try this this morning,Shane0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 316 IRC5
- 61 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 799 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings