aboutsummaryrefslogtreecommitdiffstats
path: root/verteco.c
diff options
context:
space:
mode:
authorJonathan McCrohan <jmccrohan@gmail.com>2011-10-15 14:44:28 +0100
committerJonathan McCrohan <jmccrohan@gmail.com>2011-10-15 14:44:28 +0100
commita2b89c88185d680051076e9b341c8b8f6cf5b25d (patch)
tree2d8457d844d57a4696c948e1b59b4404dd58925d /verteco.c
parente60a7cc135af7ee738d67ecc7bd02ce18963ace6 (diff)
downloadverteco-a2b89c88185d680051076e9b341c8b8f6cf5b25d.tar.gz
Add GPLv3 licence.
Diffstat (limited to 'verteco.c')
-rw-r--r--verteco.c97
1 files changed, 0 insertions, 97 deletions
diff --git a/verteco.c b/verteco.c
deleted file mode 100644
index 91391dd..0000000
--- a/verteco.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/ gcc verteco.c -o verteco `pkg-config --libs --cflags libmodbus libconfig`
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#include <libconfig.h>
-#include <modbus.h>
-
-#define SLAVE_ID 1
-#define START_ADDRESS 0
-#define NUMBER_REGISTERS 14
-#define DEBUG 1
-
-int main(int argc, char *argv[])
-{
-
-const char *CONFIG_FILE = "verteco.cfg";
-
- config_t cfg;
- //config_setting_t *setting;
-
- const char *modbus_device_address;
- int modbus_baud_rate;
- int modbus_data_bits;
- const char *modbus_parity;
- int modbus_stop_bits;
-
- config_init(&cfg);
-
-
- if(!config_read_file(&cfg, CONFIG_FILE))
- {
- fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg),
- config_error_line(&cfg), config_error_text(&cfg));
- config_destroy(&cfg);
- fprintf(stderr, "Unable to find CONFIG_FILE.\n");
- return -1;
- }
-
- modbus_t *ctx;
- uint16_t tab_reg[64];
- int rc;
- int i;
-
- if(!(config_lookup_string(&cfg, "modbus.device", &modbus_device_address)
- && config_lookup_int(&cfg, "modbus.baud", &modbus_baud_rate)
- && config_lookup_int(&cfg, "modbus.data_bits", &modbus_data_bits)
- && config_lookup_string(&cfg, "modbus.parity", &modbus_parity)
- && config_lookup_int(&cfg, "modbus.stop_bits", &modbus_stop_bits))
-){
- fprintf(stderr, "Check modbus configuration in configuration file.\n");
- return -1;
-}
-
- if(DEBUG){
- printf("%s %d %c %d %d\n",modbus_device_address, modbus_baud_rate, modbus_parity[0], modbus_data_bits, modbus_stop_bits);
- }
-
-ctx = modbus_new_rtu(modbus_device_address, modbus_baud_rate, modbus_parity[0], modbus_data_bits, modbus_stop_bits);
-
-modbus_set_slave(ctx, SLAVE_ID);
-modbus_set_debug(ctx, DEBUG);
-
-if (ctx == NULL) {
- fprintf(stderr, "Unable to create the libmodbus context\n");
- return -1;
-}
-
-
-
-if (modbus_connect(ctx) == -1) {
- fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
- modbus_free(ctx);
- return -1;
-}
-
-rc = modbus_read_input_registers(ctx, START_ADDRESS, NUMBER_REGISTERS, tab_reg);
-
-
-if (rc == -1) {
- fprintf(stderr, "ERROR: %s\n", modbus_strerror(errno));
- return -1;
-}
-
-
-for (i=0; i < rc; i=i+2) {
- printf("reg[%d]=%d\n", i, tab_reg[i]+tab_reg[i+1]);
-}
-
-
-modbus_close(ctx);
-modbus_free(ctx);
-
- return 0;
-}