1. GI.knowledgebase
  2. Sales Support Information

Direct data access from Gantner Instruments Q.station using Python

How to retrieve measurement data from a controller in Python for analysis, manipulation, reporting, or writing back results.

Introduction

Python is a versatile programming language commonly used for software development, web applications, task automation, and data analysis. As a general-purpose language, it is not limited to a specific domain and can be utilized to develop a wide range of applications.

Gantner Instruments provides a C API for directly reading measurement data from a controller into a Python program. This C API is called eGateHighSpeedPort API and is part of the GInsData Library. This library is available as a 32/64-bit DLL for Windows (giutility.dll) or Linux (libGInsUtility.so).

The latest releases of Python can be downloaded here: www.python.org.

 

ctypes package

To use the eGateHighSpeedPort API, Gantner Instruments provides an interface to the required DLL functions. The package utilizes the ctypes module, a foreign function library for Python, to perform DLL calls. This module enables interaction with shared libraries by providing C-compatible data types and function calling capabilities.

For example:

from ctypes import*
import ctypes
 
# Load DLL into memory, take care to have the corresponding dll available
try:
GINSDll = ctypes.cdll.LoadLibrary("giutility_x64.dll")
print("64 bit DLL imported")
except OSError:
GINSDll = ctypes.cdll.LoadLibrary("giutility_x86.dll")
print("32 bit DLL imported")
 
...
# function prototypes: specifying the required argument types
GINSDll._CD_eGateHighSpeedPort_Init.argtypes=[c_char_p,c_int,c_int,c_int,POINTER(c_int),POINTER(c_int)]
 
# function call:
ret=GINSDll._CD_eGateHighSpeedPort_Init(self.controllerIP,self.timeout,self.HSP_BUFFER,self.sampleRate,byref(self.HCLIENT),byref(self.HCONNECTION))
...

The DLL functions are simplified for ease of use in Python:

# Load Package
import ginsapy.giutility.connect.PyQStationConnectWin as Qstation #module with communication functions to Gantner Q.Station under windows environment
 
#initialize buffer connection
conn=Qstation.ConnectGIns()
conn.init_connection("192.168.5.24")
 
#Return some information of the controller
conn.read_controller_name()
conn.read_channel_names()
conn.read_channel_count()
 
#Call function to store buffer into the variable buffer
buffer=conn.yield_buffer()

 

Ginsapy package

Basic GInsData functionality is implemented in different Python modules and classes. All of the interface scripts, with examples and documentation, are delivered in an interface package called Ginsapy.

 

This package is already preinstalled with your Gi.bench installation. 

 

This blog/tutorial will walk you through how to communicate with the Q.station and how to work with the data you collect using different Python tools. The provided code snippets will help you apply these steps to your own data analysis needs. 

Documentation

The API documentation of the module is located in your Gi.bench or Gi.cloud under the tab: 
Help → APIS → Ginsapy 

 

The following examples are part of the package.

  • Read UDBF file (data logger file)

  • Connect to a controller

  • Write an online value to a controller
  • Read a data stream

  • Write a data stream

Additional libraries

All necessary libraries are automatically installed with the startup script, but can be installed or altered separately through the requirements.txt:

pip3 install -r requirements.txt

 

 

Example step-by-step

To run individual example navigate into your Bench installation folder: 

C:\Users\Public\Documents\Gantner Instruments\GI.bench\api\Python\examples\ginsapy

To install the package run: 

python startup.py
 
 
Now you can run individual examples from the src folder with the postfix -h to inspect different arguments. With these options parameters can be set or will use default parameters if left empty.
python "C:\Users\Public\Documents\Gantner Instruments\GI.bench\api\Python\examples\ginsapy\src\example_connect_controller.py" -h

 

In the Input parameters section, specify which channel you wish to be plotted. Multiple inputs are allowed.
    
This will allow you to fetch information from the controller. The code snippet below provides an example. 
 
Now when running the code example with plot variable on with
python "C:\Users\Public\Documents\Gantner Instruments\GI.bench\api\Python\examples\ginsapy\src\example_connect_controller.py" -g
Your output should look something like this:
 
 

 

Don't forget to set the according IP if a parameter is available.

127.0.0.1 Will access the buffer of the running Gi.bench instance, while using the Controller IP of a Q.station will use its buffer.