2 * Copyright © Stéphane Raimbault <stephane.raimbault@gmail.com>
4 * SPDX-License-Identifier: BSD-3-Clause
20 modbus_mapping_t
*mb_mapping
;
22 ctx
= modbus_new_tcp("127.0.0.1", 1502);
23 /* modbus_set_debug(ctx, TRUE); */
25 mb_mapping
= modbus_mapping_new(500, 500, 500, 500);
26 if (mb_mapping
== NULL
) {
27 fprintf(stderr
, "Failed to allocate the mapping: %s\n", modbus_strerror(errno
));
32 s
= modbus_tcp_listen(ctx
, 1);
33 modbus_tcp_accept(ctx
, &s
);
36 uint8_t query
[MODBUS_TCP_MAX_ADU_LENGTH
];
39 rc
= modbus_receive(ctx
, query
);
41 /* rc is the query size */
42 modbus_reply(ctx
, query
, rc
, mb_mapping
);
43 } else if (rc
== -1) {
44 /* Connection closed by the client or error */
49 printf("Quit the loop: %s\n", modbus_strerror(errno
));
54 modbus_mapping_free(mb_mapping
);