1MODBUS_SEND_RAW_REQU(3)        Libmodbus Manual        MODBUS_SEND_RAW_REQU(3)
2
3
4

NAME

6       modbus_send_raw_request - send a raw request
7

SYNOPSIS

9       int modbus_send_raw_request(modbus_t *ctx, uint8_t *raw_req, int
10       'raw_req_length);
11

DESCRIPTION

13       The modbus_send_raw_request() function shall send a request via the
14       socket of the context ctx. This function must be used for debugging
15       purposes because you have to take care to make a valid request by hand.
16       The function only adds to the message, the header or CRC of the
17       selected backend, so raw_req must start and contain at least a
18       slave/unit identifier and a function code. This function can be used to
19       send request not handled by the library.
20

RETURN VALUE

22       The modbus_send_raw_request() function shall return the full message
23       length, counting the extra data relating to the backend, if successful.
24       Otherwise it shall return -1 and set errno.
25

EXAMPLE

27           modbus_t *ctx;
28           /* Read 5 holding registers from address 1 */
29           uint8_t raw_req[] = { 0xFF, 0x03, 0x00, 0x01, 0x0, 0x05 };
30           int req_length;
31           uint8_t rsp[MODBUS_TCP_MAX_ADU_LENGTH];
32
33           ctx = modbus_new_tcp("127.0.0.1", 1502);
34           if (modbus_connect(ctx) == -1) {
35               fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
36               modbus_free(ctx);
37               return -1;
38           }
39
40           req_length = modbus_send_raw_request(ctx, raw_req, 6 * sizeof(uint8_t));
41           modbus_receive_confirmation(ctx, rsp);
42
43           modbus_close(ctx);
44           modbus_free(ctx);
45

SEE ALSO

47       modbus_receive_confirmation(3)
48

AUTHORS

50       The libmodbus documentation was written by Stéphane Raimbault
51       <stephane.raimbault@gmail.com[1]>
52

NOTES

54        1. stephane.raimbault@gmail.com
55           mailto:stephane.raimbault@gmail.com
56
57
58
59libmodbus 3.0.6                   04/02/2014           MODBUS_SEND_RAW_REQU(3)
Impressum