diff options
-rw-r--r-- | src/main.c | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -61,21 +61,29 @@ void print_help(void) { } void bus_err(int ern){ - printf("I2C communication(rd) error. errno: %d\n",errno); + //printf("I2C communication(rd) error. errno: %d\n",errno); + fprintf (stderr, "Internal error %d at %s, line %d. (function: %s/%s)", ern, __FILE__, __LINE__, __func__, __FUNCTION__); +} +void bus_errr(int ern){ + //printf("I2C communication(rd) error. errno: %d\n",errno); + fprintf (stderr, "Internal error %d at %s, line %d. (function: %s/%s)", errno, __FILE__, __LINE__, __func__, __FUNCTION__); } - uchar *xchg_data (uchar *buf, uint16 wrlen, uint16 waitlen, uint16 rdlen){ //# [buf] = 32 byte if(write(devicef, buf, 1) != 1){ //# write one byte to device perror("I2C communication(wrr) error."); - printf("errno: %d\n",errno); + fprintf (stderr, "I2C error (WR) %d at %s, line %d. (function: %s/%s)", errno, __FILE__, __LINE__, __func__, __FUNCTION__); + bus_err(errno); + bus_errr(0); } usleep(waitlen*1000); //# Wait 10ms for reading if(read(devicef, buf, rdlen) != rdlen) { //# read the result perror("I2C communication(rd) error."); - printf("errno: %d\n",errno); + fprintf (stderr, "I2C error (WR) %d at %s, line %d. (function: %s/%s)", errno, __FILE__, __LINE__, __func__, __FUNCTION__); + bus_err(errno); + bus_errr(0); } return buf; } |