linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* open() and read() a file from sysfs
@ 2005-02-28 14:18 krzaq
  2005-03-01  1:17 ` simon
  0 siblings, 1 reply; 3+ messages in thread
From: krzaq @ 2005-02-28 14:18 UTC (permalink / raw)
  To: linux-c-programming

Hi all!

I have a basic question with file opening.
I would like to make use of the data accessed from i2c sensors through sysfs.

Here's the code:

fd = open(/sys/bus/i2c/.../temp2_input,O_RDONLY);

while(1) {
  char[64] buf;
  read(fd,buf,siezof(buf));
  ...
  do_something
  ...
  sleep(5);
}

The thing is I always get the same reading in each read() :(.
When I do:
# cat /sys/bus/i2c.../temp2_input
I see that the temperature is changing, but my code still displays the
same reading.

So what's the deal? Why is it cached?
Am I supposed to open() and close() the file inside 'while' loop??
What's the proper way to do it?

-- 
Regards
Karol Krzak

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-03-01  8:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-28 14:18 open() and read() a file from sysfs krzaq
2005-03-01  1:17 ` simon
2005-03-01  8:58   ` krzaq

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).