Browse the attributes of a field
- Last UpdatedApr 08, 2026
- 2 minute read
This scenario guides you through the steps required to browse the attributes of a field.
To identify the code associated with each step, see the code comments in the Example code sections.
To browse the attributes of a field
- Open the Program.cs file from the created project.
- Add the following private global variables that will be processed in the callback:
- AutoResetEvent waitHandle = new AutoResetEvent(false);
- Create the status connection callback method to process the status of the connection call.
- Create the browse attribute callback method to process the browse attribute call by doing the following:
- Handle the output of the data returned by the browse attribute callback method if there are no errors.
- Set the state of the event to signal after processing the browse attribute callback.
- Verify that the Data Access Layer (DAL) service has initialized.
- Get the global connection.
- Block the current thread until the current instance receives a signal or the timeout expires.
- Reset the global AutoResetEvent waitHandle variable.
- Browse the topic information in the RealTime database (RTDB).
- Block the current thread until the current instance receives a signal or the timeout expires.
Example code
The following example code details creating the status connection callback.
private void StatusConnectionCallback(BaseMessage response)
{
switch (response.MessageType)
{
case DALMessageType.ConnectionDisconnectedNotification:
Console.WriteLine("Subscriber:Connection disconnected from the driver.");
break;
case DALMessageType.ConnectionEstablishedNotification:
Console.WriteLine("Subscriber:Connection established with the driver.");
break;
case DALMessageType.DataSourceConnectionNotification:
Console.WriteLine("Subscriber:Connection established with pubsub.");
waitHandle.Set();
break;
case DALMessageType.ConnectionTimeoutNotification:
Console.WriteLine("Subscriber:Connection timed out.");
break;
default:
Console.WriteLine("Subscriber:Unknown Connection notification: " + response.MessageType.ToString());
break;
}
}The following example code details creating the browse attribute callback method to process the browse attribute call.
private void BrowseAttributeCallback(String leafNodeName, DataSet data, DALPSBrowseStatus browseStatus, DALResponseStatus dalResponseStatus, Object clientObject, String failureReason)
{
// Handle the output of the data returned by the browse attribute callback method if there are no errors.
if (browseStatus == DALPSBrowseStatus.Success)
{
foreach (DataRow curRow in data.Tables[0]?.Rows)
{
var print = String.Empty;
foreach (object field in curRow.ItemArray)
{
print += field + " ";
}
Console.WriteLine(print);
}
}
else
{
Console.WriteLine("BrowseAttributeCallback: Failed to browse attribute due to " + failureReason);
}
// Set the state of the event to signaled after processing the browse attribute callback.
waitHandle.Set();
}The following example code details browsing the topic information in the RTDB.
public void BrowseAttributes()
{
try
{
// Verify that DAL service has initialized.
if (DALService.IsInitialized == false)
{
DALService.Initialize();
}
var statusConnectionDelegate = new DALConnectionStatusCallBackMethod(StatusConnectionCallback);
var browseAttributeDelegate = new DALPSConnection.DALPSBrowseAttributeDelegate(BrowseAttributeCallback);
// Get the global connection.
var psSubConn = DALPSClient.GetGlobalConnection("common", statusConnectionDelegate);
// Block the current thread until the current instance receives a signal or the timeout expires.
waitHandle.WaitOne(TimeSpan.FromSeconds(10));
if (psSubConn.IsConnected)
{
var topic = "analog.AutoCommandAnalog01.curspt";
// Reset the global AutoResetEvent waitHandle variable.
waitHandle = new AutoResetEvent(false);
// Browse the topic attributes information in the RTDB.
psSubConn.BrowseAttributes(topic, browseAttributeDelegate, this);
// Block the current thread until the current instance receives a signal or the timeout expires.
waitHandle.WaitOne(TimeSpan.FromSeconds(10));
}
}
catch (Exception e)
{
Console.WriteLine("Error:" + e.Message);
}
}