Debian Codegraph @

bindings/python/examples/get_line_info.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # SPDX-FileCopyrightText: 2023 Kent Gibson <[email protected]>
4
5 """Minimal example of reading the info for a line."""
6
7 import gpiod
8
9
10 def get_line_info(chip_path, line_offset):
11 with gpiod.Chip(chip_path) as chip:
12 info = chip.get_line_info(line_offset)
13 is_input = info.direction == gpiod.line.Direction.INPUT
14 print(
15 "line {:>3}: {:>12} {:>12} {:>8} {:>10}".format(
16 info.offset,
17 info.name or "unnamed",
18 info.consumer or "unused",
19 "input" if is_input else "output",
20 "active-low" if info.active_low else "active-high",
21 )
22 )
23
24
25 if __name__ == "__main__":
26 try:
27 get_line_info("/dev/gpiochip0", 3)
28 except OSError as ex:
29 print(ex, "\nCustomise the example configuration to suit your situation")