OWCAPI(1)

NAME
owcapi - easy C-language 1-wire interface

SYNOPSIS
libowcapi library to link with your program

  Initialization
ssize_t OW_init( device name or full parameter string )
ssize_t OW_init_args( int argc, char ** args )

The full set of initialization options is extensive. They correspond roughly to the command line options of owfs (1) owhttpd (1) and owftpd (1)

  Get data
int OW_present( const char * path )
int OW_get( const char * path, char ** buffer, size_t * buffer_length )
ssize_t OW_lread( const char * path, unsigned char * buffer, const size_t size, const off_t offset )

  Set data
ssize_t OW_put( const char * path, const char * buffer, size_t * buffer_length )
ssize_t OW_lwrite( const char * path, const unsigned char * buffer, const size_t size, const off_t offset )

  Debug
void OW_set_error_level( const char *param )
void OW_set_error_print( const char *param )

  Close
void OW_finish( void )

FUNCTIONS

  OW_init
OW_init_string offers the full flexibility of the owfs (1) and owhttpd (1) command line.

Arguments
    Can be as simple as jus the device name, a full parameter specification. One or more device names (includes tcp, serial, usb...) and command line switches. See owfs (1) for full syntax.

Returns
    0 for success. -1 on error and errno will be set. OW_finish does not need to be called if OW_init fails.

Sequence
    One of the init functions must be called before accessing the 1-wire bus. OW_finish is optional.

  OW_init_args
OW_init_args offers the full flexibility of the owfs (1) and owhttpd (1) command line.

Arguments
    One or more device names (includes tcp, serial, usb...) and command line switches. See owfs (1) for full syntax. Unlike OW_init_string the arguments are in argv/argc format.

Returns
    0 for success. -1 on error and errno will be set. OW_finish does not need to be called if OW_init fails.

Sequence
    One of the init functions must be called before accessing the 1-wire bus. OW_finish is optional.

  OW_present
OW_present is used to check presence of a 1-wire device.

Arguments
    path is the path to the directory or file (property).

Returns
    0 on success. -1 on error (and errno is set).

Sequence
    One of the init functions must be called before accessing the 1-wire bus. OW_finish is optional.

  OW_get
OW_get is used to get directory listings and file contents. The results are put in a dynamically allocated buffer.

Arguments
    path is the path to the directory or file (property). *buffer returns a pointer to a buffer containing the directory (comma separated) or value. buffer_length returns the length of the value/string in buffer

Returns
    number of bytes on success. -1 on error (and errno is set).

Sequence
    One of the init functions must be called before accessing the 1-wire bus. OW_finish is optional.

Important note
    buffer is allocated ( with malloc ) by OW_get but must be freed in your program. See malloc (3) and free (3)

  OW_lread
OW_lread is used to read 1-wire memory chips. Think of it as a combination of lseek and read It allows random-access to the memory, specifying location and length. Unlike OW_get directories cannot be obtained and the buffer must be pre-allocated rather than allocated by the routine. buffer must be at least size length.

Arguments
    path is the path to the file (property). buffer is the (pre-allocated) memory area where the value will be placed. size is the length of bytes requested. offset is the position in file to start reading.

Returns
    number of bytes on success. -1 on error (and errno is set).

Sequence
    One of the init functions must be called before accessing the 1-wire bus. OW_finish is optional.

  OW_put
OW_put is an easy way to write to 1-wire chips.

Arguments
    path is the path to the file (property). buffer is the value to be written. buffer_length is the length of the value buffer. Returns number of bytes on success. -1 on error (and errno is set).

Sequence
    One of the init functions must be called before accessing the 1-wire bus. OW_finish is optional.

  OW_lwrite
OW_lwrite is the companion of OW_lread. It allows writing to arbitrary positions in 1-wire memory. Think of it as a combination of lseek and write. buffer must be at least size length.

Arguments
    path is the path to the file (property). buffer is the data to be written. size is the length of bytes to be written. offset is the position in file to start writing.

Returns
    number of bytes on success. -1 on error (and errno is set).

Sequence
    One of the init functions must be called before accessing the 1-wire bus. OW_finish is optional.

  OW_set_error_level
OW_set_error_level sets the debug output to a certain level. 0 is default, and higher value gives more output.
(0=default, 1=err_connect, 2=err_call, 3=err_data, 4=err_detail, 5=err_debug, 6=err_beyond)

Arguments
    params is the level. Should be an integer.

Returns
    None

Sequence
    One of the init functions must be called before setting the level, since init defaults to level 0.

  OW_set_error_print
OW_set_error_print sets where the debug output should be directed. 0=mixed output, 1=syslog, 2=console.

Arguments
    params is the level. Should be an integer between 0 and 2.

Returns
    None

Sequence
    One of the init functions must be called before setting the level, since init defaults to 0 (mixed output).

  OW_finish
OW_finish cleans up the OWFS 1-wire routines, releases devices and memory.

Arguments
    None.

Returns
    None

Sequence
    OW_finish is optional since cleanup is automatic on program exit.

DESCRIPTION

  libowcapi
libowcapi (1) is an encapsulation of the full libow library for C programs.

libowcapi (1) allows a C program to use OWFS principles (consistent naming scheme, multiple adapters, devices, and compatibility) directly from a C program. There are analogous modules for other programming languages:

C   libowcapi

perl
    owperl

php owphp

python
    owpython

tcl owtcl

EXAMPLE
/* Simple directory listing -- no error checking */
#include <owcapi.h>
unsigned char * buf;
size_t s ;
OW_init("/dev/ttyS0");
OW_set_error_print("2");
OW_set_error_level("6");
OW_get("/",&buf,&s) ;
printf("Directory %s,buf);
free(buf);
OW_finish() ;

SEE ALSO

AVAILABILITY
http://www.owfs.org

AUTHOR
Paul Alfille (paul.alfille@gmail.com)