Hi,
Is there a limit to how many times you can open or write to a device file? I have a program which is a continuous loop and is always writing or reading an I2C device file. After about the 1000th time it fails to open the device.
Anybody have an idea?
Here's the code:
Code:
/************************************************************************/
/* read_ad */
/* inputs: I2C address to write to (addr) */
/* outputs: Reading from the A/D in hex (ad_output) */
/* descritpion: Reads I2C A/D chip */
/************************************************************************/
int read_ad(char addr){
sprintf(filename, "/dev/i2c-%d", adapter_nr);
if ((file = open(filename,O_RDWR)) < 0)
{
printf("Error openning device file in read_ad()\n");
exit(1);
}
else{
//printf("Device file opened\n");
}
if (ioctl(file,I2C_SLAVE,addr) < 0)
{
printf("Error with ioctl function in read()\n");
exit(1);
}
if (read(file,ad_output,2) != 2)
{
printf("Error reading A/D chip\n");
}
else{
printf("Device file (A/D chip) reads %x\n", ad_output[0]);
}
}