SP209 API

Download

The API can be downloaded via this GitHub repository

This repository includes all required header files, the latest binary files in “dependency” folder, as well a fully functional, yet minimal example to help you get started with the API.

Documented C header file

Below is the latest version of the file sp209api_types.h

#ifndef SP209API_TYPES_H
#define SP209API_TYPES_H

#include <stdint.h>

#define API_VER_MAJ 1
#define API_VER_MIN 0
#define API_VER_PAT 0

#define SP209_CHANNELS_COUNT        (9)
#define SP209_TRIG_ENGINES_COUNT    (2)
#define SP209_THRESHOLDS_COUNT      (3)
#define SP209_MAX_TRIG_STEPS_COUNT  (128)

/**
 * @brief The sp209api_variant_t enum is used to determine which firmware is loaded when openning a device
 */
enum sp209api_variant_t
{
    SP209API_VARIANT_STD = 0, ///< Standard SP209 firmware
    SP209API_VARIANT_NEXUS = 1,///< Custom firmware reserved for Nexus bus analyzer
    SP209API_VARIANT_TPIU = 2, ///< Custom firmware reserved for TPIU bus analyzer
};

/**
 * @brief The sp209api_clock_pol_t enum defines the clock polarity
 * of the external clock (if used)
 */
enum sp209api_clock_pol_t
{
    CLK_POL_RISING = 1, ///< Rising edge
    CLK_POL_FALLING = 0, ///< Falling edge
    CLK_POL_DUAL = 2, ///< Dual edge (any rising or falling edge)
};

/**
 * @brief The sp209api_device_model_t enum defines the model of the device within SP209 family
 * of logic analyzer devices
 */
enum sp209api_device_model_t
{
    SP209API_MODEL_209, ///< Standard SP209
    SP209API_MODEL_209I, ///< Industrial SP209i

    SP209API_MODEL_209C1, ///< Custom HW for ST-Micro internal use
    SP209API_MODEL_209A1, ///< Custom HW ID for internal use only
    SP209API_MODEL_NONE ///< Should never be used.
};

/**
 * @brief The sp209api_threshold_t enum defines the thresholds supported by SP209 devices
 */
enum sp209api_threshold_t
{
    SP209API_TH_1V8 = 0, ///< 1.8V logic level
    SP209API_X_TH_2V5 = 1, ///< 2.5V logic level
    SP209API_X_TH_3V3 = 2, ///< 3.3V logic level
    SP209API_TH_5V0 = 4, ///< 5.0V logic level
};

/**
 * @brief The sp209api_trigger_type_t enum lists the different kind of trigger supported by the API
 */
enum sp209api_trigger_type_t
{
    SP209API_TRG_NOTRIG = 0,
    SP209API_TRG_RISING,
    SP209API_TRG_FALLING,
    SP209API_TRG_CHANGE,
    SP209API_TRG_EXT_RISING,
    SP209API_TRG_EXT_FALLING
};



#pragma pack(push, 4) //Ensure known packing on all platforms

struct sp209api_trigger_description_t
{
    /**
     * @brief type is the type of trigger (e.g. falling edge, rising edge or logic change).
     */
    sp209api_trigger_type_t type;
    /**
     * @brief channel set to the number of the channel concerned by the trigger,
     * or -1 if you wish to target all channels. (-1 is only valid for Logic Change
     * type of trigger)
     * @note channel is a 0 based index, i.e. first channel is 0.
     */
    int8_t channel;
};

/**
 * @brief The spx_settings_t struct exposes the options that need to be configured by the user via
 * various GUI options.
 */
struct sp209api_settings_t
{
    /**
     * @brief Total number of samples requested by the user
     */
    int64_t sampling_depth;

    /**
     * @brief Total number of samples after the trigger
     */
    int64_t post_trig_depth;

    /**
     * @brief Trigger clock expressed in HZ
     */
    uint32_t t_clk[SP209_TRIG_ENGINES_COUNT];

