Directly access the RealTime database (RTDB)
- Last UpdatedApr 24, 2025
- 2 minute read
In some cases it may be more efficient to directly access the RealTime database (RTDB), instead of using the Microsoft SQL Engine (Object Linking and Embedding database (OLE DB) access).
The following example shows how components can access RTDB using the RealTime High Performance database (HPDB) classes. The component takes two status points as input. The status points must be two-bit input status points. The component returns the four-bit status represented by the combination of the two points.
In order to run this example, you must add a .NET reference to OASySDNA.RealTime.HighPerformanceSetDB and OASySDNA.RealTime.HighPerformanceDB. You must also add the following line at the top of the <name>Processor file (C# code):
using OASySDNA.RealTime.HighPerformanceSetDB;
using OASySDNA.RealTime;
using OASySDNA.RealTime.HighPerformanceDB;
In addition, the component must be installed on all computers that host the RealTime service and the component must run on the Hot RealTime computer.
Constructor
this.Parameters = new BLTParameterList();
this.Parameters.Add(new BLTParameter(
"Status1Name",typeof (string),false,false));
this.Parameters.Add(new BLTParameter(
"Status2Name",typeof (string),false,false));
this.Parameters.Add(new BLTParameter("Result",typeof (int),false,true));
Process() method
bool bAnyFeed1;
bool bAnyFeed2;
byte bytBitWidth1;
byte bytBitWidth2;
byte bStatus1Value;
byte bStatus2Value;
int bStatusRetval;
// Get the input parameters
string szStatus1Name = this.Parameters.Item(0).Value.ToString();
string szStatus2Name = this.Parameters.Item(1).Value.ToString();
// Open the Realtime database as the default user (required)
OASySDNA.RealTime.HighPerformance.RealTimeDatabase.Open();
// Bind to the status table
RealTimeTable rtStatus=new RealTimeTable("status");
// Create a key field for the status.name field
RealTimeStringField rtfName = new RealTimeStringField(rtStatus,"name");
// Lock the status table for SAFE_READ
rtStatus.Lock(TableLockRequestType.SAFE_READ,0);
// Find the status records we need
RealTimeRecord rtrecStatus1 = rtStatus.FindRecord(rtfName,szStatus1Name);
RealTimeRecord rtrecStatus2 = rtStatus.FindRecord(rtfName,szStatus2Name);
// Lock the status records we need
// Wrap the following in a try-catch block so that we can unlock the
status table and records even if an exception occurs (the Lock methods throw an exception if the lock cannot be achieved).
try
{
rtrecStatus1.Lock(RecordLockRequestType.SAFE_READ,0);
rtrecStatus2.Lock(RecordLockRequestType.SAFE_READ,0);
// Get the field values that we need bAnyFeed1 = rtrecStatus1.ReadBool("anyfeed");
bytBitWidth1 = rtrecStatus1.ReadByte("inbit.bitwi");
bAnyFeed2 = rtrecStatus2.ReadBool("anyfeed");
bytBitWidth2 = rtrecStatus2.ReadByte("inbit.bitwi");
if(bAnyFeed1 && bAnyFeed2 &&(bytBitWidth1 == 2) && (bytBitWidth2 == 2))
{
bStatus1Value = rtrecStatus1.ReadByte("cursta");
bStatus2Value = rtrecStatus2.ReadByte("cursta");
this.Parameters.Item(2).Value = bStatusRetval;
bStatusRetval = bStatus1Value | bStatus2Value;
}
}
catch(System.Exception e)
{
// Let the BLT error handler handle the exception.
throw(e);
}
finally
{
// Unlock the status records
if(rtrecStatus1.Locked)
{rtrecStatus1.UnLock();}
if(rtrecStatus2.Locked){rtrecStatus2.UnLock();}
if(rtStatus.Locked
{
// Unlock the status table.
rtStatus.UnLock();
}
}