summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2413e5f)
raw | patch | inline | side by side (parent: 2413e5f)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 27 Mar 2010 14:01:35 +0000 (15:01 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 27 Mar 2010 14:01:35 +0000 (15:01 +0100) |
The API of the library changes every other month, so be conservative and
use the "stable" version, released in May 2008, and hope *that* API is
somewhat stable.
use the "stable" version, released in May 2008, and hope *that* API is
somewhat stable.
src/modbus.c | patch | blob | history |
diff --git a/src/modbus.c b/src/modbus.c
index 78c43350def7c4af7bca68bfe4c14b8cfdac9cd5..5dc958f6b9434cb5ea0e56cae7976eb1633e2838 100644 (file)
--- a/src/modbus.c
+++ b/src/modbus.c
#include "plugin.h"
#include "configfile.h"
+#include <netdb.h>
+
#include <modbus/modbus.h>
+#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
+
/*
* <Data "data_name">
* RegisterBase 1234
modbus_set_debug (&host->connection, 1);
+#if 0
/* We'll do the error handling ourselves. */
modbus_set_error_handling (&host->connection, NOP_ON_ERROR);
+#endif
if ((host->port < 1) || (host->port > 65535))
host->port = MODBUS_TCP_DEFAULT_PORT;
host->node, host->port);
modbus_init_tcp (&host->connection,
- /* host = */ host->node,
+ /* host = */ host->node);
+#if 0
/* port = */ host->port);
+#endif
status = modbus_connect (&host->connection);
if (status != 0)
static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */
mb_data_t *data)
{
- uint16_t values[2];
+ int values[2];
int values_num;
const data_set_t *ds;
int status;
/* ========= */
-#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);