1 modbus_send_raw_request(3)
2 ==========================
7 modbus_send_raw_request - send a raw request
12 *int modbus_send_raw_request(modbus_t *'ctx', uint8_t *'raw_req', int 'raw_req_length');*
17 The *modbus_send_raw_request()* function shall send a request via the socket of
18 the context _ctx_. This function must be used for debugging purposes because you
19 have to take care to make a valid request by hand. The function only adds to the
20 message, the header or CRC of the selected backend, so _raw_req_ must start and
21 contain at least a slave/unit identifier and a function code. This function can
22 be used to send request not handled by the library.
24 The public header of libmodbus provides a list of supported Modbus functions
25 codes, prefixed by `MODBUS_FC_` (eg. `MODBUS_FC_READ_HOLDING_REGISTERS`), to help
26 build of raw requests.
31 The function shall return the full message length, counting the extra data
32 relating to the backend, if successful. Otherwise it shall return -1 and set
41 /* Read 5 holding registers from address 1 */
42 uint8_t raw_req[] = { 0xFF, MODBUS_FC_READ_HOLDING_REGISTERS, 0x00, 0x01, 0x0, 0x05 };
44 uint8_t rsp[MODBUS_TCP_MAX_ADU_LENGTH];
46 ctx = modbus_new_tcp("127.0.0.1", 1502);
47 if (modbus_connect(ctx) == -1) {
48 fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
53 req_length = modbus_send_raw_request(ctx, raw_req, 6 * sizeof(uint8_t));
54 modbus_receive_confirmation(ctx, rsp);
62 linkmb:modbus_receive_confirmation[3]
67 The libmodbus documentation was written by Stéphane Raimbault
68 <stephane.raimbault@gmail.com>