logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

owcapi - easy C-language 1-wire interface

Author

       Paul Alfille (paul.alfille@gmail.com)

OWFS Manpage                                          2004                                             OWCAPI(3)

Availability

Description

1-Wire1-wire is a wiring protocol and series of devices designed and manufactured by Dallas Semiconductor, Inc.
       The bus is a low-power low-speed low-connector scheme where the data line can also provide power.

       Each device is uniquely and unalterably numbered during manufacture. There are a wide variety of devices,
       including  memory,  sensors (humidity, temperature, voltage, contact, current), switches, timers and data
       loggers. More complex devices (like thermocouple sensors) can be built with these  basic  devices.  There
       are also 1-wire devices that have encryption included.

       The 1-wire scheme uses a single busmaster and multiple slaves on the same wire. The bus master initiates
       all communication. The slaves can be individually discovered and addressed using their unique ID.

       Bus masters come in a variety of configurations including serial, parallel, i2c, network or USB adapters.

   OWFSdesignOWFS  is  a suite of programs that designed to make the 1-wire bus and its devices easily accessible. The
       underlying principle is to create a virtual filesystem, with the unique ID being the directory,  and  the
       individual properties of the device are represented as simple files that can be read and written.

       Details of the individual slave or master design are hidden behind a consistent interface. The goal is to
       provide  an easy set of tools for a software designer to create monitoring or control applications. There
       are some performance enhancements in the implementation, including data caching, parallel access  to  bus
       masters,  and  aggregation  of  device  communication.  Still  the fundamental goal has been ease of use,
       flexibility and correctness rather than speed.

   libowcapilibowcapi(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 %s0,buf);
       free(buf);
       OW_finish() ;

Functions

OW_initOW_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_argsOW_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_presentOW_present is used to check presence of a 1-wire device.

       Argumentspath 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_getOW_get  is  used  to  get  directory  listings  and  file  contents. The results are put in a dynamically
       allocated buffer.

       Argumentspath 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 bufferReturns
              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.

       Importantnotebuffer is allocated ( with malloc ) by OW_get but must be freed in your program.  See  malloc(3)
              and free(3)OW_lreadOW_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.

       Argumentspath  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_putOW_put is an easy way to write to 1-wire chips.

       Argumentspath 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_lwriteOW_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.

       Argumentspath 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_levelOW_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)

       Argumentsparams 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_printOW_set_error_print sets where the debug output should be directed. 0=mixed output, 1=syslog, 2=console.

       Argumentsparams 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_finishOW_finish cleans up the OWFS 1-wire routines, releases devices and memory.

       Arguments
              None.

       Returns
              None

       SequenceOW_finish is optional since cleanup is automatic on program exit.

Name

owcapi - easy C-language 1-wire interface

See Also

Programsowfs(1)owhttpd(1)owftpd(1)owserver(1)owdir(1)owread(1)owwrite(1)owpresent(1)owtap(1)Configurationandtestingowfs(5)owtap(1)owmon(1)Languagebindingsowtcl(3)owperl(3)owcapi(3)ClocksDS1427(3)DS1904(3)DS1994(3)DS2404(3)DS2404S(3)DS2415(3)DS2417(3)IDDS2401(3)DS2411(3)DS1990A(3)MemoryDS1982(3)DS1985(3)DS1986(3)DS1991(3)DS1992(3)DS1993(3)DS1995(3)DS1996(3)DS2430A(3)DS2431(3)DS2433(3)DS2502(3)DS2506(3)DS28E04(3)DS28EC20(3)SwitchesDS2405(3)DS2406(3)DS2408(3)DS2409(3)DS2413(3)DS28EA00(3)TemperatureDS1822(3)DS1825(3)DS1820(3)DS18B20(3)DS18S20(3)DS1920(3)DS1921(3)DS1821(3)DS28EA00(3)DS28E04(3)HumidityDS1922(3)VoltageDS2450(3)ResistanceDS2890(3)Multifunction(current,voltage,temperature)DS2436(3)DS2437(3)DS2438(3)DS2751(3)DS2755(3)DS2756(3)DS2760(3)DS2770(3)DS2780(3)DS2781(3)DS2788(3)DS2784(3)CounterDS2423(3)LCDScreenLCD(3)DS2408(3)CryptoDS1977(3)PressureDS2406(3)--TAI8570

Synopsis

libowcapi library to link with your program

   Initializationssize_tOW_init(devicenameorfullparameterstring)ssize_tOW_init_args(intargc,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)GetdataintOW_present(constchar*path)intOW_get(constchar*path,char**buffer,size_t*buffer_length)ssize_tOW_lread(constchar*path,unsignedchar*buffer,constsize_tsize,constoff_toffset)Setdatassize_tOW_put(constchar*path,constchar*buffer,size_t*buffer_length)ssize_tOW_lwrite(constchar*path,constunsignedchar*buffer,constsize_tsize,constoff_toffset)DebugvoidOW_set_error_level(constchar*param)voidOW_set_error_print(constchar*param)ClosevoidOW_finish(void)

See Also