1MODBUS_SEND_RAW_REQU(3) libmodbus Manual MODBUS_SEND_RAW_REQU(3)
2
3
4
6 modbus_send_raw_request - send a raw request
7
9 int modbus_send_raw_request(modbus_t *ctx, const uint8_t *raw_req, int
10 raw_req_length);
11
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
21 The public header of libmodbus provides a list of supported Modbus
22 functions codes, prefixed by MODBUS_FC_ (eg.
23 MODBUS_FC_READ_HOLDING_REGISTERS), to help build of raw requests.
24
26 The function shall return the full message length, counting the extra
27 data relating to the backend, if successful. Otherwise it shall return
28 -1 and set errno.
29
31 modbus_t *ctx;
32 /* Read 5 holding registers from address 1 */
33 uint8_t raw_req[] = { 0xFF, MODBUS_FC_READ_HOLDING_REGISTERS, 0x00, 0x01, 0x0, 0x05 };
34 int req_length;
35 uint8_t rsp[MODBUS_TCP_MAX_ADU_LENGTH];
36
37 ctx = modbus_new_tcp("127.0.0.1", 1502);
38 if (modbus_connect(ctx) == -1) {
39 fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
40 modbus_free(ctx);
41 return -1;
42 }
43
44 req_length = modbus_send_raw_request(ctx, raw_req, 6 * sizeof(uint8_t));
45 modbus_receive_confirmation(ctx, rsp);
46
47 modbus_close(ctx);
48 modbus_free(ctx);
49
51 modbus_receive_confirmation(3)
52
54 The libmodbus documentation was written by Stéphane Raimbault
55 <stephane.raimbault@gmail.com>
56
57
58
59libmodbus v3.1.6 01/19/2023 MODBUS_SEND_RAW_REQU(3)