Creating a C# function block library
With Visual Studio®, you can program functions, function blocks, function containers and programs in C# which you can subsequently import using the iCube Engineer Toolchain, iCUbe Engineer and use on a iCube Control device.
Creating a iCube Engineer C# library project
-
Create a new project
On the Visual Studio select Create a new project
Type in search iCube Engineer and double-click theiCube Engineer C# library project
Type in your Project Name, select a storage location and click Create.
-
Enable the System namespace
See the System namespace topic for this step.
-
Add new code sheets
With the extension, different code sheet templates are available. All templates are very basic but working examples. They can be compiled and tested right away.
-
To add a new template right click in the Solution Explorer on your desired project.
-
Select
Add→
New Item….
-
Select in the left tree
C# Items →iCube Engineer
and then one of the following templates:
-
Function
Template for a C# function to be used in IEC 61131-3 code.
Select a return value in the popped-up dialog:
Return Type:
For information on the data types in C# programming and their correlations to data types in IEC 61131 or C++ programming, you can pop up the table of supported data types in an overlay window.
Kind of Return Value:
By Reference is recommended for complex data types and is mandatory for strings, arrays and structures.
-
Function Block
Template for a C# function block to be used in IEC 61131-3 code.
-
Function Container
Template for a C# function container to define several IEC functions in on class.
-
Program
Template for a C# program to be used like an IEC 61131-3 program.
↪ A default code sheet for the selected type of element is created.
-
To add a new template right click in the Solution Explorer on your desired project.
-
Create the code
In the template code sheet, create the code for the function, function block, or function container
Create the entire project by pressing F6.
↪ A *.pcwlx library is being stored in either the Release or the Debug directory of the project.
Proceed with importing the library into iCube Engineer to use your C# function or function block in an automation project.