I2 API User Guide
I2 API User Guide
4 API
USER GUIDE
Introduction.................................................................................................. 2
Overview ...................................................................................................... 7
Types ............................................................................................................ 8
Classes ........................................................................................................ 10
Interfaces.................................................................................................... 11
Example ...................................................................................................... 36
Appendix .................................................................................................... 37
i2 Math API.................................................................................................. 37
Range Groups .............................................................................................. 41
Object Model Reference .............................................................................. 42
Page 1
INTRODUCTION
This document provides an overview of the MoTeC i2 API Licence installation, activation and general use.
On installation (x64), the sample files are located in the following folder:
C:\Program Files\MoTeC\i2\1.1\Samples\i2API
Page 2
i2 API INSTALLATION AND ACTIVATION
Installation
1. Install the latest release version of i2 Pro from http://www.motec.com/software/latestreleases/.
2. Start i2 Pro and open a Workspace. If no Workspaces exist in i2 Pro, create a new one via the File > Workspace > New
Workspace… menu.
3. Once a Workspace is open, go to the Help > Licences menu and click on the Request button.
4. In the Request a Licence window, enter your Name and Company, select i2 API and select OK. See Figure 1.
Note: The i2 Licence is issued for the specific computer and will need to be updated if the computer hardware
changes.
Page 3
If you are using an email client (like Outlook or similar), the Licence request email is created automatically after
clicking Yes in the Confirmation window.
Note: If there is no email client running on your computer, a file with instructions will open. Create an email by
following the instructions given.
5. Verify that the Licence request file i2.mtcreq is attached to the email.
6. Send the email to your MoTeC dealer.
The dealer will respond by sending you a Licence Activation file.
Activation
7. On receiving the Licence Activation file from your dealer, save the file to your computer.
8. Start i2 Pro and open a Workspace.
9. Go to the Help > Licences menu. The Feature Licences window displays.
10. Select the Load button and select the Licence Activation file.
After the Licence is activated, i2 API appears in the Feature Licences list with the number of days for which the Licence is
valid. Ensure the Activation Serial No is shown at the top of the window.
Page 4
USING THE SAMPLES
C#
1. To select the C# sample file, go to: C:\Program Files\MoTeC\i2\1.1\Samples\i2API\C#.
2. Double click on the i2API.sln file.
If Visual Studio is installed and associated with *.sln files, the sample file will open in the Visual Studio IDE.
Note: If i2 Pro is installed properly and the i2 API Licence is activated, you will be able to compile and run the sample
program.
MATLAB
1. To select the MATLAB sample file, go to: C:\Program Files\MoTeC\i2\1.1\Samples\i2API\MATLAB.
2. Double click on the i2API.m file.
If MATLAB is installed and associated with *.m files, the sample file will open in the MATLAB editor.
Note: If i2 Pro is installed properly and the i2 API Licence is activated, you will be able to compile and run the sample
program.
Troubleshooting
The most common error relates to MATLAB being unable to create the OLE Automation server for the i2 Pro API.
The error usually occurs at the line i2 = actxserver('MoTeC.i2Application'); and the error message is something like
“ActiveX - Invalid ProgID ‘MoTec.i2Application’”.
This issue may be caused by:
incomplete i2 API registration (may require administrator privileges)
32/64 bit interop failure
If the error persists, or support is required, please send an email to [email protected]. It is always helpful to attach
screenshots and an example of the code that highlights the problem.
Note: By default, the i2 API loads the most recently used i2 Pro Workspace.
Page 5
i2 NAMESPACE OBJECT DEFINITIONS
Introduction
This section outlines the object and interface definitions within the “i2” namespace.
Note: Parts of the i2 API are also used by i2 Pro External Maths Plug-ins and External Maths Functions which are discussed
at the end of this document.
Scope
The definitions below are written against “MoTeC i2 2.3 Type Library” unless specified otherwise.
Items marked as “Internal Use Only” are not expected to be used by third parties and are thus not fully documented.
Some programming knowledge is expected. Terms such as Instantiation, Namespace, Class, Method and Property are used
throughout this section.
Notes
Be sure to add the latest i2 Type Library as a reference to all .NET based projects.
All time values (unless stated otherwise) are in microseconds [ µs ].
Page 6
OVERVIEW
The following diagram illustrates the main interfaces and connections associated with the i2 API.
Page 7
TYPES
The following enumerations are used by the classes and interfaces described throughout this document.
AntiAliasFilterType
aaNone
aaAvg
aaMin
aaMax
ChannelStatus
Valid
Invalid
Dimension
Array
Scalar
EDataExtent
deMainRange
deMainRangeOuting
deMainRangeZoom
ESampleRateOpt
srCustom
srDefault
srFastest
Page 8
The following types provide string constants to be used by some API methods:
DataType
Integer = “MoTeC.Integer”
Real = “MoTeC.Float”
String = “MoTeC.String”
Layer
Burst0 = “Burst0”
Burst1 = “Burst1”
Details = “Details”
Fastest = “Fastest”
Normal = “”
SetupSheet = “SetupSheet”
Page 9
CLASSES
The following classes represent the primary entry point into the i2 API. Once instantiated, these instances will provide the
ability to create, read and update data within i2.
Application
Class denoting an instance of the i2 application. It connects to an already running instance of the i2 application, or starts
one if not.
Example ( C# )
var i2 = new i2.Application();
i2.Visible = true;
i2.Exit();
ApplicationSingle
Class denoting an instance of the i2 application. Unlike the Application class, it always creates a new instance of an i2
application. It implements same properties and methods as the Application class.
Example ( C# )
var i2 = new i2.ApplicationSingle();
i2.Visible = true;
i2.Exit();
Page 10
INTERFACES
The following interfaces, in combination, make up what is known as the i2 API.
IMtcApplication
The generic MoTeC application interface.
Properties
Name Type Description
Name string Get the application name
Methods
Name Parameters Description
void
Exit()
void
ShowHelp()
void
ShowHelpAbout()
Page 11
IMtcChannel
Represents a channel in i2.
Properties
Name Type Description
DataArray IMtcDataArray Get/Set the data array (samples)
associated with this channel
Methods
Name Parameters Description
IMtcDataArray SampleRate: usually between 1 – 1000
CreateDataArray( Hz
double SampleRate
) A buffer is created with enough space
to store samples at this rate for the
time extent of the data source
Creates a DataArray for this channel definition, based on
the sample rate required
Page 12
IMtcChannel2
Extends the IMtcChannel interface with the following properties. These properties are a shortcut to the same properties
exposed via the Descriptor.
Properties
Name Type Description
Color long Get the color (RGB)
IMtcChannel3
Extends the IMtcChannel2 interface with additional properties and methods.
Page 13
Methods
Name Parameters Description
IMtcDataArray StartIndex: an index to start resampling
DataArraySegmentFromIndexes ( Count: the number of samples to be
int StartIndex, resampled
int Count,
SampleRate [Hz]: the new sampling
double SampleRate, rate (can be higher or lower than the
int AntiAliasFilterType original rate)
IMtcChannelDescriptor
Defines some basic properties that describe a channel (without the channel necessarily existing).
Properties
Name Type Description
Color long Get the color (RGB)
Page 14
Name Type Description
Id string Get the display name
IMtcChannelDescriptors
A collection of IMtcChannelDescriptor objects.
Properties
Name Type Description
Count long Get the number of arguments in the
collection
Page 15
Methods
Name Parameters Description
IMtcChannelDescriptor Id: display name
Add ( Type: the DataType of the channel
string Id,
Unit: the default display unit
string Type,
string Unit
)
Page 16
IMtcChannels
A collection of IMtcChannel objects.
Properties
Name Type Description
Count long Get the number of channels in the
collection
Methods
Name Parameters Description
IMtcChannel Id: display name
Add ( Type: the DataType of the channel
string Id,
string Type
)
Page 17
IMtcChannelSource
Represents the channels available from a data source. All interfaces from here are read-only.
Properties
Name Type Description
Channels IMtcChannels Get the channels associated with this
source
IMtcDataArray
The main interface for dealing with data samples in i2.
Properties
Name Type Description
Count long Get the number of samples of the data
Page 18
Methods
Name Parameters Description
Object Time [µs]: time
GetValue (
double Time
)
Return the sample value at the given time. Depending on
the channel’s interpolation mode, it may return an
interpolated value
double
SampleTime (
long Index
)
Return the sample time [µs] for a given index. The index
may be beyond the interval of the actual samples
available
IMtcDataLayer
Represents a time interval of logging. Typically used to represent Normal and Burst logging groups.
Properties
Name Type Description
Channels IMtcChannels Get the channels collection
Page 19
IMtcDataLayers
A collection of IMtcDataLayer objects.
Properties
Name Type Description
Count long Get the number of data layers in the
collection
Methods
Name Parameters Description
IMtcDataLayer Nth: data layer index
Index[long Nth]
IMtcDataSelection
Represents a data selection in i2.
Properties
Name Type Description
CursorTimeDatum double Get the datum cursor time [µs]
Page 20
Methods
Name Parameters Description
void StartTime: out parameter, receives the
GetZoomTime( zoom start time [µs]
double StartTime, [out]
double EndTime [out] EndTime: out parameter, receives the
) zoom end time [µs]
IMtcDataSelection2
Extends the IMtcDataSelection interface with the following properties.
Properties
Name Type Description
ChannelSource IMtcChannelSource Get the associated channel source
IMtcDataSelections
Represents the main and (optional) reference IMtcDataSelection interfaces currently active in i2.
Properties
Name Type Description
Main IMtcDataSelection Get the main data selection for the
active component in i2
IMtcDataSource
A data source can represent:
An LD representing logged data
or
An active telemetry stream
Page 21
Properties
Name Type Description
Date date Get the date of the data source
Methods
Name Parameters Description
IMtcDataArray Type: the DataType of the array. One
CreateDataArray( of:
Page 22
IMtcDataSources
A collection of IMtcDataSource objects.
This interface and methods can only be accessed if you have a valid i2 API Licence
Properties
Name Type Description
Count long Get the number of data sources in the
collection
Methods
Name Parameters Description
IMtcDataSource Nth: data layer index
Index[long Nth]
void
Close(
IMtcDataSource DataSource
)
Close the supplied data source
void
CloseAll()
Close all data sources currently loaded
Page 23
Name Parameters Description
IMtcDataSource Duration [µs]: the amount of time
Create( represented by the data source
double Duration
)
Create a data source that represents an interval of time
Page 24
IMtcDataSources2
Extension of the IMtcDataSource interface.
Methods
Name Parameters Description
void FileName: the destination file name of
ExportMainAsCSV( the export
string FileName,
EDataExtent DataExtent DataExtent: amount of data to be
) exported (for example, the selected
lap, the entire outing or just the
Export the main selection logged channels as a MoTeC currently zoomed extent)
CSV file
IMtcDetail
Represents a detail (named value).
Properties
Name Type Description
Id string Get the name of the detail
Page 25
Methods
Name Parameters Description
string
ToString()
bool
IsNumeric()
IMtcDetails
Represents a collection of IMtcDetail objects.
Properties
Name Type Description
Count long Get the number of details in the
collection
Methods
Name Parameters Description
IMtcDetail Nth: details index
Index[long Nth]
Page 26
Name Parameters Description
void Id: details name
AddNumeric(
string Id, Value: the numeric value
double Value, Unit: the i2 unit
string Unit,
int DPS DPS: the decimal places
)
Add a numeric detail
IMtcI2Application
The primary entry point into using the i2 API (extends the IMtcApplication interface).
Properties
Name Type Description
QueryAPI IMtcQueryAPI Internal Use Only
Methods
Name Parameters Description
void
WorkspaceNew()
void
WorkspaceOpen()
Page 27
Name Parameters Description
void File: fully qualified file name to be
WorkspaceLoad( loaded
string File
)
Load the Workspace from the file
void
WorkspaceLoadRecent()
void
CheckForUpdates()
Launch the checks for update dialogue
IMtcMarker
Represents a point in time or distance within the data (layer).
Properties
Name Type Description
ClassName string Get the marker class. Marker classes
differ depending on the type of
Workspace that opens. Examples (for
circuit) include:
BCN (main lap beacon)
SPLTBCN (split beacon)
IGRDBCN (ignored beacon)
RESET (device reset)
SOL (start of logging)
EOL (end of logging)
Page 28
Name Type Description
MarkerGroup IMtcMarkerGroup Get the marker group that contains the
marker
IMtcMarkerGroup
Represents a collection of IMtcMarker (usually of the same class).
Properties
Name Type Description
Count long Get the number of markers in the
collection
Methods
Name Parameters Description
IMtcMarker Nth: marker index
Index[long Nth]
Page 29
Name Parameters Description
void
Clear()
Clear all the markers from the group
IMtcMarkerGroup2
Extends the IMtcMarkerGroup interface with the following methods.
Methods
Name Parameters Description
IMtcMarker Parent: parent marker
AddDistMarker(
IMtcMarker Parent,
ClassName: the class of marker
string ClassName
string Name,
double Distance, Name: unique name of the marker
string Comment
)
Distance [m]: distance relative to the
Add a distance [m] based marker (relative to the parent parent marker
marker) to the group
Comment [optional]
Comment [optional]
Page 30
IMtcMarkerGroups
A collection of IMtcMarkerGroup objects
Properties
Name Type Description
Count long Get the number of marker groups in
the collection
Methods
Name Parameters Description
IMtcMarkerGroup Nth: marker group index
Index[long Nth]
IMtcRange
Represents a range (defined between two markers) in i2.
Properties
Name Type Description
Abbrev string Get/Set the range name abbreviation
(e.g. “L1” for “Lap 1”)
Page 31
IMtcRangeGroup
A collection of IMtcRange objects.
Properties
Name Type Description
Count long Get the number of ranges in the
collection
Methods
Name Parameters Description
IMtcRange Nth: range index
Index[long Nth]
void
Clear()
Clear all the ranges from the group
Page 32
IMtcRangeGroups
A collection of IMtcRangeGroup objects.
Properties
Name Type Description
Count long Get the number of range groups in the
collection
Methods
Name Parameters Description
IMtcRangeGroup Nth: range group index
Index[long Nth]
IMtcSetupSheet
Represents a Microsoft Excel based setup sheet in i2.
Properties
Name Type Description
Details IMtcDetails Get the details from the setup sheet
IMtcQty
Represents a quantity in i2.
Properties
Name Type Description
DisplayName string Get the quantity name (e.g.
Acceleration)
Page 33
Name Type Description
Units IMtcUnits Get the units associated with the
quantity
IMtcQtys
A collection of IMtcQty objects.
Properties
Name Type Description
Count long Get the number of quantities in the
collection
Methods
IMtcUnit
Represents a unit in i2. The full set of units available in i2 can be seen in “Tools|View Units…”.
Properties
Page 34
Methods
Name Parameters Description
void Value: [in] SI value, [out] unit value
FromSI(
object Value [in/out]
)
IMtcUnits
A collection of IMtcUnit objects.
Properties
Name Type Description
Count long Get the number of units in the
collection
Methods
Name Parameters Description
IMtcUnit Nth: unit index
Index[long Nth]
Get the Nth unit
Page 35
EXAMPLE
The following C# example iterates through channels from a pre-loaded data source in i2 and output name and display unit
information.
For the “Engine RPM” channel (if it exists), it will also output 2 seconds of samples from the start of the data.
Example ( C# )
Note: You may need to set the “Embed Interop Types = False” property on the i2 Reference in your Visual Studio solution.
Page 36
APPENDIX
i2 Math API
Unlike the i2 API interfaces mentioned previously, the i2 Math API are a set of interfaces that you can implement to
provide i2 with hooks into your own custom code.
Note: Math plug-ins may need to be registered under administrative privileges (i.e. start i2 with 'Run as Administrator').
IMtcArgs
Represents the i2 Math function arguments passed into your custom Math function.
Properties
Name Type Description
Count long Get the number of arguments in the
referenced collection
Methods
Page 37
IMtcMathArray
Extends the IMtcDataArray interface with additional properties.
Properties
Name Type Description
MathEndTime double Get the end time for this Math based
array [µs]
MathStartTime double Get the start time for this Math based
array [µs]
IMtcMathFunction
Implement this interface to add your own Math functions into i2.
Methods
IMtcMathPlugin
Implement this interface to add your own Math results into i2.
Properties
Name Type Description
InputChannels string [ array ] Get the channel names this plug-in
requires
Page 38
Name Type Description
Summary string Get the high level description of the
plug-in
Methods
void
UnRegister(
IMtcChannelDescriptors Descs
)
Implement this method to unregister the channels this
plug-in generates
void
ShowSettings()
Implement this method to show any UI required for the
user to edit settings
Page 39
IMtcMathPluginArgs
Represents the i2 Math plug-in arguments.
Properties
Name Type Description
DataLayerName string Get the data layer name this plug-in is
currently executing in (within the
supplied data source context)
Page 40
Range Groups
Range groups are collections of ranges. A range defines a time or distance extent (based on markers) within the normal
data layer.
The following range groups are available in i2 (based on their Workspace type):
Circuit
“Outings:Laps” – A collection of lap ranges
“Outings:Laps:Splits” - A collection of splits
Drag
“Outings:Runs” – Typically a single run range
Rally
“Outings:Stages” – Stage and transport ranges
Engine
“Outings:Data” – Typically a single extent of data
Page 41
Object Model Reference
Page 42