Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA Enterprise SCADA High Performance Database (HPDB) API Reference

Create a device timer in the Secondtimer table for Setpoint and command timeouts

Create a device timer in the Secondtimer table for Setpoint and command timeouts

This scenario guides you through the steps required to create a device timer for a record in a new telemetered table in the RealTime database (RTDB).

To identify the code associated with each step, see the code comments in the Example code section.

Before you begin

  1. Open the Program.cs file from the created project.
  2. Open the RTDB.
  3. Review the list of additional namespaces needed for the desired scenario.

    using System;
    using System.Runtime.InteropServices;
    using OASySDNA.RealTime.Data.Common.HighPerformanceDBWrapper;
    using OASySDNA.RealTime.Data.Common.HighPerformanceDBWrapper.Interfaces;
    using OASySDNA.RealTime.Data.Common.HighPerformanceSetDBWrapper;
    using OASySDNA.RealTime.Data.Common.HighPerformanceSetDBWrapper.Interfaces;
  4. Resolve the use of external functions by adding the following code:

    [DllImport("libvdb.dll", EntryPoint = "?secondTricre@@YAHHPEADHHH@Z", ExactSpelling = true)]
    private static extern Int32 secondTricre(Int32 init, String func, Int32 parm, Int32 dataset, Int32 warnPeriod);
    [DllImport("libvdb.dll", EntryPoint = "?secondTrvdel@@YAXH@Z", ExactSpelling = true)]
    private static extern void secondTrvdel(Int32 num);
  5. Use the secondTricre method to create a new device timer in the Secondtimer table.
    A callback function must be sent to the secondTricre method when it is invoked.

    In this example, myDLL.dll contains the callback function.

    Only extensions written in C++ are supported.

  6. Make the extension visible to the Secondtimer by adding the extension to the RealTime_extension.json into the TimerCallbacks setting section:

    "TimerCallbacks": {
      myDLL.dll: true
    },

To create a device timer in the Secondtimer table

The new telemetered table used in this scenario is myTable, which contains the fields timerslot(secondtimer slot#) and timeout(expire command time in seconds) needed in this example.

  1. Access the myTable table.
  2. Lock myTable table for reading.
  3. Locate the myTable record by name to create a new device timer.
  4. Get the record number.
    This record number will be used as an input parameter for the timer.
  5. Lock the myTable record for writing.
  6. Read the timerslot, and check if any device timers are running.
  7. Delete the old device timer if one is already running.  
  8. Create a new device timer in the Secondtimer table.
  9. Link the device timer to the myTable record by writing the new Secondtimer slot. 
  10. Unlock the myTable record. 
  11. Unlock the myTable table.  

Example code

try
{
    IRealTimeDatabase database = new RealTimeDatabase();
    // Open the RTDB.
    if (!database.IsOpen())
    {
        database.Open();
    }
    // Access the myTable table.
    using (IRealTimeTable table = new RealTimeTable("myTable"))
    {
        ITableLockRequestType tableLockRequest = new TableLockRequestType();
        IRecordLockRequestType recordLockRequest = new RecordLockRequestType();
        // Lock the myTable table for reading.
        table.Lock(tableLockRequest.SAFE_READ);
        // Locate the myTable record by name to create a new device timer.
        var nameField = new RealTimeStringField(table, "name");
        using (var record = table.FindRecord(nameField, "myPoint_1"))
        {
            // Get the record number. 
            var param0 = record.RecordNumber;
            // Lock the myTable record for writing.
            record.Lock(recordLockRequest.SAFE_WRITE);
            // Read the timerslot, and check if any device timers are running.
            if (record.ReadField<Int32>("timerslot") > 0)
            {
                 // Delete the old device timer.
                 secondTrvdel(record.ReadField<Int32>("timerslot"));
            }
            // Create a new device timer in the secondtimer table.
            var newTimerSlot = secondTricre(record.ReadField<ushort>("timeout"), "mycallback", param0, record.ReadField<Int32>("dataset"),0);
            // Link the device timer to the myTable record by writing the new secondtimer slot.
            record.WriteField<Int32>("timerslot", newTimerSlot);
        } // Leaving scope releases the myTable record lock.
    } // Leaving scope releases the myTable table lock.
}
catch (Exception ex)
{
    Console.WriteLine(
quot;Error creating a device timer in the secondtimer table:
{ex.Message}"); result = false; }
TitleResults for “How to create a CRG?”Also Available in