    /**
     * @brief An array of thresholds
     * @details can be 3, 6, or 12, for SP209, SP218, and SP236
     */
    sp209api_threshold_t thresh_cfg[SP209_THRESHOLDS_COUNT];

    /**
     * @brief enable the use of external (AKA State mode)
     */
    bool ext_clk;

    /**
     * @brief External clock polarity (active edge selection)
     */
    sp209api_clock_pol_t ext_clk_pol;

    /**
     * @brief activate the 50R input resistor on Ext. Trig input
     */
    bool ext_trig_50r;

    /**
     * @brief enable (and use) Ext Trig In as trigger source
     */
    bool ext_trig_in[SP209_TRIG_ENGINES_COUNT];

    /**
     * @brief ext_trig_in_polarity selects the active edge for the external trigger
     * 0: Faling edge
     * 1: Rising edge
     */
    uint8_t ext_trig_in_polarity[SP209_TRIG_ENGINES_COUNT];
    uint8_t ext_trig_out_polarity;

    /**
     * @brief 2 bits describing the operation of the dual trigger engine
     * @details the 2 LSB bits describe the operation of the dual trigger engine
     * as the following:
     * - 00: Trig 0 or Trig 1 (any of the two trigger engines will cause the trigger to be valid)
     * - 01: Trig 0 then Trig 1 (Trig 1 is only enabled after Trig 1 occures)
     * - 10: Trig 1 then Trig 0 (Trig 0 is only enabled after Trig 0 occures)
     * - 11: Trig 0 and Trig 1, in any order.
     */
    uint8_t trig_order;

    //********
    //Industrial version (SP209I) only related settings
    //********

    /**
     * @brief Multiplexing enable for each pin
     * @details when enabled an input pin uses the multiplexed (auxiliary input)
     * instead of the standard single ended input.
     * @note This is only applicable to SP209i (industrial) version
     */
    bool mux[SP209_CHANNELS_COUNT];
    /**
     * @brief can_term when TRUE, CAN bus termination resistor is enabled
     * @note This is only applicable to SP209i (industrial) version
     */
    bool can_term;
    /**
     * @brief rs485_1_term when TRUE, RS485 bus number 1's termination resistor is enabled
     * @note This is only applicable to SP209i (industrial) version
     */
    bool rs485_1_term;
    /**
     * @brief rs485_2_term when TRUE, RS485 bus bumber 2's termination resistor is enabled
     * @note This is only applicable to SP209i (industrial) version
     */
    bool rs485_2_term;
};

/**
 * @brief The sp209api_transition_t struct describes an SP209 transition
 * @details SP209 API provides captured samples in minimal structures called "transition".
 * During a transition, one or more chanel's logic level change. This structure describes this
 * transition.
 */
struct sp209api_transition_t
{
    /**
     * @brief data_word The 9 less significant bits of this word describe the logic level
     * of the 9 channels of SP209 device, right after the transition (the newest value of
     * the logic levels)
     */
    uint16_t data_word;     //Line values
    /**
     * @brief delta_samples Number of samples since the previous transition
     */
    uint8_t delta_samples;  //number of samples
    /**
     * @brief trigger_flag is set to TRUE if trigged occured.
     * @note trigger_flag will remain true for all transitions that are subsequent to the trigger instant
     */
    bool trigger_flag;
};

/**
 * @brief The sp209api_tpiu_data_t struct describes TPIU custom firmware transaction
 * @warning This is used for custom and proprietary usage of SP209C1 devices.
 */
struct sp209api_tpiu_data_t
{
    /**
     * @brief id ID associated with a data byte
     */
    uint8_t id;     //ID associated with data byte
    /**
     * @brief data Data content (single byte)
     */
    uint8_t data;  //Data byte
};

#pragma pack(pop)


#endif // SP209API_TYPES_H

Below is the latest version of the file sp209api.h

#ifndef SP209_API_H
#define SP209_API_H

#if defined(GENERATE_API_WIN)
    #define SCANA_API __declspec(dllexport)
