hello
krzaq wrote:
ok... i suggest you to read the return value of read...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.
in your code, you can't see if an error append...
reinit your buffer with memset can be a good idea...
in your programm, we can imagine a first correct read, a second who return an error... you don't detect it... and you read an unchanged buffer...
ok that's not your only problem...
try something like that :
char buf[SIZE]; int fd;
if ((fd = open(/sys/bus/i2c/.../temp2_input,O_RDONLY)) == -1)
{
perror ("open ()");
return (-1);
}
while (1)
{
memset (buf, 0, SIZE);
if (read (fd, buf, SIZE) != SIZE)
{
fprintf (stderr, "bad read size... bla bla\n");
return (-1);
}
...
do what you want
...
lseek (buf, 0, SEEK_SET);
}lseek is possible as files in /sys are specials... open, read and write methods are directly handle by drivers...
don't expect to do that with classic files
simon - To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
