OWCAPI(1)
π OWCAPI(1) β owcapi π
okay so. bestie. you want to talk to a 1-wire bus from C and you don't want to suffer? say less. this is owcapi, the easy C-language 1-wire interface β¨ it's the manual page, it's section 1, and it's about to make your whole week.
πΈ SYNOPSIS πΈ
link your program against the libowcapi library. that's it, that's the vibe π«Ά
π§ 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). iykyk π
π 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. she's versatile, she's giving main character energy β¨
Arguments β can be as simple as jus the device name, or a full parameter specification. one or more device names (includes tcp, serial, usb...) plus command line switches. see owfs (1) for full syntax. π
Returns β 0 for success. -1 on error and errno will be set. and listen: OW_finish does not need to be called if OW_init fails. periodt π
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. same energy, different shape π«Ά
Arguments β one or more device names (includes tcp, serial, usb...) plus command line switches. see owfs (1) for full syntax. unlike OW_init_string, the arguments are in argv/argc format. so if you already have your argv/argc sitting there, she ate π₯
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. is she there? vibe check π
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). bestie please free your buffer, don't leave her hanging π
π§ 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. no cap, it's the simple route π
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. they're a duo, your honor π
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. tidy queen π§Ήβ¨
Arguments β none.
Returns β none.
Sequence β OW_finish is optional since cleanup is automatic on program exit.
π¦ DESCRIPTION π¦
β 1-Wire
1-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. iconic design honestly.
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 bus master 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.
πΈ OWFS design
OWFS 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. priorities, she has them π
π 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 %s0,buf);
free(buf);
OW_finish() ;
π SEE ALSO π
Programs
owfs (1) owhttpd (1) owftpd (1) owserver (1) owdir (1) owread (1) owwrite (1) owpresent (1) owtap (1)
Configuration and testing
owfs (5) owtap (1) owmon (1)
Language bindings
owtcl (3) owperl (3) owcapi (3)
Clocks
DS1427 (3) DS1904(3) DS1994 (3) DS2404 (3) DS2404S (3) DS2415 (3) DS2417 (3)
ID
DS2401 (3) DS2411 (3) DS1990A (3)
Memory
DS1982 (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)
Switches
DS2405 (3) DS2406 (3) DS2408 (3) DS2409 (3) DS2413 (3) DS28EA00 (3)
Temperature
DS1822 (3) DS1825 (3) DS1820 (3) DS18B20 (3) DS18S20 (3) DS1920 (3) DS1921 (3) DS1821 (3) DS28EA00 (3) DS28E04 (3)
Humidity
DS1922 (3)
Voltage
DS2450 (3)
Resistance
DS2890 (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)
Counter
DS2423 (3)
LCD Screen
LCD (3) DS2408 (3)
Crypto
DS1977 (3)
Pressure
DS2406 (3) -- TAI8570
π AVAILABILITY π
π AUTHOR π
Paul Alfille (paul.alfille@gmail.com)
and that's the whole page bestie, slay π β¨ this one came out of the OWFS Manpage, dated 2004 β go build something iconic with it π«Άπ
π¦ where this page comes from
- alpine 3.24: owfs-doc 3.2_p4-r1 Β· GPL-2.0-only
- fedora 43: owfs-capi 3.2p4-13.fc43 Β· GPL-2.0-only
- fedora 43: owfs-capi 3.2p4-13.fc43 Β· GPL-2.0-only
- fedora 43: owfs-devel 3.2p4-13.fc43 Β· GPL-2.0-only
- fedora 43: owfs-devel 3.2p4-13.fc43 Β· GPL-2.0-only
- fedora 44: owfs-capi 3.2p4-15.fc44 Β· GPL-2.0-only
- fedora 44: owfs-capi 3.2p4-15.fc44 Β· GPL-2.0-only
- fedora 44: owfs-devel 3.2p4-15.fc44 Β· GPL-2.0-only
- fedora 44: owfs-devel 3.2p4-15.fc44 Β· GPL-2.0-only
- nixos 26.05: libow 3.2p4
- nixpkgs unstable: libow 3.2p4
- Copyright (c) 2003-2006 Paul H Alfille, MD
- Copyright (c) 2003-2004 Paul H Alfille, MD
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms