Part 3 - Equipment types

This article is a part of the "Creating an equipment model" tutorial

Now that we can connect to the database, we can start defining equipment types. The system consists of two tanks, pipes, and a pump. The tanks and pipes are mechanical devices, and the pump is an electrical device. The example devices have a model type hierarchy as follows.

Device
├── Electrical device
│   └── Pump
└── Mechanical device
    ├── Pipe
    └── Tank

Each equipment type has a common "manufacturer" property, so it might be convenient to make it an inherited property that is defined only once for all equipment types devised from the "Device" type. The other properties are not shared so that they can be defined for each equipment type as appropriate.

New equipment types can be easily created and defined using the data abstraction interface VtrinLib. The following code snippet creates a new equipment type called "Device".

var baseEquipmentType = (ABB.Vtrin.Interfaces.IEquipment)RTDBDriver.Classes["Equipment"].Instances.Add();
baseEquipmentType.Name = "Device";
baseEquipmentType.CommitChanges();

Once created, another equipment type can be created, which inherits from the base type that was just created. Let's create a "Mechanical device". Note that "Mechanical device" uses "Device" (baseEquipmentType) as a base equipment.

var mechanicalDeviceType = (ABB.Vtrin.Interfaces.IEquipment)driver.Classes["Equipment"].Instances.Add();
mechanicalDeviceType.Name = "Mechanical device";
mechanicalDeviceType.Base = baseEquipmentType;
mechanicalDeviceType.CommitChanges();

Implementing the full method

When adding multiple equipment types, the code will become more and more repetitive. Thus, it makes sense to create a helper method CreateOrUpdateEquipmentType. This method will create a new equipment type if it doesn't already exist. Otherwise, it will update the existing equipment type. This kind of method makes creating equipment types more straight forward.

private static ABB.Vtrin.Interfaces.IEquipment CreateOrUpdateEquipmentType(
    string equipmentTypeName,
    bool isAbstract = false,
    ABB.Vtrin.Interfaces.IEquipment baseEquipmentType = null)
{
    var equipmentCache = RTDBDriver.Classes["Equipment"].Instances;

    // Try to find existing equipment type with the given name
    var equipmentType =
        (ABB.Vtrin.Interfaces.IEquipment)equipmentCache[equipmentTypeName]?.BeginUpdate();

    // Case: No existing equipment type found
    // > Create a new equipment type
    if (equipmentType == null)
        equipmentType = (ABB.Vtrin.Interfaces.IEquipment)equipmentCache.Add();

    // Update attributes and commit changes
    equipmentType.Name = equipmentTypeName;
    equipmentType.Base = baseEquipmentType;
    equipmentType.Abstract = isAbstract;
    equipmentType.CommitChanges();

    return equipmentType;
}

Now equipment types can be defined the following way.

// Abstract base types
// ===================

var baseEquipmentType = CreateOrUpdateEquipmentType(
    equipmentTypeName: "Device",
    isAbstract: true);

var mechanicalEquipmentType = CreateOrUpdateEquipmentType(
    equipmentTypeName: "Mechanical device",
    baseEquipmentType: baseEquipmentType,
    isAbstract: true);

var electricalEquipmentType = CreateOrUpdateEquipmentType(
    equipmentTypeName: "Electrical device",
    baseEquipmentType: baseEquipmentType,
    isAbstract: true);

// Equipment types
// ===============

var tankType = CreateOrUpdateEquipmentType(
    equipmentTypeName: "Tank",
    baseEquipmentType: mechanicalEquipmentType);

var pipeType = CreateOrUpdateEquipmentType(
    equipmentTypeName: "Pipe",
    baseEquipmentType: mechanicalEquipmentType);

var pumpType = CreateOrUpdateEquipmentType(
    equipmentTypeName: "Pump",
    baseEquipmentType: electricalEquipmentType);

What do we have now?

After running the complete code, you should have equipment types defined. Rerunning the code will update existing equipment types, so it is perfectly safe to do. At this point, you might want to check what you have actually created. Open your browser, navigate to the address https://<RTDB-host-address>/history. Your browser will prompt username and password. Just type in your database admin username and password (Same as RTDBUsername and RTDBPassword).

After logging in to Engineering UI, select "Configuration" > "Equipment types" from the navigation bar on the left. You should now see the list of all equipment types defined above among all the default equipment types.

Name

Base

Abstract

Class name

Device

Yes

Path_Device

Electrical device

Device

Yes

Path_Electrical device

Mechanical device

Device

Yes

Path_Mechanical device

Pipe

Mechanical device

No

Path_Pipe

Tank

Mechanical device

No

Path_Tank

Pump

Electrical device

No

Path_Pump

📘

Compare your code

This tutorial is following the code that can be found from our GitHub repository. Checking out the full example code is highly recommended.