modbus: serial: Allow custom stop-bit settings in server mode#87484
Conversation
subsys/modbus/Kconfig
Outdated
| help | ||
| Enable function code 08 Diagnostic support | ||
|
|
||
| config MODBUS_STOP_BITS_IN_SERVER_MODE |
There was a problem hiding this comment.
A Modbus server should be able to operate with the same settings as a
client.
Why should it?
Stop-bits -is the only setting not available in server mode.
Because the RTU format is always 11 bits. There is either parity + stop or stop + stop. The client only supports this to communicate with non-compliant server devices, introduced in #40558.
There was a problem hiding this comment.
Hello @jfischer-no
Thank you for feedback!
Yes, I'm fully aware that 8N1 is not compliant with the specification but there are devices on the market that use exactly this format.
Right now the Modbus subsystem can talk to a non-compliant server device as a client but can't act as a non-compliant server. So we can't create a server device that may be added to an existing non-compliant bus.
This is exactly my case: an existing bus that works at 9600 8N1 and I need to add another server to it without changing the communication format.
May be a better description of the config option is needed to highlight that this options is not compliant with the specification and should be used with caution.
There was a problem hiding this comment.
understood, I am fine with
config MODBUS_NONCOMPLIANT_RTU_MODE
bool "Non-compliant RTU server mode"
depends on MODBUS_SERVER && MODBUS_SERIAL
help
Allow non-compliant stop and parity bit settings.
subsys/modbus/Kconfig
Outdated
| depends on MODBUS_SERVER | ||
| depends on MODBUS_SERIAL |
There was a problem hiding this comment.
depends on MODBUS_SERVER && MODBUS_SERIAL
subsys/modbus/Kconfig
Outdated
| help | ||
| Enable function code 08 Diagnostic support | ||
|
|
||
| config MODBUS_STOP_BITS_IN_SERVER_MODE |
There was a problem hiding this comment.
understood, I am fine with
config MODBUS_NONCOMPLIANT_RTU_MODE
bool "Non-compliant RTU server mode"
depends on MODBUS_SERVER && MODBUS_SERIAL
help
Allow non-compliant stop and parity bit settings.
2ede2c7 to
5468698
Compare
|
Hello @jfischer-no What about renaming I.e.:
/**
* @brief Modbus serial line parameter
*/
struct modbus_serial_param {
/** Baudrate of the serial line */
uint32_t baud;
/** parity UART's parity setting:
* UART_CFG_PARITY_NONE,
* UART_CFG_PARITY_EVEN,
* UART_CFG_PARITY_ODD
*/
enum uart_config_parity parity;
- /** stop_bits_client UART's stop bits setting if in client mode:
+ /** stop_bits UART's stop bits setting:
* UART_CFG_STOP_BITS_0_5,
* UART_CFG_STOP_BITS_1,
* UART_CFG_STOP_BITS_1_5,
* UART_CFG_STOP_BITS_2,
*/
- enum uart_config_stop_bits stop_bits_client;
+ enum uart_config_stop_bits stop_bits;
};
- if (ctx->client || IS_ENABLED(MODBUS_NONCOMPLIANT_SERIAL_SERVER_MODE)) {
+ if (IS_ENABLED(CONFIG_MODBUS_NONCOMPLIANT_SERIAL_MODE)) {
/* Allow custom stop bit settings */
- switch (param->serial.stop_bits_client) {
+ switch (param->serial.stop_bits) {
case UART_CFG_STOP_BITS_0_5:
case UART_CFG_STOP_BITS_1:
case UART_CFG_STOP_BITS_1_5:
case UART_CFG_STOP_BITS_2:
uart_cfg.stop_bits = param->serial.stop_bits;
break;
default:
return -EINVAL;
}
}This will require some migration effort for existing applications but will explicitly enable non-compliant mode for both clients and servers. |
89a92d8 to
99e29e7
Compare
Yes, that is event better. |
99e29e7 to
7479f2c
Compare
7479f2c to
086dde0
Compare
The mode is activated by the CONFIG_MODBUS_NONCOMPLIANT_SERIAL_MODE option and allows any stop-bit setting for the serial port. Signed-off-by: Maksim Salau <msalau@iotecha.com>
086dde0 to
eb289d3
Compare
|



A Modbus server should be able to operate with the same settings as a client. Stop-bits -is the only setting not available in server mode.
The change makes it possible to override default stop-bits settings in backwards compatible way. The feature is disabled by default.