Hello, 

  I think I can sugest something to you. 
  First you can set the value of buf to '0' and after that check all the 
return value of read. So this way you must be sure if it is really caching 
something. Like this: 

while(1) { 
  char[64] buf; 
  nread = 0; 
  memset(buf,'\0',sizeof(buf)); 
  nread = read(fd,buf,siezof(buf)); 

  if (nread) 
     do_something 
  ... 
  sleep(5); 
} 

  I think it is a nice thing to try to find the problem. 


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? 

Reply via email to