<commit_before>modbus_set_slave(3)
===================


NAME
----
modbus_set_slave - set slave number in the context


SYNOPSIS
--------
*int modbus_set_slave(modbus_t *'ctx', int 'slave');*


DESCRIPTION
-----------
The *modbus_set_slave()* function shall set the slave number in the libmodbus
context.

The behavior depends of network and the role of the device:

*RTU*::
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.

*TCP*::
The slave number is only required in TCP if the message must reach a device
on a serial network. The special value `MODBUS_TCP_SLAVE` (0xFF) can be used in TCP mode to restore
the default value.

The broadcast address is `MODBUS_BROADCAST_ADDRESS`. This special value must be
use when you want all Modbus devices of the network receive the request.


RETURN VALUE
------------
The function shall return 0 if successful. Otherwise it shall return -1 and set
errno to one of the values defined below.


ERRORS
------
*EINVAL*::
The slave number is invalid.


EXAMPLE
-------
[source,c]
-------------------
modbus_t *ctx;

ctx = modbus_new_rtu("/dev/ttyUSB0", 115200, 'N', 8, 1);
if (ctx == NULL) {
    fprintf(stderr, "Unable to create the libmodbus context\n");
    return -1;
}
<commit_msg>Add information about not compliant devices (closes #219)<commit_after>modbus_set_slave(3)
===================


NAME
----
modbus_set_slave - set slave number in the context


SYNOPSIS
--------
*int modbus_set_slave(modbus_t *'ctx', int 'slave');*


DESCRIPTION
-----------
The *modbus_set_slave()* function shall set the slave number in the libmodbus
context.

The behavior depends of network and the role of the device:

*RTU*::
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 holding its slave number or the special broadcast number.

*TCP*::
The slave number is only required in TCP if the message must reach a device on a
serial network. Some not compliant devices or software (such as modpoll) uses
the slave ID as unit identifier, that's incorrect (cf page 23 of Modbus
Messaging Implementation Guide v1.0b) but without the slave value, the faulty
remote device or software drops the requests! The special value
`MODBUS_TCP_SLAVE` (0xFF) can be used in TCP mode to restore the default value.

The broadcast address is `MODBUS_BROADCAST_ADDRESS`. This special value must be
use when you want all Modbus devices of the network receive the request.


RETURN VALUE
------------
The function shall return 0 if successful. Otherwise it shall return -1 and set
errno to one of the values defined below.


ERRORS
------
*EINVAL*::
The slave number is invalid.


EXAMPLE
-------
[source,c]
-------------------
modbus_t *ctx;

ctx = modbus_new_rtu("/dev/ttyUSB0", 115200, 'N', 8, 1);
if (ctx == NULL) {
    fprintf(stderr, "Unable to create the libmodbus context\n");
    return -1;
}

{'fraction_non_alphanumeric': 0.11421238370227783, 'fraction_numerical': 0.01122874558870709, 'mean_word_length': 3.585294117647059, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5361463', 'n_tokens_mistral': 922, 'n_tokens_neox': 878, 'n_words': 436}