/* * 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 SERVER_ID 17 #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_rp_status; uint16_t *tab_rp_registers; modbus_param_t mb_param; int i; int nb_points; double elapsed; uint32_t start; uint32_t end; uint32_t bytes; uint32_t rate; int rc; /* TCP */ modbus_init_tcp(&mb_param, "127.0.0.1", 1502); rc = modbus_connect(&mb_param); if (rc == -1) { fprintf(stderr, "Connexion failed: %s\n", modbus_strerror(errno)); return -1; } /* Allocate and initialize the memory to store the status */ tab_rp_status = (uint8_t *) malloc(MAX_STATUS * sizeof(uint8_t)); memset(tab_rp_status, 0, MAX_STATUS * sizeof(uint8_t)); /* Allocate and initialize the memory to store the registers */ tab_rp_registers = (uint16_t *) malloc(MAX_REGISTERS * sizeof(uint16_t)); memset(tab_rp_registers, 0, MAX_REGISTERS * sizeof(uint16_t)); printf("READ COIL STATUS\n\n"); nb_points = MAX_STATUS; start = gettime_ms(); for (i=0; i