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

Filter an ordered record collection with the same key value

Filter an ordered record collection with the same key value

This scenario guides you through the steps required to filter an ordered record collection with the same key value of a key field of an analog table in the RealTime database (RTDB).

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

  • GetKeyValueEqualRecordCollection methods can be called with a record number to specify the starting record to create the collection from.
  • Built-in types can be used for different type key fields. For example, RealTimeStringField class.

To filter an ordered record collection with the same key value

In this example, the RealTimeBoolField"commisioningRequired" with a value of "true" is used to filter.

  1. Open the Program.cs file from the created project.
  2. Open the RTDB.
  3. Access the analog table.
  4. Lock the analog table for reading.
  5. Lock the record for reading.
  6. Filter by key value.
  7. Process the ordered record collection.
  8. Unlock the record.
  9. Unlock the analog table.        

 Example code

IRealTimeDatabase database = new RealTimeDatabase();
try
{
    // Open the RTDB.
    if (!database.IsOpen())
    {
        database.Open();
    }

    // Access the analog table.    
    using (IRealTimeTable table = new RealTimeTable("analog"))
    {
        ITableLockRequestType lockRequest = new TableLockRequestType();
        IRecordLockRequestType recordLockRequest = new RecordLockRequestType();
        // Lock the analog table for reading.
        table.Lock(lockRequest.SAFE_READ);
        // Filter by key value.
        RealTimeBoolField nameField = new RealTimeBoolField(table.Name, "commissioningRequired");
        var orderCollection = table.GetKeyValueEqualRecordCollection(nameField, true);
      
        // Process the ordered record collection.
        foreach (var rtRecord in orderCollection)
        {
            // Lock the record for reading.
            rtRecord.Lock(recordLockRequest.SAFE_READ);
            Console.WriteLine(
quot;Name:
{rtRecord.ReadString("name")} has ptnum: {rtRecord.RecordNumber}"); rtRecord.UnLock(); } // Leaving scope releases the record lock. } // Leaving scope releases the analog table lock. } catch (Exception ex) { Console.WriteLine(
quot;Error occurred while getting the KeyValueEqualRecordCollection:
{ex.Message} has been raised"); }
TitleResults for “How to create a CRG?”Also Available in