Override a Baseline Data Type Converter
- Last UpdatedApr 08, 2026
- 2 minute read
This scenario guides you through the steps required to override a baseline Data Type Converter.
To identify the code associated with each instruction, see the code comments in the Example code section.
Overriding a baseline Data Type Converter
- Within your custom development workspace, locate the source for the Data Type Converter you want to modify. The converter source will be located within a KrunchDataStream\ KrunchDataStream\OASySDNA.RealTime.KrunchDataTypeConverters folder under the RealTime silo. For example:
C:\OASySDev\RealTime\source\KrunchDataStream\OASySDNA.RealTime.KrunchDataTypeConverters
- In the created project used to modify converter code, open or create the class file using a copy of the baseline Data Type Converter. In the example, a copy of the DefaultUInt16Converter.cs file is renamed to CustomUInt16Converter.cs.
- Rename the class to the name of your modified version of the converter.
Renaming the converter is not required, but is performed here for illustrative purposes.
- Set the DataTypeName member to the name of your converter.
- Modify the code within the converter as desired.
Example code
using System;
using OASySDNA.RealTime.Data.Model;
using OASySDNA.RealTime.ExecutionPipelines.KrunchCommon.Context;
using OASySDNA.RealTime.ExecutionPipelines.KrunchDataStream.Context;
using OASySDNA.RealTime.ExecutionPipelines.KrunchDataStream.ConverterFramework;
namespace OASySDNA.RealTime.KrunchDataTypeConverters
{
//Rename the class to the name of your modified version of the converter.
//Renaming the converter is not required, but is performed here for illustrative purposes.
public sealed class CustomUInt16Converter : IKrunchDataTypeConverter
{
//Set the DataTypeName member to the name of your converter.
public String DataTypeName { get; } = "CustomUInt16Converter";
public Double Convert(KrunchContext context)
{
if (((AnalogKrunchDataStreamParameters)context.TableParameters).KrunchData.Length < sizeof(UInt16))
{
context.AdditionalParameters.Update("InstrumentFailFlag", Hilowstate.HILOW_INS_HIGH);
return 0.0;
}
else
{
var truncatedByteArray = new Byte[] { 0, 0 };
if (((AnalogKrunchDataStreamParameters)context.TableParameters).KrunchData.Length > sizeof(UInt16))
{
Array.Copy(((AnalogKrunchDataStreamParameters)context.TableParameters).KrunchData, truncatedByteArray, truncatedByteArray.Length);
}
else
{
truncatedByteArray = ((AnalogKrunchDataStreamParameters)context.TableParameters).KrunchData;
}
//Modify the code within the converter as desired.
//Order the byte array.
var orderedByte = DataStreamByteOrder.ConvertFromMSB(truncatedByteArray);
//Decode the byte array.
var decodedValue = BitConverter.ToUInt16(orderedByte, 0);
//If it is the maximum value, it is an instrumentation failure.
if (decodedValue == UInt16.MaxValue)
{
context.AdditionalParameters.Update("InstrumentFailFlag", Hilowstate.HILOW_INS_HIGH);
return 0.0;
}
return decodedValue;
}
}
}
}