Subscribe to and read a flag structure
- Last UpdatedApr 08, 2026
- 1 minute read
This scenario guides you through the steps required to subscribe to and read a flag structure.
To identify the code associated with each step, see the code comments in the Example code section.
To subscribe to and read a flag structure
- Open the Program.cs file from the created project.
- Open a PubSub connection.
- Confirm there is a connection with the PubSub system.
- Subscribe to the "flag.packqual" PubSub topic.
- Receive a PubSub message.
- Process the PubSub message.
- Unsubscribe from the topic by disposing the connection.
Example code
internal void AddSubscriptionAndReadFlagStructure()
{
try
{
IPubSubConnectionFactory pubSubConnectionFactory = new PubSubConnectionFactory();
// Open a PubSub connection.
using (var pubsubConnection = pubSubConnectionFactory.OpenConnection())
{
// Confirm there is a connection with the PubSub system.
if (pubsubConnection.IsConnected())
{
var topic = "es.realtime.db.analog.DeviceRollupAnalog01.flag.packqual";
// Subscribe to a topic.
var subscription = pubsubConnection.Subscribe(topic);
// Receive a PubSub message.
var pubSubMsg = subscription.Receive();
// Process the PubSub message.
byte[] blobByteArray = pubSubMsg.GetBlob();
FlagPackQual flagPackQual = new FlagPackQual();
flagPackQual.CompactedFlags = blobByteArray;
Console.WriteLine(quot;Current topic is in Manual Mode: {flagPackQual.Manual}");
}
}// Unsubscribe from the topic by disposing the connection.
}
catch (Exception ex)
{
Console.WriteLine("Error:" + ex.Message);
}
}