aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGergő J. Miklós2020-10-16 23:47:49 +0200
committerGergő J. Miklós2020-10-16 23:47:49 +0200
commit89402128bb7e993a375cf54476e3627826dc071c (patch)
treeba75fbe14db5e73d8ec256e27458b71c06c46341 /src
parent521dad36cb4533e423fe14602165a534080b7344 (diff)
downloadi2sensors-89402128bb7e993a375cf54476e3627826dc071c.tar.gz
i2sensors-89402128bb7e993a375cf54476e3627826dc071c.zip
i2sensors: some errorhandling
Diffstat (limited to 'src')
-rw-r--r--src/main.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index d9644be..3ba3da3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -100,11 +100,11 @@ __uint8_t *xchg_data (__uint8_t *buf, __uint16_t wrlen, __uint16_t waitlen, _
#ifdef WITH_I2C_SMBUS
} else if ( funcs && I2C_FUNC_SMBUS_WORD_DATA ){
- if(i2c_smbus_write_byte(devicef, buf[0] ) == -1){ //# write one byte to device
+ if(i2c_smbus_write_byte(devicef, buf[0] ) < 0){ //# write one byte to device
fprintf (stderr, "I2C write error: [NO: %d, MSG: %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__);
}
usleep(waitlen*1000); //# Wait 10ms for reading
- if((data = i2c_smbus_read_word_data(devicef, buf[0])) == -1) { //# read the result
+ if((data = i2c_smbus_read_word_data(devicef, buf[0])) < 0) { //# read the result
fprintf (stderr, "I2C read error: [NO: %d, MSG: %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__);
} else {
buf[0] = data & 0x0FF;
@@ -166,9 +166,9 @@ int main( int argc, char *argv[] ){
if( argc > 4 ){ //If not get_info was called
if(argv[4][0]=='0' && argv[4][1]=='x'){ //# Hexadecimal representetion of device address
- addr = (int)strtol(argv[4], NULL, 0); //# strtol() is working with hex-string correctly
+ addr = (long)strtol(argv[4], NULL, 0); //# strtol() is working with hex-string correctly
- if (ioctl(devicef, I2C_SLAVE, addr) < 0){ //# Seeking/Opening the device on the Bus
+ if (ioctl(devicef, I2C_SLAVE_FORCE, addr) < 0){ //# Seeking/Opening the device on the Bus
//printf("\n\tCan't open i2c DEVICE, errno: %d\n\n",errno);
fprintf (stderr, "\n\tCan't open i2c DEVICE! [ERR: %d, MSG: %s] at %s, line %d. \n", errno, strerror(errno), __FILE__, __LINE__);
exit(EXIT_FAILURE);