In addition to functions written in ATLAS's Function Definition Language (FDL) ATLAS 10 is able to call external interpreters to evaluate functions written in alternative languages. This guide explains how to construct a function which evaluates in the .NET runtime. This example will specifically use C#. There are two methods to call .NET functions, one way is to write a Dynamic Link Library (.DLL) containing the functions' implementations (described in this article) the other is to embed the C# code directly into an .XFN file. In ATLAS 9, to access data from .NET you must write an application which uses the ActiveX API to read the data and process it plus write it back into ATLAS. This new method takes the hard work away and leaves you to concentrate on just the function implementation rather than the method of passing data between ATLAS and .NET.
Important Notes
- It is not possible to open .XFN files containing C# .NET functions inside the ATLAS 10 Function Editor. Doing so may cause ATLAS 10 to behave abnormally.
Example
A C# .NET function can be implemented directly in a specially constructed .XFN file. Each .XFN function file can implement multiple function outputs.
The .XFN file must be in the ATLAS 10 Functions directory: %HOMEPATH%\Documents\McLaren Electronic Systems\SQL Race\Functions
To try this example:
- Download the SinAndCosOfSteeringWheelAngle.xfn file attached to this example and place it in the functions directory.
- Start ATLAS 10 (or if it is already running, restart it).
- Only one input parameter is referenced by the function aSteerWheel:Chassis so for the function to calculate, data containing this parameter must be loaded.
- Two output parameters are calculated steerWheelSin:FunctionParameters and steerWheelCos:FunctionParameters. These should now be available to add to any display from the ATLAS 10 Parameter Browser or Quick Access shortcut.
C# .NET Function .XFN File in Detail
In order to write your own C# .NET functions a template .XFN file is provided to download. The template looks like this:
Firstly the InputParameters section defines which ATLAS parameter identifiers are to be sourced by the .NET function. There should be an Identifier line for each input parameter to the function.
The OutputParameters section defines the output function parameter properties for each value the .NET function calculates. Each OutputParameter must have a Name, Description, Units, Format, DisplayMin and DisplayMax. Your .NET function can define more than one output parameter.
The calculation defaults should be left as they are, these will be described in more detail in later Help documents.
The FunctionCode section defines the actual function implementation in C#. At the top of the implementation the three using statements bring the required types into the namespace without using their fully qualified names. The IFunction interface comes from MESL.SqlRace.Domain.Functions so this must be imported. In this example System is needed for the maths functions and System.Collections.Generic is not actually needed as no collections defined by this are being used (List<> for example).
The function must define a class which implements the IFunction interface. It may be named anything you want but it is best practice to have it match the name of the XFN file which contains the class. Because each function is compiled separately there should be no name clashes though.
The interface requires an Execute() method which is called by ATLAS to calculate the function values. It is inside this method where the named output parameters get assigned their calculated values. The class can contain other methods which are called by Execute() to perform the actual calculations.
The comments in the template explain the implementation details of the C# code.
The Future
C# .NET functions are a relatively new feature in ATLAS 10 and this document is here to help you get started with the basics and preview the capabilities. It is intended that in the future the .XFN file will be generated by the ATLAS 10 Function Editor meaning it is only necessary to point ATLAS at the .M file implementation. Please use Zendesk to raise further questions.
Comments
0 comments
Please sign in to leave a comment.