Function Object With C Code

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

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Create a Class Volume

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.

The class definition objects reside in a class volume, and first the class volume has to be registered and created. The registration is performed in the Global Volume list which is opened from File->Open->GlobalVolumeList in the Project List window. Here you create a VolumeReg object with a suitable volume name and volume identity. The volume identity for user created class volumes should be within the interval 0.0.2-249.1-254. The prefix CVol for the name should be used since it is the preferred method indicate that it is a class volume. The current project also needs to be defined.

Function Object Classes

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);
}

Compiling

Linking

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox