X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmodbus.c;h=40b6c57a36bfe39eab361032de7c56b74c0a9c7f;hb=c6da31fb30c2fb1d131f92efcde0b3ec9a010b2c;hp=78c43350def7c4af7bca68bfe4c14b8cfdac9cd5;hpb=2413e5f1faeee70920593a3a07f6b7ef997a5e65;p=collectd.git diff --git a/src/modbus.c b/src/modbus.c index 78c43350..40b6c57a 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -24,8 +24,18 @@ #include "plugin.h" #include "configfile.h" +#include + #include +#ifndef MODBUS_TCP_DEFAULT_PORT +# ifdef MODBUS_TCP_PORT +# define MODBUS_TCP_DEFAULT_PORT MODBUS_TCP_PORT +# else +# define MODBUS_TCP_DEFAULT_PORT 502 +# endif +#endif + /* * * RegisterBase 1234 @@ -796,9 +806,8 @@ static int mb_config_add_host (oconfig_item_t *ci) /* {{{ */ else interval.tv_sec = 0; - plugin_register_complex_read (name, mb_read, - (interval.tv_sec > 0) ? &interval : NULL, - &ud); + plugin_register_complex_read (/* group = */ NULL, name, + mb_read, (interval.tv_sec > 0) ? &interval : NULL, &ud); } else { @@ -832,47 +841,6 @@ static int mb_config (oconfig_item_t *ci) /* {{{ */ /* ========= */ -#if 0 -static int foo (void) /* {{{ */ -{ - int status; - uint16_t values[2]; - int values_num; - - if (dev == NULL) - return (EINVAL); - - printf ("mb_read (addr = %i, float = %s);\n", register_addr, - is_float ? "true" : "false"); - - memset (values, 0, sizeof (values)); - if (is_float) - values_num = 2; - else - values_num = 1; - - status = read_holding_registers (dev->connection, - /* slave = */ 1, /* start_addr = */ register_addr, - /* num_registers = */ values_num, /* buffer = */ values); - printf ("read_coil_status returned with status %i\n", status); - if (status <= 0) - return (EAGAIN); - - if (is_float) - { - float value = mb_register_to_float (values[0], values[1]); - printf ("read_coil_status returned value %g (hi %#"PRIx16", lo %#"PRIx16")\n", - value, values[0], values[1]); - } - else - { - printf ("read_coil_status returned value %"PRIu16"\n", values[0]); - } - - return (0); -} /* }}} int foo */ -#endif - static int mb_shutdown (void) /* {{{ */ { data_free_all (data_definitions);