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

Krunch a value into a record

This scenario guides you through the steps required in krunching a value into a record 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 RealTime database (RTDB).
  3. Review the list of additional namespaces needed for the desired scenario.

    using OASySDNA.RealTime.Data.Common.HighPerformanceDBWrapper.Interfaces;
    using OASySDNA.RealTime.Data.Common.HighPerformanceSetDBWrapper;
    using OASySDNA.RealTime.Data.Common.HighPerformanceSetDBWrapper.Interfaces;
    using OASySDNA.RealTime.HighPerformanceDB;
  4. Resolve ambiguous references.

    using RealTimeDatabase = OASySDNA.RealTime.Data.Common.HighPerformanceDBWrapper.RealTimeDatabase;
    using RealTimeTable = OASySDNA.RealTime.Data.Common.HighPerformanceDBWrapper.RealTimeTable;

To krunch a value into a record

  1. Find the analog record to krunch, by name.
  2. Lock the analog record for writing.
  3. Prepare to krunch the data.
  4. Krunch the analog data into the record.
  5. Review the old and new values.
  6. Unlock the record.
  7. Unlock the table.

Example code

try
{
    IRealTimeDatabase database = new RealTimeDatabase();
    // Open the RTDB.
    if (!database.IsOpen()
    {
        database.Open();
    }
    using (IRealTimeTable table = new RealTimeTable("analog"))
    {
            ITableLockRequestType tableLockRequest = new TableLockRequestType();
            // Lock the analog table for reading.
            table.Lock(tableLockRequest.SAFE_READ);
            // Find the analog record to krunch, by name.
            var nameField = new RealTimeStringField(table.Name, "name");
            using (IRealTimeRecord record = table.FindRecord(nameField, "AutoCommandAnalog01"))
            {
                IRecordLockRequestType recordLockRequest = new RecordLockRequestType();
                // Lock the analog record for writing.
                record.Lock(recordLockRequest.SAFE_WRITE);
                // Prepare to krunch data.
                var krunchDescriptor = new KrunchDescriptor();
                record.GetKrunchDescriptor(krunchDescriptor);
                krunchDescriptor.putAnaVal(515);
                var curvalOldValue = record.ReadField<Double>("curval");
                var currentTime = TimeStamp.Now();
                // Krunch the analog data into the record.
                record.Krunch(currentTime, krunchDescriptor, HilowStates.HILOW_OK, false, false);
                // Review the old and new values.
                var curvalNewValue = record.ReadField<Double>("curval");
                Console.WriteLine(
quot;Curval previous value:
{curvalOldValue} changed to: {curvalNewValue}"); } // Leaving scope releases the record lock. } // Leaving scope releases the table lock. } catch (Exception ex) { Console.WriteLine(
quot;Failed while trying to krunch due to:
{ex.Message}"); }
TitleResults for “How to create a CRG?”Also Available in