]> sigrok.org Git - libsigrok.git/commitdiff
rdtech-dps: Retry sr_modbus_read_holding_registers() up to 3 times.
authorFrank Stettner <redacted>
Wed, 1 May 2019 21:18:13 +0000 (23:18 +0200)
committerFrank Stettner <redacted>
Wed, 13 Nov 2019 09:09:07 +0000 (10:09 +0100)
The communication with the rdtech power supplies is not very reliable,
especially during the start. Because of that, the driver tries to read the
modbus registers up to three times.
Nevertheless there is the chance, that the communication fails.

src/hardware/rdtech-dps/protocol.c
src/hardware/rdtech-dps/protocol.h

index 565a2e0246190611f7be0b5c9ad26fa1bac20457..fe34b25700184fef2bb0428838a9c76e83eee235 100644 (file)
 #include <config.h>
 #include "protocol.h"
 
+SR_PRIV int rdtech_dps_read_holding_registers(struct sr_modbus_dev_inst *modbus,
+               int address, int nb_registers, uint16_t *registers)
+{
+       int i, ret;
+
+       i = 0;
+       do {
+               ret = sr_modbus_read_holding_registers(modbus,
+                       address, nb_registers, registers);
+               ++i;
+       } while (ret != SR_OK && i < 3);
+
+       return ret;
+}
+
 SR_PRIV int rdtech_dps_get_reg(const struct sr_dev_inst *sdi,
                uint16_t address, uint16_t *value)
 {
@@ -33,7 +48,7 @@ SR_PRIV int rdtech_dps_get_reg(const struct sr_dev_inst *sdi,
        modbus = sdi->conn;
 
        g_mutex_lock(&devc->rw_mutex);
-       ret = sr_modbus_read_holding_registers(modbus, address, 1, registers);
+       ret = rdtech_dps_read_holding_registers(modbus, address, 1, registers);
        g_mutex_unlock(&devc->rw_mutex);
        *value = RB16(registers + 0);
        return ret;
@@ -67,7 +82,7 @@ SR_PRIV int rdtech_dps_get_model_version(struct sr_modbus_dev_inst *modbus,
         * No mutex here, because there is no sr_dev_inst when this function
         * is called.
         */
-       ret = sr_modbus_read_holding_registers(modbus, REG_MODEL, 2, registers);
+       ret = rdtech_dps_read_holding_registers(modbus, REG_MODEL, 2, registers);
        if (ret == SR_OK) {
                *model = RB16(registers + 0);
                *version = RB16(registers + 1);
@@ -119,6 +134,10 @@ SR_PRIV int rdtech_dps_receive_data(int fd, int revents, void *cb_data)
        devc = sdi->priv;
 
        g_mutex_lock(&devc->rw_mutex);
+       /*
+        * Using the libsigrok function here, because it doesn't matter if the
+        * reading fails. It will be done again in the next acquision cycle anyways.
+        */
        ret = sr_modbus_read_holding_registers(modbus, REG_UOUT, 3, registers);
        g_mutex_unlock(&devc->rw_mutex);
 
index 9e2b23f336378540e117841236d4da759e0f3621..feab0990f3026224b538511dc466b6317c5d586b 100644 (file)
@@ -85,6 +85,9 @@ enum rdtech_dps_mode {
        MODE_CC      = 1,
 };
 
+SR_PRIV int rdtech_dps_read_holding_registers(struct sr_modbus_dev_inst *modbus,
+               int address, int nb_registers, uint16_t *registers);
+
 SR_PRIV int rdtech_dps_get_reg(const struct sr_dev_inst *sdi, uint16_t address, uint16_t *value);
 SR_PRIV int rdtech_dps_set_reg(const struct sr_dev_inst *sdi, uint16_t address, uint16_t value);