#elif defined(GENERATE_API_UNIX)
    #define SCANA_API __attribute__((visibility("default")))
#elif defined(GENERATE_API_MAC)
    #include "ftd2xxUNIX.h"
    #include "WinTypes.h"
    #  define SCANA_API __attribute__((visibility("default")))
#elif defined(OS_WIN)
    #define SCANA_API __declspec(dllimport)
#else
    #define SCANA_API
#endif

#include <cstddef>
#include "ihwapi_common_types.h"
#include "sp209api_types.h"

#ifdef __cplusplus
extern "C"
{
#endif

/**
 * @brief sp209api_handle Pointer to SP209API
 */
typedef void* sp209api_handle;

//library instance management

/**
 * @brief sp209api_create_new_handle This functions creates a new handle that can be
 * later used to call the functions of this API.
 * @return the newly created handle.
 */
SCANA_API
sp209api_handle sp209api_create_new_handle(void);

/**
 * @brief sp209api_free is used to clear a handle (freeing all the memory used).
 * @param handle
 */
SCANA_API
void sp209api_free(sp209api_handle handle);


//Device listing functions

/**
 * @brief sp209api_create_device_list is used to create (or update the list
 * of SP209 devices that can be found on the USB).
 * @param handle
 */
SCANA_API
void sp209api_create_device_list(sp209api_handle handle);

/**
 * @brief sp209api_free_device_list is used to free the memory used to
 * store the list of current devices.
 * @param handle
 */
SCANA_API
void sp209api_free_device_list(sp209api_handle handle);

/**
 * @brief sp209api_get_devices_count is used to get the list of device
 * that was created using the sp209api_create_device_list function.
 * @param handle
 * @return the number of devices
 */
SCANA_API
uint8_t sp209api_get_devices_count(sp209api_handle handle);

/**
 * @brief sp209api_get_device_descriptor is used to get the device descriptor
 * for a device on the bus. The funciton sp209api_create_device_list must be called
 * prior to calling this function. The device descriptor is needed to open an SP209
 * device.
 * @param handle
 * @param device_number, 0-based index.
 * @return device descriptor (Serial number and description). See device_descriptor_t type.
 */
SCANA_API
device_descriptor_t sp209api_get_device_descriptor(sp209api_handle handle, uint8_t device_number);

//General Device Commands (common to all variants)

/**
 * @brief sp209api_device_open Open SP209 device using a device descriptor.
 * @param handle
 * @param device: the device descriptor
 * @param variant: the device variant (or operation mode). Some devices ship with custom,
 * application speicifc firmware (like Nexus or TPIU) that are loaded next to the standard (Logic Analyzer)
 * firmware. The variant must be specified when openning a device.
 * @return error code, see ihwapi_err_code_t type.
 */
SCANA_API
ihwapi_err_code_t sp209api_device_open(sp209api_handle handle, device_descriptor_t device, sp209api_variant_t variant);

/**
 * @brief sp209api_device_power_off is used to switch off SP209 device (effectively
 * loosing any configuration made to the device).
 * @param handle
 * @return error code, see ihwapi_err_code_t type.
 */
SCANA_API
ihwapi_err_code_t sp209api_device_power_off(sp209api_handle handle);

/**
 * @brief sp209api_get_firmware_version_major returns the major version of the firmware
 * @param handle
 * @return
 */
SCANA_API
uint8_t sp209api_get_firmware_version_major(sp209api_handle handle);

/**
 * @brief sp209api_get_firmware_version_minor returns the minor version of the firmware
 * @param handle
 * @return
 */
SCANA_API
uint8_t sp209api_get_firmware_version_minor(sp209api_handle handle);

/**
 * @brief sp209api_get_bootloader_version_major return the major version of the bootloader
 * @param handle
 * @return
 */
SCANA_API
uint8_t sp209api_get_bootloader_version_major(sp209api_handle handle);

/**
 * @brief sp209api_get_bootloader_version_minor returns the minor version of the bootloader
 * @param handle
 * @return
 */
SCANA_API
uint8_t sp209api_get_bootloader_version_minor(sp209api_handle handle);

/**
 * @brief sp209api_get_device_open_flag returns TRUE if the device is open (connection is still active)
 * @param handle
 * @return
 */
SCANA_API
bool sp209api_get_device_open_flag(sp209api_handle handle);

/**
 * @brief sp209api_launch_fw_update is used to launch a firmware update
 * @param handle
 * @param fw_data a pointer to the an array containing the firmware (loaded from *.bin file)
 * @param fw_size the size of the array (number of bytes).
 * @return error code, see ihwapi_err_code_t type.
 */
SCANA_API
ihwapi_err_code_t sp209api_launch_fw_update(sp209api_handle handle, uint8_t *fw_data, size_t fw_size);

/**
 * @brief sp209api_request_abort request any pending operation to abort.
 * This function returns without verifying if the operation was effectiely aborted
 * @param handle
 */
SCANA_API
void sp209api_request_abort(sp209api_handle handle);

/**
 * @brief sp209api_get_firmware_update_progress is used to get the progres of an ongoing
 * firmware update running in background.
 * @param handle
 * @return Number from 0 to 100 representing progress.
 */
SCANA_API
uint8_t sp209api_get_firmware_update_progress(sp209api_handle handle);

/**
 * @brief sp209api_get_firmware_update_done_flag is used to poll firmware update status
 * @param handle
 * @return true if done, false otherwize.
 */
SCANA_API
bool sp209api_get_firmware_update_done_flag(sp209api_handle handle);

/**
 * @brief sp209api_get_last_error_code is used to return the last error code.
 * It should be called after a background task is finished.
 * @note After the first call to this function, the error flag will be reset to default "no error" value.
 * @param handle
 * @return error code.
 */
SCANA_API
ihwapi_err_code_t sp209api_get_last_error_code(sp209api_handle handle);


/**
 * @brief sp209api_launch_new_capture is used to start a new capture of samples.
 * @param handle
 * @param settings the SP209 device settings to be used for this capture
 * @return error code.
 * @details This function does not offer any trigger options, capture will start as soon as possible
 * after this function is called.
 * @see sp209api_launch_new_capture_complex_trigger
 */
SCANA_API
ihwapi_err_code_t sp209api_launch_new_capture_simple_trigger(sp209api_handle handle,
                                                              sp209api_trigger_description_t trig,
                                                              sp209api_settings_t settings);

/**
 * @brief sp209api_launch_new_capture_complex_trigger is used to start a new capture
 * after a specific trigger condition occured.
 * @warning This functions is not intended to be used by anything/anyone else but ScanaStudio software
 * @details Trigger is defined using trigger steps. A trigger step mainly describes the logic state
 * of all channels and timing constraints with respect to previous step. Each step is a coded as a 64 bits word.
 * For a capture to start, all the logic signals must match all trigger steps in
 * the right order.
 *
 * SO209 has two trigger engines (named A and B).
 * @param handle
 * @param settings the SP209 device settings to be used for this capture
 * @param trig_a_data pointer to an array of trigger steps (words), or null pointer if not used
 * @param trig_a_size number of steps pointed to by trig_a_data, or 0 if trig_a_data is a null pointer.
 * @param trig_b_data pointer to an array of trigger steps (words), or null pointer if not used
 * @param trig_b_size number of steps pointed to by trig_b_data, or 0 if trig_b_data is a null pointer.
 * @return error code.
 * @see sp209api_launch_new_capture_simple_trigger
 */
SCANA_API
ihwapi_err_code_t sp209api_launch_new_capture_complex_trigger(sp209api_handle handle,
                                              sp209api_settings_t settings,
                                              uint64_t* trig_a_data, uint16_t trig_a_size,
                                              uint64_t* trig_b_data, uint16_t trig_b_size);

/**
 * @brief sp209api_get_config_done_flag is used to check if the device have finished its internal
 * configuration after a request to launch a new capture.
 * @details There is no any obligation to use this function, as the configuration of the device
 * usually takes a few milliseconds. This function is mainly here for feedback and monitoring purposes.
 * @param handle
 * @return TRUE if configuration is done, FALSE if configuration is still in progress.
 */
SCANA_API
bool sp209api_get_config_done_flag(sp209api_handle handle);

/**
 * @brief sp209api_get_available_transitions
 * @param handle
 * @return
 */
SCANA_API
uint32_t sp209api_get_available_transitions(sp209api_handle handle);

SCANA_API
void sp209api_get_transitions(sp209api_handle handle, sp209api_transition_t* transitions_data, uint32_t transitions_to_get);

SCANA_API
void sp209api_flush_transitions(sp209api_handle handle);

SCANA_API
bool sp209api_get_triggered_flag(sp209api_handle handle);


SCANA_API
bool sp209api_get_capture_done_flag(sp209api_handle handle);

//TPIU Variant functions
/**
 * @brief sp209api_tpiu_start is used to start the SP209 device in TPIU mode. Once started, SP209 device will stream captured TPIU packets
 * @param handle
 * @param test_mode: if true, the SP209 device will send 16 bit counter information instead of real captured TPIU data
 * @param logic_threshold
 * @return error code
 * @note The SP209 device must be open in TPIU operation mode (see sp209api_device_open).
 */
SCANA_API
ihwapi_err_code_t sp209api_tpiu_start(sp209api_handle handle,
                                      bool test_mode,
                                      sp209api_threshold_t logic_threshold);

/**
 * @brief sp209api_tpiu_stop is used to stop TPIU streaming.
 * @param handle
 */
SCANA_API
void sp209api_tpiu_stop(sp209api_handle handle);

/**
 * @brief sp209api_tpiu_get_available_data_count returns the number of TPIU data items that can be read.
 * @param handle
 * @return
 */
SCANA_API
uint32_t sp209api_tpiu_get_available_data_count(sp209api_handle handle);

/**
 * @brief sp209api_tpiu_get_data is used to fill "data_to_get" items of data in "*data" buffer.
 * @note *data must be initialized with the correct size prior to calling this functions
 * @param handle
 * @param data
 * @param data_to_get
 */
SCANA_API
void sp209api_tpiu_get_data(sp209api_handle handle, sp209api_tpiu_data_t* data, uint32_t data_to_get);

/**
 * @brief sp209api_tpiu_flush_data is used to flush any data that was streamed by SP209 device but still
 * not retrieved by the application.
 * @param handle
 */
SCANA_API
void sp209api_tpiu_flush_data(sp209api_handle handle);

/**
 * @brief tpiu_get_overflow_flag is used to check if an overflow has occured in the SP209 DDR3 memory since last "tpiu start".
 * @param handle
 * @return
 */
SCANA_API
bool sp209api_get_overflow_flag(sp209api_handle handle);



#ifdef __cplusplus
}
#endif


