libsigrok  0.4.0
sigrok hardware access and backend library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Functions
Initialization

Initializing and shutting down libsigrok. More...

Functions

int sr_init (struct sr_context **ctx)
 Initialize libsigrok. More...
 
int sr_exit (struct sr_context *ctx)
 Shutdown libsigrok. More...
 

Detailed Description

Initializing and shutting down libsigrok.

Before using any of the libsigrok functionality (except for sr_log_loglevel_set()), sr_init() must be called to initialize the library, which will return a struct sr_context when the initialization was successful.

When libsigrok functionality is no longer needed, sr_exit() should be called, which will (among other things) free the struct sr_context.

Example for a minimal program using libsigrok:

#include <stdio.h>
int main(int argc, char **argv)
{
int ret;
struct sr_context *sr_ctx;
if ((ret = sr_init(&sr_ctx)) != SR_OK) {
printf("Error initializing libsigrok (%s): %s.\n",
return 1;
}
// Use libsigrok functions here...
if ((ret = sr_exit(sr_ctx)) != SR_OK) {
printf("Error shutting down libsigrok (%s): %s.\n",
return 1;
}
return 0;
}

Function Documentation

int sr_exit ( struct sr_context ctx)

Shutdown libsigrok.

Parameters
ctxPointer to a libsigrok context struct. Must not be NULL.
Return values
SR_OKSuccess
otherError code SR_ERR, ...
Since
0.2.0

Definition at line 550 of file backend.c.

References sr_driver_list(), SR_ERR, and SR_OK.

+ Here is the call graph for this function:

int sr_init ( struct sr_context **  ctx)

Initialize libsigrok.

This function must be called before any other libsigrok function.

Parameters
ctxPointer to a libsigrok context struct pointer. Must not be NULL. This will be a pointer to a newly allocated libsigrok context object upon success, and is undefined upon errors.
Returns
SR_OK upon success, a (negative) error code otherwise. Upon errors the 'ctx' pointer is undefined and should not be used. Upon success, the context will be free'd by sr_exit() as part of the libsigrok shutdown.
Since
0.2.0

Definition at line 464 of file backend.c.

References sr_dev_driver::context, SR_ERR, SR_OK, and sr_resource_set_hooks().

+ Here is the call graph for this function: