]> sigrok.org Git - libsigrok.git/commitdiff
modbus: Return explicit SR_ERR values as required by modbus.c
authorJames Churchill <redacted>
Sun, 18 Feb 2018 06:54:01 +0000 (16:54 +1000)
committerJames Churchill <redacted>
Mon, 26 Mar 2018 05:41:01 +0000 (15:41 +1000)
The Modbus RTU implementation was inappropriately returning lengths
from the serial functions when the calling functions expect only an
sr_error_code value.

src/modbus/modbus_serial_rtu.c

index 4b15d241fcdf14c1b35a761b60d4814b0b429008..065c25f67a355f23316bb5a186aad1300ec2be42 100644 (file)
@@ -111,18 +111,18 @@ static int modbus_serial_rtu_send(void *priv,
 
        result = serial_write_blocking(serial, &slave_addr, sizeof(slave_addr), 0);
        if (result < 0)
-               return result;
+               return SR_ERR;
 
        result = serial_write_blocking(serial, buffer, buffer_size, 0);
        if (result < 0)
-               return result;
+               return SR_ERR;
 
        crc = modbus_serial_rtu_crc(0xFFFF, &slave_addr, sizeof(slave_addr));
        crc = modbus_serial_rtu_crc(crc, buffer, buffer_size);
 
        result = serial_write_blocking(serial, &crc, sizeof(crc), 0);
        if (result < 0)
-               return result;
+               return SR_ERR;
 
        return SR_OK;
 }
@@ -135,11 +135,11 @@ static int modbus_serial_rtu_read_begin(void *priv, uint8_t *function_code)
 
        ret = serial_read_blocking(modbus->serial, &slave_addr, 1, 500);
        if (ret != 1 || slave_addr != modbus->slave_addr)
-               return ret;
+               return SR_ERR;
 
        ret = serial_read_blocking(modbus->serial, function_code, 1, 100);
        if (ret != 1)
-               return ret;
+               return SR_ERR;
 
        modbus->crc = modbus_serial_rtu_crc(0xFFFF, &slave_addr, sizeof(slave_addr));
        modbus->crc = modbus_serial_rtu_crc(modbus->crc, function_code, 1);
@@ -167,7 +167,7 @@ static int modbus_serial_rtu_read_end(void *priv)
 
        ret = serial_read_blocking(modbus->serial, &crc, sizeof(crc), 100);
        if (ret != 2)
-               return ret;
+               return SR_ERR;
 
        if (crc != modbus->crc) {
                sr_err("CRC error (0x%04X vs 0x%04X).", crc, modbus->crc);