#endif // SP209_API_H

The sp209api_transition_t type

Captured samples are packetized and transfered between device and your application using a data type called sp209api_transition_t. This data type allows for more optimal - compressed - transfer of captured samples. You can think of this data type as a way of timestamping each transition recorded by the device. Here is how it works: Each time the logic level on one or more channels changes, a new transition is created, and the time difference (delta_samples) between this transition and the previous one is recorded.

Please not that the number in delta_samples can’t be bigger than 63. In the case of the SP209 device, 63 samples means 315 nanoseconds. So even if logic channels are totally idle, a new transition will be created and transferred to the computer every 315ns. In that particular case, the data_word field won’t change (and in that particular case, technically speaking, there are no transitions).

Trigger configuration

In order to describe a particular trigger configuration, the sp209api_trigger_description_t structure is used. it can be passed as a parameter to SP209’s API as it can be seen in the examples below. The definition of each member of this structure is described in the header file sp209api_types.h

Please note that the trigger capabilities of the API are somewhat limited compared to what’s possible with ScanaStudio, nevertheless, it allows basic triggering options.

Usage examples

Below are some C/C++ example code snippets.

Note: in order to run those examples, it’s necessary to include the following files:

  1. ihwapi_common_types.h
  2. sp209_types.h
  3. sp209api.h

