'\" t .\" Title: modbus_send_raw_request .\" Author: [see the "AUTHORS" section] .\" Generator: DocBook XSL Stylesheets vsnapshot .\" Date: 10/15/2022 .\" Manual: libmodbus Manual .\" Source: libmodbus v3.1.6 .\" Language: English .\" .TH "MODBUS_SEND_RAW_REQU" "3" "10/15/2022" "libmodbus v3\&.1\&.6" "libmodbus Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" modbus_send_raw_request \- send a raw request .SH "SYNOPSIS" .sp \fBint modbus_send_raw_request(modbus_t *\fR\fB\fIctx\fR\fR\fB, const uint8_t *\fR\fB\fIraw_req\fR\fR\fB, int \fR\fB\fIraw_req_length\fR\fR\fB);\fR .SH "DESCRIPTION" .sp The \fBmodbus_send_raw_request()\fR function shall send a request via the socket of the context \fIctx\fR\&. This function must be used for debugging purposes because you have to take care to make a valid request by hand\&. The function only adds to the message, the header or CRC of the selected backend, so \fIraw_req\fR must start and contain at least a slave/unit identifier and a function code\&. This function can be used to send request not handled by the library\&. .sp The public header of libmodbus provides a list of supported Modbus functions codes, prefixed by MODBUS_FC_ (eg\&. MODBUS_FC_READ_HOLDING_REGISTERS), to help build of raw requests\&. .SH "RETURN VALUE" .sp The function shall return the full message length, counting the extra data relating to the backend, if successful\&. Otherwise it shall return \-1 and set errno\&. .SH "EXAMPLE" .sp .if n \{\ .RS 4 .\} .nf modbus_t *ctx; /* Read 5 holding registers from address 1 */ uint8_t raw_req[] = { 0xFF, MODBUS_FC_READ_HOLDING_REGISTERS, 0x00, 0x01, 0x0, 0x05 }; int req_length; uint8_t rsp[MODBUS_TCP_MAX_ADU_LENGTH]; ctx = modbus_new_tcp("127\&.0\&.0\&.1", 1502); if (modbus_connect(ctx) == \-1) { fprintf(stderr, "Connection failed: %s\en", modbus_strerror(errno)); modbus_free(ctx); return \-1; } req_length = modbus_send_raw_request(ctx, raw_req, 6 * sizeof(uint8_t)); modbus_receive_confirmation(ctx, rsp); modbus_close(ctx); modbus_free(ctx); .fi .if n \{\ .RE .\} .SH "SEE ALSO" .sp \fBmodbus_receive_confirmation\fR(3) .SH "AUTHORS" .sp The libmodbus documentation was written by Stéphane Raimbault