5.3 Building the user interface
5.3.14 DataBinding of RAPID data and IO signals
© Copyri ght 200 7 - 2009 ABB . All ri ghts res erved.
5.3.14. DataBinding of RAPID data and IO signals
What is databinding?Databinding is the process of binding a property of a GUI control to a data source, so that the property automatically reflects the value of the data source. In .NET CF 2.0 this functionality was simplified thanks to the new BindingSource class. This class encapsulates the complexity related to setting up and managing databinding.
FlexPendant SDK classes to be used as binding sources
In the FlexPendant SDK there are two classes that inherit .NET BindingSource:
RapidDataBindingSource and SignalBindingSource.These classes enable binding to
RAPID data and IO signals respectively. They belong to the ABB.Robotics.DataBinding
namespace and the assembly you need to reference is ABB.Robotics.DataBinding.dll.
RapidDataBindingSource
By using RapidDataBindingSource an automatic update of the bound GUI control takes place when the value of the specified RAPID data source in the controller has changed, or when the control is repainted.
SignalBindingSource
By using SignalBindingSource an automatic update of the bound GUI control takes place when the value of the specified IO signal in the controller has changed, or when the control is repainted.
NOTE!
It is only possible to use persistent RAPID data (PERS) as data source. NOTE!
If you want to let users modify RAPID data, launching the standard FlexPendant application Program Data from your application is probably the best alternative. See Using standard dialogs to modify data on page 131 for information about how to do it.
GUI example
Many different controls can be used with binding sources, e.g. TpsLabel, TextBox,
ListView etc. The figure below shows two System.Windows.Forms.DataGrid controls that each bind to several objects defined in a RapidDataBindingSource and a
5.3.14. DataBinding of RAPID data and IO signals © Copyri ght 200 7 - 2009 ABB . All ri ghts res erved.
SignalBindingSource . The labels in each GroupBox are bound to the same sources. As you see the grid displays all objects defined in the BindingSource control, whereas each label displays the currently selected grid row.
When a signal or a data value changes this GUI is automatically updated with the new value. You do not have to write any code make this happen, as setting up subscriptions and updating the user interface is done by the underlying implementation.
6.3.14_1
Continued
5.3.14. DataBinding of RAPID data and IO signals © Copyri ght 200 7 - 2009 ABB . All ri ghts res erved. CAUTION!
To avoid any memory leaks an explicit call to the Dispose method of BindingSource
controls must be made. However, the wrapper-objects SignalObject and
RapidDataObject created for you are disposed of under the hood, so you do not need to worry about it.
How to use the VS designer for data binding
This section explains how to create the FlexPendant view shown in the previous section. First a RapidDataBindingSource control with bindings to specified RAPID data is
created.Then the DataBindings property of a TpsLabel is used to bind the label to the binding source. Finally a standard .NET DataGrid is bound to the same binding source.
Step Action
1. Start by dragging a RapidDataBindingSource from the Toolbox to the Designer. It will be placed in the Components pane under the form. Open the Properties window and select the RapidDataList property to add the RAPID data you are interested in. For each new RapidDataObject member you must specify module name, task name and name of the persistent RAPID data to bind.
6.3.14_2
Continued
5.3.14. DataBinding of RAPID data and IO signals © Copyri ght 200 7 - 2009 ABB . All ri ghts res erved.
2. The next step is to open the Properties window for the label that is to display the value of the RAPID data. Expand the DataBindings node and select Advanced.
6.3.14_3
Step Action
Continued
5.3.14. DataBinding of RAPID data and IO signals © Copyri ght 200 7 - 2009 ABB . All ri ghts res erved.
3. In the Advanced Binding dialog box that appears, choose the already created
RapidDataBindingSource in the Binding combo box, at the same time specifying which one of the RapidDataObject properties you want to bind to, in this case Value. (The other properties available are variable name, task name and module name, as can be seen in the figure in step 1.)
You also select your preferred Data Source Update Mode, usually OnProperty- Changed. The yellow marking in the list to the left shows that the binding has been done to the Text property of the label. When a control has been bound to a data source you will see the same yellow marking in its Properties window, at the bound property. See figure of step 2.
6.3.14_4
NOTE!
If a label has been bound to a data source with several member objects, the first one in the list is the one by default displayed by the label. If the selected index of the list changes (if the user selects a row in the grid for example) the label is updated auto- matically to show the value of the selected index. See the figure in GUI example on page 122.
Step Action Continued
5.3.14. DataBinding of RAPID data and IO signals © Copyri ght 200 7 - 2009 ABB . All ri ghts res erved. SuspendBinding/ResumeBinding
SuspendBinding() and ResumeBinding() have extended functionality compared to the methods of the inherited BindingSource class. Removing/adding subscriptions have been added, as subscribing to signals and RAPID data can be resource consuming. These methods can be used in the Deactivate/Activate methods, which are executed each time the user switches back and forth between different applications using the FlexPendant task bar. See
Application Framework usage - ITpsViewActivation on page 190 for further information. If you suspend the binding you no longer get any updates if the data source is changed. However, the binding still exists, so if DataSourceUpdateMode is set to OnValidation the value will be updated when you repaint the control, as the value from the controller will be read before it is repainted.
4. Now launch the Properties window of the DataGrid control. Set ColumnHeader- Visible to true and select your data source at the DataSource property.
6.3.14_5
NOTE!
The DataGrid control displays only one row in design-time (See the figure of step 1). In run-time, however, the entire collection of RapidDataObject members is displayed (see the figure in GUI example on page 122).
Step Action
Method Description
SuspendBinding Suspends the binding and value change event.
ResumeBinding Resumes the binding and value change event.