Refactoring/Updating FB Types
In general, refactoring means modifying (improving) the structure of existing source code while preserving its functional behavior. PLCnext Engineer supports refactoring by providing a mechanism for the automatic and consistent modification of object (variable, FB instance, etc.) properties. Consistent means that the properties to be replaced are considered throughout the solution.
There are several modes for refactoring and updating function block instances and their types in your project:
- Instance refactoring - Refactoring a specific instance of an FB. The procedure is executed with the 'Refactoring' context menu command of an FB instance. For details on this procedure, see the topic "Refactoring Variables and FB Types".
- FB type updating - Updating all FB instances of the same type in all graphical worksheets in the project without changing the FB type itself and the related type of the instance variable in the variables table (can only be executed for an FB selected in the graphical worksheet). Useful when the interface of an FB was changed, for example, adding/removing formal parameters or changing the type of formal parameters.
- FB type refactoring - Changing the type of all FB instances of the same type in all graphical worksheets in the project and the corresponding related type of the instance variables in the variables table (can only be executed for an FB selected in the graphical worksheet). Useful when, for example, calls to a function block are to be replaced by another/newer version of that function block.
The current refactoring mode is shown as subtitle in the REFACTORING window.
Specifics when refactoring safety-related data
The impact that refactoring/updating (safety-related) FB types has on the safety-related application is solely your responsibility as the solution developer. Therefore, the following must be observed before refactoring/updating safety-related FB types.
WARNING
|
Unintended machine operation
|
Updating FB types of the same type in all graphical worksheets without updating the FB type itself
- In the graphical worksheet, select the FB.
- Right-click the FB and click 'Refactor / Update FB Type'.In the Cross Function Area, the REFACTORING window is opened with the subtitle 'FB Type Update' displayed in the header. The window lists all calls of the selected FB of the same type in all graphical worksheets of the project and the corresponding instance variables. In the 'Refactor' column, all checkboxes for the FB calls are selected by default (as shown in the figure above) and all checkboxes for the instance variables are unchecked.Double-clicking a location in the list opens the respective editor with the object highlighted.
- Check or uncheck the locations of the FB calls you want to update.You can use the toolbar icons
and
for the checking and unchecking all locations.
-
Make sure...
- you have followed the instructions in the hazard message above this procedure, and
- your selection does not result in a code error due to inconsistencies.
icon on the toolbar to update the selected FB calls.All checked FB calls are updated with the FB selected in the graphical worksheet.
- After the operation:
- Check the MESSAGES window for any errors that result from the operation.
- Validate and thoroughly test the application with regard to the updated FB calls.
Refactoring FB types in all graphical worksheets with updating the FB type and the type of the related instance variable
- In the graphical worksheet, select the FB.
- Right-click the FB and click 'Refactor / Update FB Type'.In the Cross Function Area, the REFACTORING window is opened with the subtitle 'FB Type Update' displayed in the header. The window lists all calls of the selected FB of the same type in all graphical worksheets of the project and the corresponding instance variables. In the 'Refactor' column, all checkboxes for the FB calls are selected by default (as shown in the figure above) and all checkboxes for the instance variables are unchecked.Double-clicking a location in the list opens the respective editor with the object highlighted.
- In the 'Type' column under the 'New Values' group, select the new FB type from the drop-down list that will replace the original FB type.As soon as you select another FB type, the REFACTORING window switches to 'FB Type Refactoring' mode (displayed with the subtitle 'FB Type Refactoring' in the header) and the checkboxes for all instance variables are additionally checked.
- Check or uncheck the locations of the FB calls and the corresponding instance variables you want to refactor.You can use the toolbar icons
and
for the checking and unchecking all locations.
-
Make sure...
- you have followed the instructions in the hazard message above this procedure, and
- your selection does not result in a code error due to inconsistencies.
icon on the toolbar to refactor the selected FB calls and instance variables.The types of all checked FB calls and the types of the checked instance variables are updated with the FB type selected in the 'Type' drop-down list.
- After the operation:
- Check the MESSAGES window for any errors that result from the operation.
- Validate and thoroughly test the application with regard to the refactored FB calls and instance variables.