How to Read CI Data Files in Matlab

Introduction
The ATFX API C# DLL files can be used in three supported coding languages: Python, Matlab and LabVIEW. Fortunately, Matlab has a built-in function to reference C# DLL files and import various properties and functions.

For more detailed information on how to implement the following code sections and properties in a class, please refer to the ATFX API manual and the provided C# & Matlab Demo code. The package can be downloaded from our Programming Corner.

There are times when the script is reading the correct file path and the DLL files exist, but the script shows an error stating that it cannot find the DLL files. One solution is to click a box labeled Unblock in the DLL file properties accompanying the following description, “This file came from another computer and might be blocked to help protect this computer.”. Unblocking the DLL file should allow the scripts relying on the DLL files to locate and read them.

CI ATFX Reader properties

Importing C# DLL Files to Matlab
Matlab includes a function identified as NET.addAssembly that can import ATFX API DLL files. The documentation is here: https://www.mathworks.com/help/matlab/ref/net.addassembly.html.

R2009a became available when the NET.addAssembly function was introduced, thus it is recommended to use R2021b or later to utilize numerous quality-of-life improvements provided by Matlab.

% Load common and reader dll
NET.addAssembly('C:\Users\KevinCheng\Downloads\ATFX API Package v1.4\Common.dll');
NET.addAssembly('C:\Users\KevinCheng\Downloads\ATFX API Package v1.4\CI.ATFX.Reader.dll');

Opening an ATFX File and Extracting Various Data
The provided Matlab Demo Script demonstrates how to extract and display a signal property in addition to plotting out its frame data. A significant Matlab advantage is the ability to visualize signal data values.

%create a atfx recording instance
atfxFilePath = 'C:\Users\KevinCheng\Downloads\gps test example\{4499520}_REC_{20220419}(1).atfx';
rec = EDM.Recording.ODSNVHATFXMLRecording(atfxFilePath);
% array to contain boolean return and the actual out IRecording parameter
[openRecordSucceed, recording] = EDM.Recording.RecordingManager.Manager.OpenRecording(atfxFilePath);

%use item function to get signal instance
sig = Item(recording.Signals,0);

%display signal properties
disp(System.String.Format("Name:",sig.Name));
disp(System.String.Format("X Unit:",sig.Properties.xUnit));
disp(System.String.Format("Y Unit:",sig.Properties.yUnit));
disp(System.String.Format("GPS Enable:",rec.Measurement.GPSEnabled));
disp(System.String.Format("Longitude:",rec.Measurement.Longitude));
disp(System.String.Format("Latitude:",rec.Measurement.Latitude));
disp(System.String.Format("Altitude:",rec.Measurement.Altitude));
disp(System.String.Format("Time zone:",rec.Environment.TimeZone));
disp(System.String.Format("Created Time (Local):",rec.RecordingProperty.CreateTime));
disp(System.String.Format("Created Time (UTC):",rec.Environment.GetUTCTime(rec.RecordingProperty.CreateTime)));
disp(System.String.Format("Nanoseconds Elapsed:",rec.Measurement.NanoSecondElapsed));

disp("display signal frame data");
%get signal frame
frame = sig.GetFrame(0);
%convert .Net double[][] array to matlab cell
matFrame = cell(frame);
%Long format, showing more decimal places
format long
%convert back to mat array
xVals = cell2mat(matFrame(1));
yValues = cell2mat(matFrame(2));

%plot the signal
plot(xVals,yValues,'r');
xlabel(string(sig.Properties.xQuantity)+" ("+string(sig.Properties.xUnit)+")");
ylabel(string(sig.Properties.yQuantity)+" ("+string(sig.Properties.yUnit)+")");
title("Plot of the "+string(sig.Name));
legend(string(sig.Name))

The following screenshot is an example of the provided Matlab Demo Script print statements: