Read and modify a slot field
- Last UpdatedApr 08, 2026
- 1 minute read
This scenario guides you through the steps required to read and modify a slot-type field of an analog record in the RealTime database (RTDB).
To identify the code associated with each step, see the code comments in the Example code section.
To read and modify a slot field
- Open the Program.cs file from the created project.
- Open the RTDB.
- Access the analog table.
- Lock the analog record for writing.
- Get the slot field of a record.
- Lock the record for writing.
- Modify the record.
- Unlock the record.
- 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 tableLockRequest = new TableLockRequestType();
// Lock the analog table for writing.
table.Lock(tableLockRequest.SAFE_WRITE);
// Get the slot field of a record.
using (IRealTimeRecord record = new RealTimeRecord(table, 28))
{
IRecordLockRequestType recordLockRequest = new RecordLockRequestType();
// Lock the record for writing.
record.Lock(recordLockRequest.SAFE_WRITE);
// Modify the record.
var rtuSlot = record.ReadField<Int32>("rtu");
record.WriteField<Int32>("rtu", 10);
Console.WriteLine(quot;Rtu changed from {rtuSlot} to: {record.ReadField<Int32>("rtu")}");
} // Leaving scope releases the record lock.
} // Leaving scope releases the analog table lock.
}
catch (Exception ex)
{
Console.WriteLine(quot;An error occurred while reading/writing the slot field: {ex.Message}");
}