Also, please note those examples are created, run, and tested under Qt environment, that being said, we used standard C++ compliant syntax, without any fancy Qt specific functions

Listing the number of open devices

sp209api_handle h;
int devices_count = 0;

h = sp209api_create_new_handle();
sp209api_create_device_list(h);
devices_count = sp209api_get_devices_count(h);
sp209api_free_device_list(h);

Here is a more complex example that also gets device descriptor:

#define DBG   std::cout << "\n\r" << " "
sp209api_handle h;
device_descriptor_t d;
int devices_count = 0;

h = sp209api_create_new_handle();
sp209api_create_device_list(h);
devices_count = sp209api_get_devices_count(h);
if (devices_count > 0)
{
  d = sp209api_get_device_descriptor(h,0);
}
sp209api_free_device_list(h);
DBG << "New device, serial number = " << d.sn << ", description = " << d.desc;

Open a device

#define DBG   std::cout << "\n\r" << " "
sp209api_handle h;
device_descriptor_t d;
int devices_count = 0;
ihwapi_err_code_t e;

h = sp209api_create_new_handle();
sp209api_create_device_list(h);
devices_count = sp209api_get_devices_count(h);
if (devices_count > 0)
{
  d = sp209api_get_device_descriptor(h,0);
  e = sp209api_device_open(h,d,SP209API_VARIANT_STD);

  if (e == IHWAPI_OK)
  {
    DBG << "Device is open";
  }
  else
  {
    DBG << "Device not open! error code = " << e;
  }
  sp209api_device_power_off(h);
}
sp209api_free_device_list(h);
sp209api_free(h);

