Debian Codegraph @

bindings/python/examples/get_line_value.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 a single line."""
6
7 import gpiod
8
9 from gpiod.line import Direction
10
11
12 def get_line_value(chip_path, line_offset):
13 with gpiod.request_lines(
14 chip_path,
15 consumer="get-line-value",
16 config={line_offset: gpiod.LineSettings(direction=Direction.INPUT)},
17 ) as request:
18 value = request.get_value(line_offset)
19 print("{}={}".format(line_offset, value))
20
21
22 if __name__ == "__main__":
23 try:
24 get_line_value("/dev/gpiochip0", 5)
25 except OSError as ex:
26 print(ex, "\nCustomise the example configuration to suit your situation")