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

Write a struct array type

This scenario guides you through the steps required to write a struct array type in the RealTime database (RTDB).

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

To write a struct array type

  1. Open the Program.cs file from the created project.
  2. Open the RTDB.
  3. Access the trendIndicatorImageSet table.
  4. Lock trendIndicatorImageSet table for reading.
  5. Locate the test record.
  6. Lock the test record reading.
  7. Access the IncreaseThresholds array field of the test record found. 
  8. Unlock the test record.
  9. Unlock the trendIndicatorImageSet table.

Example code

try
{
    IRealTimeDatabase database = new RealTimeDatabase();
    // Open the RTDB.
    if (!database.IsOpen())
    {
        database.Open();
    }
    // Access the trendIndicatorImageSet table.
    using (IRealTimeTable table = new RealTimeTable("trendIndicatorImageSet"))
    {
        ITableLockRequestType tableLockRequest = new TableLockRequestType();
        // Lock trendIndicatorImageSet table for reading.
        table.Lock(tableLockRequest.SAFE_WRITE);
        // Locate the test record.
        var nameField = new RealTimeStringField(table.Name, "name");
        using (IRealTimeRecord rtRecord = table.FindRecord(nameField, "test"))
        {
            IRecordLockRequestType recordLockRequest = new RecordLockRequestType();
            // Lock the test record reading.
            rtRecord.Lock(recordLockRequest.SAFE_WRITE);
            // Access the IncreaseThresholds array field of the test record found.
            var increaseThresholdField = new RealTimeField(table.Name, "IncreaseThresholds");
            var realtimeArrayType = new RealTimeArrayType(increaseThresholdField.GetRealTimeType().Name);
            var arrayFieldName = "IncreaseThresholds";
            var readArray = new StructRealTimeArray<ITrendIndicatorImageThreshold>(rtRecord, arrayFieldName, realtimeArrayType.ArraySize,(record, arrayElement) =>
{ return new TrendIndicatorImageThreshold(record, arrayElement); });
          
            foreach (var result in readArray)
            {
                result.Value *= 2;
                Console.WriteLine(
quot;TrendIndicatorImage IncreaseThresholds value changed:
{result.Value}"); } } // Leaving scope releases the test record lock. } // Leaving scope releases the trendIndicatorImageSet table lock. } catch (Exception ex) { Console.WriteLine(
quot;An error occurred while writing a structure array:
{ex.Message}"); }
TitleResults for “How to create a CRG?”Also Available in