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

Retrieve an ordered or reversed record collection sorted by key

Retrieve an ordered or reversed record collection sorted by key

This scenario guides you through the steps required to retrieve an ordered or reversed record collection sorted by key for 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.

  • GetKeyRercordOrderCollection methods can be called with a record number to specify the starting record to create the collection from.
  • To get the record collection in reverse order, use the GetReverseKeyOrderRecordCollection method and the appropriate ReverseKeyOrderRecordCollection class.
  • ReverseKeyOrderRecordCollection is directly accessible without the use of the HPDBKeyOrderRecordCollection property

To retrieve an ordered record collection sorted by key

In this example, the RealTimeField key is used.

  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. Get an ordered record collection sorted by key.
  7. Process the ordered record collection sorted by key.
  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);
        // Get the ordered record collection sorted by key.
        var orderCollection = table.GetKeyOrderRecordCollection(new RealTimeField(table.Name, "name"));
        // Process the ordered record collection sorted by key.
        foreach (var rtRecord in orderCollection.HPDBKeyOrderRecordCollection)
        {
            // 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 KeyOrderRecordCollection:
{ex.Message} has been raised"); }
TitleResults for “How to create a CRG?”Also Available in