Skip to content

ClassType

class ClassType

The ClassType enables the implementation of object oriented patterns in the application. This type can be used for both local controller variables and variables in the interfaces of a controller. A ClassType instance can extend an existing ClassType instance.

Create ClassType

image2019-11-6_11-25-29

Member

A member is a field like a field in a RecordType. A member is 'protected', i.e. a member is not read or written from the outside. In order to make a member publicly readable or writable, so-called getters and setters can be defined for each member:

image2019-11-6_14-17-56

With these properties the access to the members is defined.

Method

A method is a function within the ClassType. A method can have local variables, but can also access the members.

In addition, a method can have input and in/out parameters. By assigning a value to the method name, values from the method can be returned.

image2019-11-6_14-24-58

ClassType inheritance

A ClassType can be inherited. By specifying a ClassType as the base class, all its elements are made accessible in the derived ClassType.

The SUPER keyword can be used to access the method of the base class.

image2019-11-6_14-32-14

In the derived class, you can overwrite methods from the base class.

image2019-11-6_14-38-45

Instantiation

A ClassType is instantiated like any other type.

image2019-11-6_14-34-15

Within a code snippet, the methods and properties of a ClassType can be accessed.

image2019-11-6_14-43-5

Further properties

Example

Improved user experience while integrating an existing library implemented as B&R Library. Example with a function block instance (PfcConveyor) which requires some init properties and based on instance there are a few routines to get some information about instance.

Integration without class type (status quo)

pfc-conveyor

pfc-get-conveyor-post-ready

// initialization
pfcConveyor.input.pfcInstanceName = 'myProductFlow';
pfcConveyor.input.conveyorId = 1;
pfcConveyor();

// get some information based on function block instance above
if (fPfcGetConveyorPostReady(conveyor.output.pfcHandle, conveyor.output.conveyorHandle, switchPosition)) {
  // insert code here
}

Required code at application to integrate function block. Since B&R has no method support at function blocks. Global functions are declared to execute some information getter routines.

Disadvantages

  • Some handles or references function properties are required to create link between function block instance and function call.
  • A lot of declared global functions, their usage is only valid with a specific instance of some class (PfcConveyor in this case). Hard to find exact global function, which is the right one for given function block instance.

Improved integration with class type wrapper

Existing B&R Library with given function blocks and global functions called at class type wrapper here. Wrapper supports easy access for application developper while accessing library.

wrapper-class

// initialization
pfcConveyor.init('myProductFlow', 1);

// get some information based on function block instance above
if (pfcConveyor.getConveyorPostReady(switchPosition)) {
  // insert code here
}

pfcConveyor is here an instance of class type wrapper (PfConveyorClass) instead of function block type (PfcConveyor).

Advantages

  • Less code required at application
  • Easy to find method with content assist call at function block instance (pfcConveyor).