Capture samples

The following examples show how to open a seek for a device, open it, and capture some samples. Then, the first 10 transitions are dumped to the console.

#define DBG   std::cout << "\n\r" << " "
int main()
{
    sp209api_handle h;
    device_descriptor_t d;
    ihwapi_err_code_t e = IHWAPI_DEVICE_NOT_OPEN;
    sp209api_settings_t settings;
    sp209api_transition_t data_trs[10];
    int devices_count = 0;
    uint32_t transitions_count = 0;




    h = sp209api_create_new_handle();
    sp209api_create_device_list(h);

    devices_count = sp209api_get_devices_count(h);
    DBG << "Found " << devices_count << " devices" ;
    if (devices_count > 0)
    {
        d = sp209api_get_device_descriptor(h,0);
        DBG << "New device, serial number = " << d.sn << ", description = " << d.desc ;
        e = sp209api_device_open(h,d,SP209API_VARIANT_STD);

        if (e == IHWAPI_OK)
        {
            DBG << "Device is open" << endl;
        }
        else
        {
            DBG << "Device not open! error code = " << e ;
        }

    }
    sp209api_free_device_list(h);

    if (e == IHWAPI_OK)
    {
        memset(&settings,0,sizeof (settings));
        settings.sampling_depth = 100e3;
        sp209api_trigger_description_t trg;
        trg.type = SP209API_TRG_NOTRIG;
        e = sp209api_launch_new_capture_simple_trigger(h,trg,settings);
        if (e == IHWAPI_OK)
        {
            while(sp209api_get_config_done_flag(h) == false)
            {
                msleep(200);
            }
            DBG << "Device Config done, new capture launched";
        }
        else
        {
            DBG << "Launch New capture error = " << e;

        }
    }



    if (e == IHWAPI_OK)
    {
        DBG << "Waiting for trigger...";
        while (sp209api_get_triggered_flag(h) == false)
        {
            msleep(200);
        }
        DBG << "Trigg'd";
        while(sp209api_get_capture_done_flag(h) == false)
        {
            msleep(200);
        }
        transitions_count = sp209api_get_available_transitions(h);
        DBG << "Capture done, transitions count = " << transitions_count;
        sp209api_get_transitions(h,data_trs,10); //Get first 10 transitions
        for (int i = 0; i < 10; i++)
        {
           DBG << data_trs[i].data_word << "\t" << int(data_trs[i].delta_samples) << "\t" << data_trs[i].trigger_flag;
        }
    }

    if (e == IHWAPI_OK)
    {
        DBG << "Closing device";
        sp209api_device_power_off(h); //All done, power off.
    }

    sp209api_free(h);
    return 0;
}

