Krunch a value into a record
- Last UpdatedApr 08, 2026
- 2 minute read
This scenario guides you through the steps required in krunching a value into a record in the RealTime database (RTDB).
To identify the code associated with each step, see the code comments in the Example code section.
Before you begin
- Open the Program.cs file from the created project.
- Open the RealTime database (RTDB).
- Review the list of additional namespaces needed for the desired scenario.
using OASySDNA.RealTime.Data.Common.HighPerformanceDBWrapper.Interfaces; using OASySDNA.RealTime.Data.Common.HighPerformanceSetDBWrapper; using OASySDNA.RealTime.Data.Common.HighPerformanceSetDBWrapper.Interfaces; using OASySDNA.RealTime.HighPerformanceDB; - Resolve ambiguous references.
using RealTimeDatabase = OASySDNA.RealTime.Data.Common.HighPerformanceDBWrapper.RealTimeDatabase; using RealTimeTable = OASySDNA.RealTime.Data.Common.HighPerformanceDBWrapper.RealTimeTable;
To krunch a value into a record
- Find the analog record to krunch, by name.
- Lock the analog record for writing.
- Prepare to krunch the data.
- Krunch the analog data into the record.
- Review the old and new values.
- Unlock the record.
- Unlock the table.
Example code
try
{
IRealTimeDatabase database = new RealTimeDatabase();
// Open the RTDB.
if (!database.IsOpen()
{
database.Open();
}
using (IRealTimeTable table = new RealTimeTable("analog"))
{
ITableLockRequestType tableLockRequest = new TableLockRequestType();
// Lock the analog table for reading.
table.Lock(tableLockRequest.SAFE_READ);
// Find the analog record to krunch, by name.
var nameField = new RealTimeStringField(table.Name, "name");
using (IRealTimeRecord record = table.FindRecord(nameField, "AutoCommandAnalog01"))
{
IRecordLockRequestType recordLockRequest = new RecordLockRequestType();
// Lock the analog record for writing.
record.Lock(recordLockRequest.SAFE_WRITE);
// Prepare to krunch data.
var krunchDescriptor = new KrunchDescriptor();
record.GetKrunchDescriptor(krunchDescriptor);
krunchDescriptor.putAnaVal(515);
var curvalOldValue = record.ReadField<Double>("curval");
var currentTime = TimeStamp.Now();
// Krunch the analog data into the record.
record.Krunch(currentTime, krunchDescriptor, HilowStates.HILOW_OK, false, false);
// Review the old and new values.
var curvalNewValue = record.ReadField<Double>("curval");
Console.WriteLine(quot;Curval previous value: {curvalOldValue} changed to: {curvalNewValue}");
} // Leaving scope releases the record lock.
} // Leaving scope releases the table lock.
}
catch (Exception ex)
{
Console.WriteLine(quot;Failed while trying to krunch due to: {ex.Message}");
}