Retrieving the result of a 'cat' command into a Lazarus app lazarus / 32-Linux ---------------------------------------------------------------------- MartynA · 2017-12-09 13:34 Hi, I'm using Rasbian on an RPi 3. If I execute this cat /sys/class/gpio/gpio22/value in Terminal, it correctly reports the state of a push-to-make switch across port#22 and Gnd (with pull-up resistor) as 1 or 0.  The 1 or zero is displayed in Terminal on the next line, of course. If I do this in my app:   S := 'cat /sys/class/gpio/gpio22/value >';   Res := fpsystem(S); , Res always returns zero, which I guess is telling me that the command executed without error, rather than what the value on port#22  was.  So, My question is, how do I read the 1 or 0 from my Lazarus app?  Btw, in my app, I want to be able to poll the input from the port many times per second, so I doubt that sending the output of cat to a disk file would be fast enough. TIA, Martyn ---------------------------------------------------------------------- Thaddy · 2017-12-09 15:32 /sys/class/gpio/gpio22/value  does not exist on my Raspberry Pi 3's all of them run stretch. But something along this line should work: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program catweasel;{$mode objfpc}{$H+}uses sysutils, classes;var s:TStringlist;begin  s:= TStringlist.Create;  try    if FileExists('/sys/class/gpio/gpio22/value') then    begin      s.LoadFromFile('/sys/class/gpio/gpio22/value');      writeln(s.text);    end else      writeln('File does not exist');  finally    s.free;  end;end. ---------------------------------------------------------------------- MartynA · 2017-12-09 15:44 Not quite sure what you mean by "does not exist".  Physically, port 22 is pin 15 on my RPi3. And, if I redirect the output of the cat command I quoted to a file, it works fine.  Did you do the necessary set-up:  exporting the port and setting its direction to "In"? Cheers, Martyn ---------------------------------------------------------------------- Thaddy · 2017-12-09 15:46 Post crossed. Did you check my example code? ---------------------------------------------------------------------- MartynA · 2017-12-09 16:22 Yes, it works thanks, which would save me the trouble of redirecting it elsewhere. But the purpose of my q was to see  if there is a way of doing it without accessing the file system. ---------------------------------------------------------------------- Thaddy · 2017-12-09 16:28 In linux "everything is a file". It will be fast enough. Then again, look at several of the GPIO options in the wiki. http://wiki.freepascal.org/Lazarus_on_Raspberry_Pi ---------------------------------------------------------------------- MartynA · 2017-12-09 16:38 Thanks. >Then again, look at several of the GPIO options in the wiki. I have been, that's what my other 2 qs here have been about. >In linux "everything is a file". It will be fast enough. I'm not sure that the file system will be fast enough.  It wasn't for the "encapsulated shell calls" example - see my thread here:https://forum.lazarus.freepascal.org/index.php/topic,39177.0.html It turned out that the reason I couldn't get the encapsulated shell calls to work initially was because the system didn't react fast enough until I introduced some Sleep()s between calls. ---------------------------------------------------------------------- Thaddy · 2017-12-09 16:44 Quote from: MartynA on December 09, 2017, 05:38:44 pmI'm not sure that the file system will be fast enough. It is a *virtual* file system: Linux doesn't access the *disk* but the kernel space for such device directories. A common misconception for people coming from windows. ---------------------------------------------------------------------- MartynA · 2017-12-09 16:55 Yes, I already got that thanks.