2

I am currently trying to make my code safer and more structured. So far, when I want to read an analog input value, I use the following function which works fine:

FILE *fp = popen("cat /sys/bus/iio/devices/iio\\:device0/in_value_raw", "r");
char *ln = NULL;
size_t len = 0;

while (getline(&ln, &len, fp) != -1)
    fputs(ln, stdout);
    free(ln);
    pclose(fp);
int result = atoi(ln);

However, so far, I do not have the means to get error messages or check if the value has been read correctly... Is there a way to change that? I have looked at some articles about "pipe streaming", but since they are always about executing files, I do not know, if I am on the right path...

If you could tell me, how to best approach that problem it would be of great help.

Thank you for your time!

Fabian
  • 91
  • 8
  • 1
    in Linux every device can be open as file. so better to use first open instead of popen and cat inside popen. see device driver interface of that device it may be supplying ASCII Number string per unit time, according to that write your program – rajesh6115 Feb 03 '17 at 02:01

0 Answers0