2 * Copyright © 2008-2010 Stéphane Raimbault <stephane.raimbault@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 modbus_mapping_t
*mb_mapping
;
33 ctx
= modbus_new_tcp("127.0.0.1", 1502);
34 /* modbus_set_debug(ctx, TRUE); */
36 mb_mapping
= modbus_mapping_new(500, 500, 500, 500);
37 if (mb_mapping
== NULL
) {
38 fprintf(stderr
, "Failed to allocate the mapping: %s\n",
39 modbus_strerror(errno
));
44 socket
= modbus_tcp_listen(ctx
, 1);
45 modbus_tcp_accept(ctx
, &socket
);
48 uint8_t query
[MODBUS_TCP_MAX_ADU_LENGTH
];
51 rc
= modbus_receive(ctx
, query
);
53 /* rc is the query size */
54 modbus_reply(ctx
, query
, rc
, mb_mapping
);
55 } else if (rc
== -1) {
56 /* Connection closed by the client or error */
61 printf("Quit the loop: %s\n", modbus_strerror(errno
));
66 modbus_mapping_free(mb_mapping
);