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

AVEVA Enterprise SCADA PubSub API Reference

Write data into a PubSubBuffer

This scenario guides you through the steps required to write the following values in a PubSubBuffer:

  • Enumeration
  • String
  • Boolean
  • Int32
  • PubSubBuffer

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

To write into a PubSubBuffer

  1. Open the Program.cs file from the created project.
  2. Initialize a PubSubBuffer.
    The enumeration field value must be explicitly cast to a System.Byte type.
  3. Write the data into the created PubSubBuffer.
  4. Write the size and received PubSubBuffer into the created PubSubBuffer.
  5. Copy all the data to a byte array to return it.

Example code

public byte[] WriteIntoBuffer(PubSubBuffer psBuffer)
{
    // Initialize a PubSubBuffer that will contain all the data.
    var buffer = new PubSubBuffer();

    // Write the data into the created PubSubBuffer.
    // The enumeration field value must be explicitly cast to a System.Byte type.
    buffer.Write((System.Byte)DALPSMessageType.Subscribe);
    buffer.Write("TopicExample");
    buffer.Write(true);

    // Write the size and received PubSubBuffer into the created PubSubBuffer.
    var dataPtr = psBuffer.GetAllocatedBuffer();
    var psBufferLength = psBuffer.GetUsedBufferBytes();
    buffer.Write(psBufferLength);
    buffer.WriteBlob(dataPtr, psBufferLength);

    // Copy all the data to a byte array to return it.
    var ptr = buffer.GetAllocatedBuffer();
    var size = buffer.GetUsedBufferBytes();
    var returnData = new byte[size];
    Array.Copy(ptr, returnData, size);
    return returnData;
}
TitleResults for “How to create a CRG?”Also Available in