IBASE MRS-801-RE User Manual

Page 85

Advertising
background image

Copyright © 2013 IBASE Technology Inc. All Rights Reserved.

77

IBASE Technology Inc.

if (file < 0 && (errno == ENOENT || errno == ENOTDIR)) {

sprintf(filename, "/dev/i2c-%d", i2cbus);

file = open(filename, O_RDWR);

}

if (file < 0 && !quiet) {

if (errno == ENOENT) {

fprintf(stderr, "Error: Could not open file "

"`/dev/i2c-%d' or `/dev/i2c/%d': %s\n",

i2cbus, i2cbus, strerror(ENOENT));

} else {

fprintf(stderr, "Error: Could not open file "

"`%s': %s\n", filename, strerror(errno));

if (errno == EACCES)

fprintf(stderr, "Run as root?\n");

}

}

return file;

}

int set_slave_addr(int file, int address, int force)

{

/* With force, let the user read from/write to the registers

even when a driver is also running */

if (ioctl(file, force ? I2C_SLAVE_FORCE : I2C_SLAVE, address) < 0) {

fprintf(stderr,

"Error: Could not set address to 0x%02x: %s\n",

address, strerror(errno));

return -errno;

}

return 0;

}

/*

i2cbusses.h

*/

Advertising