Assume InvalidGpioHandle is -1. That wasn't so much working demo code as an illustration of how to call the entry points, noting IN PARTICULAR that the leading "Gpiod." is REQUIRED for both the static and dynamic variants.
Apart from that, the function of the various entry points is as described in the documentation for the gpiod library. I suggest familiarising yourself with that and with their examples: my units are a /very/ thin wrapper around that with no attempt to convert their API into something object-based.
Looking briefly at your code, use EITHER the gpiod unit, OR the gpiod_dynamic unit, not both since that has your program trying to use two different library interfaces for the same functionality. I would suggest using gpiod_dynamic, since (a) that doesn't need the -dev package and (b) I've already pointed out that some of the documented gpiod functionality (i.e. from the POV of the kernel developers) isn't actually in the library version shipped by Debian so might or might not be in the one shipped by Raspbian, and if you use dynamic linkage you'll get a run-time exception which you can work around.
I've not got code that you can easily drop into a project and run, but below are two snippets that you can use to see the sequence I've used... apart from that you're going to have to read the documentation.
Assume that e indicates whether a line is enabled, x whether it needs to be inverted (xor operation) and v its value. You don't want to see the GUI stuff.
e := true;
v := 0;
lineHandle := Gpiod.gpiod_chip_get_line(chipHandle, i);
if lineHandle = nil then
e := false;
if e and Gpiod.gpiod_line_is_used(lineHandle) then
e := false;
if e and (Gpiod.gpiod_line_direction(linehandle) <> GPIOD_LINE_DIRECTION_INPUT) then
e := false;
if e and (Gpiod.gpiod_line_request_input(lineHandle, Pchar('GuiTest')) <> 0) then
e := false;
if e then
// Older versions of libgpiod e.g. as shipped with Debian "Buster" might not
// support this entry point.
try
x := Gpiod.gpiod_line_is_active_low(lineHandle)
except
x := false
end
else
x := false;
if e then begin (* Accessible and input *)
v := Gpiod.gpiod_line_get_value(lineHandle); // Bit from GPIO
if not (v in [0, 1]) then
continue;
v := v xor Ord(x);
linesForDisplay.Append(Format('d%d:%d', [i - lowest, v])); // Bit to GUI
Gpiod.gpiod_line_release(lineHandle)
end
end;
...
e := true;
v := Ord(guiTestForm.DigitalOutValue[i - lowest]); // Bit from GUI
lineHandle := Gpiod.gpiod_chip_get_line(chipHandle, i);
if lineHandle = nil then
e := false;
if e and Gpiod.gpiod_line_is_used(lineHandle) then
e := false;
if e and (Gpiod.gpiod_line_direction(linehandle) <> GPIOD_LINE_DIRECTION_OUTPUT) then
e := false;
if e and (Gpiod.gpiod_line_request_output(lineHandle, Pchar('GuiTest'), 0) <> 0) then
e := false;
if e then
// Older versions of libgpiod e.g. as shipped with Debian "Buster" might not
// support this entry point.
try
x := Gpiod.gpiod_line_is_active_low(lineHandle)
except
x := false
end
else
x := false;
if e then begin (* Accessible and output *)
if Gpiod.gpiod_line_set_value(lineHandle, Ord((v <> 0) xor x)) = 0 then // Bit to GPIO
linesForDisplay.Append(Format('d%d:%d', [i - lowest, Ord((v <> 0) xor x)])); // Bit to GUI
Gpiod.gpiod_line_release(lineHandle)
end
I've not investigated using that API to set directions. What I've done so far is set them using the sysfs API, then unexport the line to make it unused hence available to the dev interface. As I've already written up, there's a gpiod program to show you chip/line status.
I've been working hard outdoors all day, and now have to do paperwork.
MarkMLl