/* * Copyright © 2008-2010 Stéphane Raimbault * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include /* Tests based on PI-MBUS-300 documentation */ #define NB_LOOPS 100000 #define G_MSEC_PER_SEC 1000 uint32_t gettime_ms(void) { struct timeval tv; gettimeofday (&tv, NULL); return (uint32_t) tv.tv_sec * 1000 + tv.tv_usec / 1000; } int main(void) { uint8_t *tab_bit; uint16_t *tab_reg; modbus_t *ctx; int i; int nb_points; double elapsed; uint32_t start; uint32_t end; uint32_t bytes; uint32_t rate; int rc; /* TCP */ ctx = modbus_new_tcp("127.0.0.1", 1502); if (modbus_connect(ctx) == -1) { fprintf(stderr, "Connexion failed: %s\n", modbus_strerror(errno)); modbus_free(ctx); return -1; } /* Allocate and initialize the memory to store the status */ tab_bit = (uint8_t *) malloc(MODBUS_MAX_BITS * sizeof(uint8_t)); memset(tab_bit, 0, MODBUS_MAX_BITS * sizeof(uint8_t)); /* Allocate and initialize the memory to store the registers */ tab_reg = (uint16_t *) malloc(MODBUS_MAX_REGISTERS * sizeof(uint16_t)); memset(tab_reg, 0, MODBUS_MAX_REGISTERS * sizeof(uint16_t)); printf("READ BITS\n\n"); nb_points = MODBUS_MAX_BITS; start = gettime_ms(); for (i=0; i