Skip to content

Program Organization unit

Ob

Ob blocks can have different meaning depending on how a plc manufacturer implements it.

In Vif, Ob is just an entry point to your program and serve no other purposes, they can be seen as multiple Main functions.

Obs won't appear in the output code of the provider compiler and only exists for testing purposes.

Ob has 2 parameters:

  • interface where you declare the interface of your Ob, can be:
    • temp, constant.
  • body where you declare the operations as an Array of operations.
ts
import {
Ob
} from "#pou"

Since Ob blocks cannot be referenced from the outside, you can inline them directly in your CreateSource function.

ts
export default 
BuildSource
({
blocks
: {
"MyFb":
MyFb
,
"MyOb": new
Ob
({
interface
: {
temp
: {
MyBool
: new
Bool
()}
},
body
() {
return [] } }) } })

INFO

When you start the simulation, vif-sim needs the name of one Ob block which will be the entry point of the simulation.

So if you register multiple Ob blocks, you can write different configurations of the same program.

Fb

ts
import {
Fb
} from "#pou"

Standard Function Block, in which you can define an interface and operations. This block cannot be called directly in your operations, you first need to create an instance or an instanceDb.

Fb has 3 parameters:

  • interface where you declare the interface of your Fb, can be:
    • input, output, inout, static, temp, constant.
  • body where you declare the operations as an Array of operations.
  • attributes provider specific.

Fb has to be declared globally in a CreateSource object and has to be instanced with either InstanceDb or Instance.

Then, you need to use the Call operation to activate the instance in a block operations?

ts
import {
Fb
} from "#pou"
import {
Assign
} from "#basics"
import {
Bool
} from "#primitives"
const
MyFb
= new
Fb
({
interface
: {
static
: {
"MyVar": new
Bool
(true)
} },
body
() {
return [new
Assign
(this.
static
.
MyVar
, false)]
} })

Fc

ts
import {
Fc
} from "#pou"

Standard function that can be called directly without instance.

Works the same as Fb except it does not have a static field but contains a return field.

Fc can be called directly without being instanced.

ts
import {
Fc
} from "#pou"
import {
Assign
} from "#basics"
import {
Bool
} from "#primitives"
const
MyFc
= new
Fc
({
interface
: {
temp
: {
"MyVar": new
Bool
(true)
} },
body
() {
return [new
Assign
(this.
temp
.
MyVar
, false)]
} })

Udt

An User-Defined Data type, basically a globally declared struct which then can be implemented in a block interface or with an InstanceDb.

ts
import {
Udt
} from "#pou"
import {
Assign
} from "#basics"
import {
Bool
} from "#primitives"
const
MyUdt
= new
Udt
({
"MyVar": new
Bool
()
})

InstanceDb

An instance of Fb but can be accessed everywhere.

ts
import {
Fb
,
InstanceDb
} from "#pou"
import {
Bool
} from "#primitives"
const
MyFb
= new
Fb
({
interface
: {
input
: {
"MyVar": new
Bool
()
} } }) const
MyInstanceDb
= new
InstanceDb
(
MyFb
)

GlobalDb

A DataBlock with arbitrary values or Udt inside that can be accessed everywhere.

ts
import {
GlobalDb
} from "#pou"
import {
Bool
,
Int
} from "#primitives"
const
MyGlobalDb
= new
GlobalDb
({
"MyFirstVar": new
Bool
(),
"MySecondVar": new
Int
()
})