The attached example demonstrates SQL Race C# functions.
The example exposes two C# functions, one with 2 input/1 output parameter(s) and another with 1 input/2 output parameter(s) (any number of input/output can be specified as required).
Use the C# Class Library project template.
The following modules must be referenced:
- OCS.Core
- SQLRace.Domain
- SQLRace.Enumerators
- SQLRace.Functions.Interfaces
- SQLRace.Functions.Types
Each function is implemented in a class that implements IDotNetFunction and is exported via the following attribute:
[Export(typeof(IDotNetFunction))]
With the following namespaces:
using MESL.SqlRace.Domain.Functions;
using MESL.SqlRace.Domain.Functions.DotNet;
using MESL.SqlRace.Enumerators;
using MESL.SqlRace.Functions.Interfaces.Enums;
using MAT.OCS.Core;
The function is defined and build in:
public void Initialize(IFunctionManager functionManager)
The function properties match those you would specify when creating a function from the editor.
Remember to assign “this” to the ImplementationDefinition.
Note: RelativePath can be set to override the location of the function within the parameter browser.
and executed in:
public void Execute(IExecutionContext executionContext)
where the timestamp of each input(s) is accessed by:
executionContext.FunctionInput.Timestamps[]
and values for each input via:
executionContext.FunctionInput.Values[][]
(input parameter index, input value)
The indexes of input parameters can be looked up by name:
executionContext.FunctionInput.InputParameterIndexes
The combined status of the inputs is accessed by:
executionContext.FunctionInput.Statuses[]
NB: if the status is DataStatusType.Missing, then assign double.NaN to the corresponding output values to indicate no value.
output values are assigned to each output parameter for each input value, via:
executionContext.FunctionOutput.OutputParametersValues[][]
(output parameter index, output value)
The indexes of output parameters can be looked up by name:
executionContext.FunctionOutput.OutputParameterIndexes
Copy just the output module to:
C:\Users\<user>\Documents\McLaren Electronic Systems\SQL Race\Functions\ or sub folder.
Restart ATLAS10 and on inspecting the parameter browser, you should see:
Additional notes
Calculation mode
functionDefinition.CalculationModeInfoDefinition.Mode = CalculationMode.FixedFrequency;
“FixedFrequency” can be replaced by "EachSamplePoint" or "HighestRate".
It is also possible to use corresponding numbers
functionDefinition.CalculationModeInfoDefinition.Mode = 0;
- 0 = EachSamplePoint
- 1 = FixedFrequency
- 2 = HighestRate
If you use FixedFrequency, the following line is to be used to set it up (Example for 1Hz):
functionDefinition.CalculationModeInfoDefinition.Frequency = 1;
Comments
0 comments
Please sign in to leave a comment.