X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fmodbus.c;h=c04b308d81728e74f4621737b64fb394eb47430d;hb=22651d8d4dc49e24bbac2cd34e0642dcf3639c97;hp=589193811c3a827514a9a5d008ea6c3be419cb8e;hpb=de9cbff39b893f445d678c0a3bc3f8fb0456f42b;p=collectd.git diff --git a/src/modbus.c b/src/modbus.c index 58919381..c04b308d 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -27,7 +27,7 @@ #include -#include +#include #ifndef LIBMODBUS_VERSION_CHECK /* Assume version 2.0.3 */ @@ -47,9 +47,9 @@ /* * * RegisterBase 1234 + * RegisterCmd ReadHolding * RegisterType float * Type gauge - * ModbusRegisterType holding * Instance "..." * * @@ -310,7 +310,9 @@ static int mb_init_connection (mb_host_t *host) /* {{{ */ if (host == NULL) return (EINVAL); +#if COLLECT_DEBUG modbus_set_debug (&host->connection, 1); +#endif /* We'll do the error handling ourselves. */ modbus_set_error_handling (&host->connection, NOP_ON_ERROR); @@ -390,7 +392,9 @@ static int mb_init_connection (mb_host_t *host) /* {{{ */ } } +#if COLLECT_DEBUG modbus_set_debug (host->connection, 1); +#endif /* We'll do the error handling ourselves. */ modbus_set_error_recovery (host->connection, 0); @@ -426,7 +430,7 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */ uint16_t values[2]; int values_num; const data_set_t *ds; - int status; + int status = 0; if ((host == NULL) || (slave == NULL) || (data == NULL)) return (EINVAL); @@ -463,7 +467,6 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */ else values_num = 1; - status = 0; if (host->connection == NULL) { status = EBADF; @@ -733,7 +736,6 @@ static int mb_config_add_data (oconfig_item_t *ci) /* {{{ */ for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; - status = 0; if (strcasecmp ("Type", child->key) == 0) status = cf_util_get_string_buffer (child, @@ -765,19 +767,19 @@ static int mb_config_add_data (oconfig_item_t *ci) /* {{{ */ status = -1; } } - else if (strcasecmp ("ModbusRegisterType", child->key) == 0) + else if (strcasecmp ("RegisterCmd", child->key) == 0) { #if LEGACY_LIBMODBUS - ERROR("Modbus plugin: ModbusRegisterType parameter can not be used " + ERROR("Modbus plugin: RegisterCmd parameter can not be used " "with your libmodbus version"); #else char tmp[16]; status = cf_util_get_string_buffer (child, tmp, sizeof (tmp)); if (status != 0) /* do nothing */; - else if (strcasecmp ("holding", tmp) == 0) + else if (strcasecmp ("ReadHolding", tmp) == 0) data.modbus_register_type = MREG_HOLDING; - else if (strcasecmp ("input", tmp) == 0) + else if (strcasecmp ("ReadInput", tmp) == 0) data.modbus_register_type = MREG_INPUT; else { @@ -894,7 +896,6 @@ static int mb_config_add_slave (mb_host_t *host, oconfig_item_t *ci) /* {{{ */ for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; - status = 0; if (strcasecmp ("Instance", child->key) == 0) status = cf_util_get_string_buffer (child, @@ -945,9 +946,15 @@ static int mb_config_add_host (oconfig_item_t *ci) /* {{{ */ status = cf_util_get_string_buffer (ci, host->host, sizeof (host->host)); if (status != 0) + { + sfree (host); return (status); + } if (host->host[0] == 0) + { + sfree (host); return (EINVAL); + } for (i = 0; i < ci->children_num; i++) {