Difference between revisions of "Function Object With C Code"
m (Added more content) |
|||
Line 1: | Line 1: | ||
− | |||
These are the step by step instructions for creating a Function Object With C Code from the Proview [http://www.proview.se/doc/en_us/man_dg.pdf "Designer's Guide"] Chapter 22.4 - Create Classes.<br \> | These are the step by step instructions for creating a Function Object With C Code from the Proview [http://www.proview.se/doc/en_us/man_dg.pdf "Designer's Guide"] Chapter 22.4 - Create Classes.<br \> | ||
<br \> | <br \> | ||
− | The class definition objects reside in a class volume, | + | =Create a Custom Class Volume= |
+ | The class definition objects reside in a class volume. First, the class volume has to be created and registered. This is done is done by the administrator. To create and register a custom Class Volume: | ||
+ | * Start the administrator with the command 'pwra' | ||
+ | * Open the Global Volume from File->Open->GlobalVolumeList in the Project List window | ||
+ | * Login as administrator | ||
+ | * Enter edit mode | ||
+ | * Here you create a VolumeReg object in the $Hier class named ClassVolumes | ||
+ | * Open the new VolumeReg object and enter a unique name and volume identity. The volume identity for user created class volumes should be within the interval 0.0.2-249.1-254. It is recommended to use the prefix CVol for the name since it is the preferred method to indicate that it is a class volume. The current project also needs to be defined. | ||
+ | * Save | ||
+ | * Logout with the command 'logout' | ||
<br \> | <br \> | ||
− | =Function Object | + | [[File:GlobalVolumeForPLCFunctions.png]] |
+ | <br \> | ||
+ | =Create a Custom Function Object Class= | ||
Function objects are used in the PLC editor to program the PLC program. A function object is also described by a class, usually a bit more complex than a data class. It defines the data structure, the graphic layout with inputs and outputs, and the code that is to be executed for the PLC program.<br \> | Function objects are used in the PLC editor to program the PLC program. A function object is also described by a class, usually a bit more complex than a data class. It defines the data structure, the graphic layout with inputs and outputs, and the code that is to be executed for the PLC program.<br \> | ||
<br \> | <br \> |
Revision as of 12:25, 18 July 2014
These are the step by step instructions for creating a Function Object With C Code from the Proview "Designer's Guide" Chapter 22.4 - Create Classes.
Contents |
Create a Custom Class Volume
The class definition objects reside in a class volume. First, the class volume has to be created and registered. This is done is done by the administrator. To create and register a custom Class Volume:
- Start the administrator with the command 'pwra'
- Open the Global Volume from File->Open->GlobalVolumeList in the Project List window
- Login as administrator
- Enter edit mode
- Here you create a VolumeReg object in the $Hier class named ClassVolumes
- Open the new VolumeReg object and enter a unique name and volume identity. The volume identity for user created class volumes should be within the interval 0.0.2-249.1-254. It is recommended to use the prefix CVol for the name since it is the preferred method to indicate that it is a class volume. The current project also needs to be defined.
- Save
- Logout with the command 'logout'
Create a Custom Function Object Class
Function objects are used in the PLC editor to program the PLC program. A function object is also described by a class, usually a bit more complex than a data class. It defines the data structure, the graphic layout with inputs and outputs, and the code that is to be executed for the PLC program.
The code can be defined either by C code, or by graphical programming in the PLC editor. This example uses C Code.
The function object class is defined by a $ClassDef object under the 'Class' object. Name the object and activate 'Configure-CCodeFo' from the popup menu of the object. Once this is done,the following objects are automatically created in the new Class Object:
- a RtBody object.
- a DevBody object with a PlcNode object that defines a buffer for graphic information in the instances.
- a GraphPlcNode object that contains information for graphic and code generation for the class.
The next step is to define the attributes of the class. The attributes are divided into inputs, internal attributes and outputs.
Inputs
The input attributes define the input pins of the function object, i.e. values that are fetched from output pins of other function objects. The inputs are defined by $Input objects and are placed below the RtBody object.
The datatype of the input, TypeRef, needs to be defined. Valid datatypes for an input are:
- pwrs:Type-Float32
- pwrs:Type-Int32
- pwrs:Type-String80
In GraphName the text at the input pin in the function object is stated. Normally you use 2 - 4 characters, block letters for analog signals, lower-case for digital, and first character upper-case for other signal types.
An input attribute in an instance object, contains both a pointer to the output it is connected to, and a value that can be stated. You choose whether to use the input pin and connect an output, or to set a value, with a checkbox (Used). If you choose not to mark Used,
the input pin is not displayed in the function object. In the Template object, you can set default values for the input, that will be used when the input is not connected.
Internal
Internal attributes are attributes that are not inputs or outputs. They can be used for calculated values that need to be stored in the object, or values that are used to configure the object.
All common datatypes are valid for intern attributes.
Outputs
The output attributes define the output pins of the function object, i.e. values that are storedin the object, and can be fetched by inputs of other function objects. The outputs are defined by $Output objects that are placed below the RtBody object.
The datatype for the output is stated in TypeRef. As for $Input, Boolean, Float32, Int32 and String80 can be stated, and in GraphName the text for the output pin in the function object is stated.
Note !
$Input, $Intern, and $Output have to be placed in this order below RtBody: $Input first, then $Intern and then $Output.
Code
The code for the class is a function which looks like this:
My_Fo.c
#include "pwr.h" #include "/usr/local/pwrp/cpptest/bld/common/inc/pwr_cvoldesclasses.h" #include "rt_c_plcthread.h" void IBL_exec( plc_sThread *tp, pwr_sClass_IBL *o) { o->Out = o->Factor * (*o->In1P + *o->In2P); }