CAEN FERS Library v1.3.0
SDK for FERS systems
Loading...
Searching...
No Matches
Software development

Precondition
You have to install the library before to start using it. See Installation page for details.

Compile your project

Header

In order to use the library, just include the FERSlib.h header in your project:

#include "FERSlib.h"

Shared library

Windows

The Visual Studio FERSlib project is already compiled for x86_64 architecture. The FERSlib.lib is available at .\ferslib\lib, and must be added in your Visual Studio project settings. The corresponding shared library ferslib.dll is found in the path .\FERSlib\bin\x64\Release.

Linux

By default libcaenferslib.so is installed in the system library directory: add the patht to the LD_LIBRARY_PATH and pass -lcaenferslib to the linker to use it.

Develop your software

Connect to device

To connect to a device, just call the FERS_OpenDevice() that provides the handle to the FERS module:

ret = FERS_OpenDevice(BoardPath, &handle[b]);

The Data readout buffers for each connectd board must be initialized manually by calling FERS_InitReadout():

FERS_InitReadout(handle[b], 0, &a1);

which provides the total allocated memory for the buffers.

Eventually, FERS_CloseReadout() releases all data readout buffers and FERS_CloseDevice() close the connection:

FERS_CloseReadout(handle[b]);
FERS_CloseDevice(handle[b]);

The BoardPath in FERS_OpenDevice must be formed as: [ConnType]:[Address]. E.g.: in ethernet connection you can pass the IPv4 address

eth:192.168.50.3 ,

in usb you can use both board PID (i.e. 23475) or progressive enumeration:

usb:0 or usb:23475 ,

in TDlink you pass the DT5215 eth IP, the chain and the node the board is connected, as eth:[DT5215_IP]:tdl:[CHAIN][NODE]:

eth:192.168.50.125:tdl:0:1

Log

The FERSlibLog file is enabled by default and saved in the folder where the .exe is running. User may enable other debug logging by setting the parameter DebugLogMask to <0xVALUE>, where <0xVALUE> can be an OR of the values in DebugLOG.

Configure

The user can configure the FERS module setting the prameters available in CfgParam both individually by using FERS_SetParam()

FERS_SetParam(handle[b], parname, parvalue);

or by reading a configuration file with FERS_LoadConfigFile()

ret = ParseCfgFile(fcfg, &this_cfg, PARSE_CFG);
//ret = FERS_LoadConfigFile(cfg_file);

The parameters value is saved statically inside the library and can be retrieved with FERS_GetParam()

ret = FERS_GetParam(handle[0], parname, parvalue);

The board will be configured only after calling FERS_configure()

ret = FERS_configure(handle[b], CFG_HARD);

For debug, both the local parameters value and the board register value can be dump on a file by setting the DebugLogMask to the correct Mask in DebugLOG.

Data acquisition

A run starts after the FERS_StartAcquisition() is called.

The data taken are decoded inside the library and available to the user by FERS_GetEvent()

ret = FERS_GetEvent(handle, &b, &dtq, &tstamp_us, &Event, &nb);

The event data qualifier dtq must be the same set in the AcquisitionMode parameter.

The user can cast the read event to the corresponding data type described in DataStructures So the Event pointer is converted in a readable format.

Check last error

In case of error, API functions return a negative value described in FERSLIB_ErrorCodes. Extended information about the last error occurred can be retrieved using FERS_GetLastError():

char emsg[1024];
Note
The message is cleared after a successful call to FERSLib_GetLastError().

For example, it can be used to get a detailed message of a failed call to FERS_OpenDevice():

ret = FERS_OpenDevice(BoardPath, &handle[b]);
if (ret != 0) {
char emsg[1024];
printf("Can't open board: %s (ret=%d)\n", emsg, ret);
}