28 #define G_MSEC_PER_SEC 1000 33 gettimeofday (&tv, NULL);
35 return (uint32_t) tv.tv_sec * 1000 + tv.tv_usec / 1000;
44 int main(
int argc,
char *argv[])
61 if (strcmp(argv[1],
"tcp") == 0) {
64 }
else if (strcmp(argv[1],
"rtu") == 0) {
68 printf(
"Usage:\n %s [tcp|rtu] - Modbus client to measure data bandwith\n\n", argv[0]);
77 if (use_backend ==
TCP) {
84 fprintf(stderr,
"Connexion failed: %s\n",
98 printf(
"READ BITS\n\n");
102 for (i=0; i<n_loop; i++) {
110 elapsed = end - start;
113 printf(
"Transfert rate in points/seconds:\n");
114 printf(
"* %d points/s\n", rate);
117 bytes = n_loop * (nb_points / 8) + ((nb_points % 8) ? 1 : 0);
120 printf(
"* %d x %d values\n", n_loop, nb_points);
121 printf(
"* %.3f ms for %d bytes\n", elapsed, bytes);
122 printf(
"* %d KiB/s\n", rate);
126 bytes = 12 + 9 + (nb_points / 8) + ((nb_points % 8) ? 1 : 0);
127 printf(
"Values and TCP Modbus overhead:\n");
128 printf(
"* %d x %d bytes\n", n_loop, bytes);
129 bytes = n_loop * bytes;
131 printf(
"* %.3f ms for %d bytes\n", elapsed, bytes);
132 printf(
"* %d KiB/s\n", rate);
135 printf(
"READ REGISTERS\n\n");
139 for (i=0; i<n_loop; i++) {
147 elapsed = end - start;
150 printf(
"Transfert rate in points/seconds:\n");
151 printf(
"* %d registers/s\n", rate);
154 bytes = n_loop * nb_points *
sizeof(uint16_t);
157 printf(
"* %d x %d values\n", n_loop, nb_points);
158 printf(
"* %.3f ms for %d bytes\n", elapsed, bytes);
159 printf(
"* %d KiB/s\n", rate);
163 bytes = 12 + 9 + (nb_points *
sizeof(uint16_t));
164 printf(
"Values and TCP Modbus overhead:\n");
165 printf(
"* %d x %d bytes\n", n_loop, bytes);
166 bytes = n_loop * bytes;
168 printf(
"* %.3f ms for %d bytes\n", elapsed, bytes);
169 printf(
"* %d KiB/s\n", rate);
172 printf(
"READ AND WRITE REGISTERS\n\n");
176 for (i=0; i<n_loop; i++) {
178 0, nb_points, tab_reg,
179 0, nb_points, tab_reg);
186 elapsed = end - start;
189 printf(
"Transfert rate in points/seconds:\n");
190 printf(
"* %d registers/s\n", rate);
193 bytes = n_loop * nb_points *
sizeof(uint16_t);
196 printf(
"* %d x %d values\n", n_loop, nb_points);
197 printf(
"* %.3f ms for %d bytes\n", elapsed, bytes);
198 printf(
"* %d KiB/s\n", rate);
202 bytes = 12 + 9 + (nb_points *
sizeof(uint16_t));
203 printf(
"Values and TCP Modbus overhead:\n");
204 printf(
"* %d x %d bytes\n", n_loop, bytes);
205 bytes = n_loop * bytes;
207 printf(
"* %.3f ms for %d bytes\n", elapsed, bytes);
208 printf(
"* %d KiB/s\n", rate);
uint32_t gettime_ms(void)
int modbus_read_bits(modbus_t *ctx, int addr, int nb, uint8_t *dest)
int main(int argc, char *argv[])
void modbus_free(modbus_t *ctx)
#define MODBUS_MAX_READ_REGISTERS
void modbus_close(modbus_t *ctx)
int modbus_set_slave(modbus_t *ctx, int slave)
const char * modbus_strerror(int errnum)
#define MODBUS_MAX_RW_WRITE_REGISTERS
modbus_t * modbus_new_rtu(const char *device, int baud, char parity, int data_bit, int stop_bit)
int modbus_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest)
int modbus_connect(modbus_t *ctx)
#define MODBUS_MAX_READ_BITS
int modbus_write_and_read_registers(modbus_t *ctx, int write_addr, int write_nb, const uint16_t *src, int read_addr, int read_nb, uint16_t *dest)
modbus_t * modbus_new_tcp(const char *ip_address, int port)