Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5197

Python • Re: gpiod documentation

$
0
0
Another thing if you are running Python you can get some help about gpiod . From the Python prompt:
>>> import gpiod
>>> help("gpiod")

The output will go to the default screen.

If you want to capture that output and send it to a file I found this Python code somewhere online:
Important: change the fname string to an a value appropriate for your system.

Code:

# simplified version of sending help() output to a fileimport gpiodimport sys# save present stdoutout = sys.stdoutfname = "/home/mistered/Desktop/gpiod_help.txt"# set stdout to file handlesys.stdout = open(fname, "w")# run your help code# its console output goes to the file nowhelp("gpiod")sys.stdout.close()# reset stdout
Here is a first few lines for the gpiod help:

Code:

Help on module gpiod:NAME    gpiod - Python bindings for libgpiod.DESCRIPTION    This module wraps the native C API of libgpiod in a set of python classes.CLASSES    builtins.object        Chip        ChipIter        Line        LineBulk        LineEvent        LineIter        class Chip(builtins.object)     |  Represents a GPIO chip.     |       |  Chip object manages all resources associated with the GPIO chip     |  it represents.     |       |  The gpiochip device file is opened during the object's construction.     |  The Chip object's constructor takes a description string as argument the     |  meaning of which depends on the second, optional parameter which defines     |  the way the description string should be interpreted. The available     |  options are: OPEN_BY_LABEL, OPEN_BY_NAME, OPEN_BY_NUMBER, OPEN_BY_PATH,     |  and OPEN_LOOKUP. The last option means that libgpiod should open the chip     |  based on the best guess what the path is. This is also the default if the     |  second argument is missing.     |       |  Callers must close the chip by calling the close() method when it's no     |  longer used.     |       |  Example:     |       |      chip = gpiod.Chip('gpiochip0', gpiod.Chip.OPEN_BY_NAME)     |      do_something(chip)     |      chip.close()     |       |  The gpiod.Chip class also supports controlled execution ('with' statement).     |       |  Example:     |       |      with gpiod.Chip('0', gpiod.Chip.OPEN_BY_NUMBER) as chip:     |          do_something(chip)     |  

Statistics: Posted by MisterEd — Thu Mar 21, 2024 12:40 am



Viewing all articles
Browse latest Browse all 5197

Trending Articles