How to Read CI Data Files in Python
Introduction
The ATFX API C# DLL files can be used in three supported coding languages: Python, Matlab and LabVIEW. A specific package that allows Python to integrate with .NET Common Language Runtime needs to be installed for the C# DLL files to work in Python. Several packages accomplish this, such as IronPython and Python.NET. In this example, Python.NET will be used.
Please refer to the ATFX API manual and the provided C# & Python Demo code for more detailed information on how to implement the following code sections and properties in a class. Download the package 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.
Installing Python.NET to import C# DLL Files
To import C# DLL files to Python, install Python.NET so that Python can communicate with .NET Common Language Runtime.
The package can be installed via “pip install pythonnet” or from their github page: https://github.com/pythonnet/pythonnet. Please note the Python version needed to run Python.NET on the github page.
After Python.NET has been installed, the following “import clr” must be used to add references to .NET assemblies and ATFX API DLL files. Then the namespaces from the ATFX API can be imported.
#---Pythonnet clr import clr.AddReference(parentPath + "CI.ATFX.Reader.dll") #---C# .NET imports & dll imports |
Opening an ATFX File and Extracting Various Data
Much of the code shown here or in the provided Python Demo Script are reapplied from the C# Demo code. The code samples in ATFX API Reading a ATFX File in C# will be reapplied here to show how to open an ATFX file and extract data in Python.
recordingPath = "C:\\Users\\KevinCheng\\Downloads\\gps test example\\" #OpenRecording(string, out IRecording) print("\nRecording Properties\n") print("\nSignal 1 Properties\n") print("\nRecording GPS Properties\n") print("GPS Enabled: " nvhMeasurement.GPSEnabled) print("Created Time (UTC): ", |
The above code should print the following screenshot:
The following screenshot is an example of the provided Python Demo Script print statements: