libsigrok  0.3.0
sigrok hardware access and backend library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups 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, 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>
#include <libsigrok/libsigrok.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 381 of file backend.c.

References SR_ERR, and SR_OK.

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 318 of file backend.c.

References SR_ERR, SR_ERR_MALLOC, and SR_OK.