If we run the example above with an SP209 with hanging wires (no any signal being recoded, i.e. idle lines), then we should see this output:

Found 1 devices
New device, serial number = 1004210123456, description = SP209
Device is open

Device Config done, new capture launched
Waiting for trigger...
Trigg'd
Capture done, transitions count = 440
0      63      0
0      63      0
0      63      0
0      63      0
0      63      0
0      63      0
0      63      0
0      63      0
0      63      0
0      63      0
Closing device

Capture samples with trigger

And finally, let’s look at an example to capture some samples with a trigger condition:


#define DBG   std::cout << "\n\r" << " "

int main()
{
    sp209api_handle h;
    device_descriptor_t d;
    ihwapi_err_code_t e = IHWAPI_DEVICE_NOT_OPEN;
    sp209api_settings_t settings;
    sp209api_transition_t data_trs[50];
    int devices_count = 0;
    uint32_t transitions_count = 0;




    h = sp209api_create_new_handle();
    sp209api_create_device_list(h);

    devices_count = sp209api_get_devices_count(h);
    DBG << "Found " << devices_count << " devices" ;
    if (devices_count > 0)
    {
        d = sp209api_get_device_descriptor(h,0);
        DBG << "New device, serial number = " << d.sn << ", description = " << d.desc ;
        e = sp209api_device_open(h,d,SP209API_VARIANT_STD);

        if (e == IHWAPI_OK)
        {
            DBG << "Device is open" << endl;
        }
        else
        {
            DBG << "Device not open! error code = " << e ;
        }

    }
    sp209api_free_device_list(h);

    if (e == IHWAPI_OK)
    {
        memset(&settings,0,sizeof (settings));
        settings.sampling_depth = 100e3;
        settings.post_trig_depth = 100e3;
        settings.thresh_cfg[0] = SP209API_X_TH_3V3;
        settings.thresh_cfg[1] = SP209API_X_TH_3V3;
        settings.thresh_cfg[2] = SP209API_X_TH_3V3;
        sp209api_trigger_description_t trg;
        trg.type = SP209API_TRG_RISING;
        trg.channel = 0;
        e = sp209api_launch_new_capture_simple_trigger(h,trg,settings);
        if (e == IHWAPI_OK)
        {
            while(sp209api_get_config_done_flag(h) == false)
            {
                msleep(200);
            }
            DBG << "Device Config done, new capture launched";
        }
        else
        {
            DBG << "Launch New capture error = " << e;

        }
    }



    if (e == IHWAPI_OK)
    {
        DBG << "Waiting for trigger...";
        while (sp209api_get_triggered_flag(h) == false)
        {
            msleep(200);
        }
        DBG << "Trigg'd";
        while(sp209api_get_capture_done_flag(h) == false)
        {
            msleep(200);
        }
        transitions_count = sp209api_get_available_transitions(h);
        DBG << "Capture done, transitions count = " << transitions_count;
        for (int t = 0; t < int(transitions_count-50); t+= 50)
        {
            sp209api_get_transitions(h,data_trs,50); //Get 50 transitions
            if (data_trs[49].trigger_flag)
            {
                for (int i = 0; i < 10; i++)
                {
                   DBG << data_trs[i].data_word << "\t" << int(data_trs[i].delta_samples) << "\t" << data_trs[i].trigger_flag;
                }
            }
        }
    }

    if (e == IHWAPI_OK)
    {
        DBG << "Closing device";
        sp209api_device_power_off(h); //All done, power off.
    }

    sp209api_free(h);
    return 0;
}