'\" t
.\"     Title: modbus_set_slave
.\"    Author: [see the "AUTHORS" section]
.\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
.\"      Date: 05/26/2012
.\"    Manual: Libmodbus Manual
.\"    Source: libmodbus 3.0.3
.\"  Language: English
.\"
.TH "MODBUS_SET_SLAVE" "3" "05/26/2012" "libmodbus 3\&.0\&.3" "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_set_slave \- set slave number in the context
.SH "SYNOPSIS"
.sp
\fBint modbus_set_slave(modbus_t *\fR\fB\fIctx\fR\fR\fB, int \fR\fB\fIslave\fR\fR\fB);\fR
.SH "DESCRIPTION"
.sp
The \fImodbus_set_slave()\fR function shall set the slave number in the libmodbus context\&.
.sp
The behavior depends of network and the role of the device:
.PP
\fBRTU\fR
.RS 4
Define the slave ID of the remote device to talk in master mode or set the internal slave ID in slave mode\&. According to the protocol, a Modbus device must only accept message holing its slave number or the special broadcast number\&.
.RE
.PP
\fBTCP\fR
.RS 4
The slave number is only required in TCP if the message must reach a device on a serial network\&. The special value
\fIMODBUS_TCP_SLAVE\fR
(0xFF) can be used in TCP mode to restore the default value\&.
.RE
.sp
The broadcast address is \fIMODBUS_BROADCAST_ADDRESS\fR\&. This special value must be use when you want all Modbus devices of the network receive the request\&.
.SH "RETURN VALUE"
.sp
The \fImodbus_set_slave()\fR function shall return 0 if successful\&. Otherwise it shall return \-1 and set errno to one of the values defined below\&.
.SH "ERRORS"
.PP
\fBEINVAL\fR
.RS 4
The slave number is invalid\&.
.RE
.SH "AUTHORS"
.sp
The libmodbus documentation was written by St\('ephane Raimbault <\m[blue]\fBstephane\&.raimbault@gmail\&.com\fR\m[]\&\s-2\u[1]\d\s+2>
.SH "NOTES"
.IP " 1." 4
stephane.raimbault@gmail.com
.RS 4
\%mailto:stephane.raimbault@gmail.com
.RE
