Function Object With C Code

From Proview Wiki
Revision as of 14:20, 18 July 2014 by Sdockter (Talk | contribs)

Jump to: navigation, search

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'

GlobalVolumeForPLCFunctions.png

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 next step is to configure the custom class volume in the directory volume of the project.

  • Open the Project Directory
  • Enter Edit mode
  • Create a ClassVolumeConfig object
  • Name the new object the same name as the Custom Class Volume (in this case CVolDES)
  • Save and leave Edit mode

CustomClassVolume.png

  • Right click on the ClassVolumeConfig object and select 'Open ClassEditor...' from the menu

OpenClassEditor.png

  • Enter Edit mode
  • Create a $ClassHier object. This will automatically be named 'Class'.
  • Create a $ClassDef object in the $ClassHier object
  • Name the $ClassDef IBL
  • Right click on the newly named $ClassDef and in the popup menu select Configure->CCodeFo. This will automatically create the following objects 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.

NewFunctionClass.png
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);
}

Compiling

Linking

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox