modbus: stop bits can now be set individually in client mode

Added the stop_bits_client parameter to the modbus_serial_param struct.
Being able to configure the number of stop bits for the client
independently from the parity setting, allows to support connecting to
modbus server that do not follow the MODBUS over Serial Line Specification
and Implementation Guide.

Signed-off-by: Constantin Krischke <constantin.krischke@lemonbeat.com>
Signed-off-by: Jan Geldmacher <jan.geldmacher@lemonbeat.com>
This commit is contained in:
Constantin Krischke 2021-11-16 16:14:28 +01:00 committed by Anas Nashif
commit 8ee675946c
5 changed files with 31 additions and 2 deletions

View file

@ -208,6 +208,7 @@ static struct modbus_iface_param client_param = {
.serial = {
.baud = MB_TEST_BAUDRATE_LOW,
.parity = UART_CFG_PARITY_ODD,
.stop_bits_client = UART_CFG_STOP_BITS_1,
},
};
@ -221,6 +222,7 @@ void test_client_setup_low_none(void)
client_param.mode = MODBUS_MODE_RTU;
client_param.serial.baud = MB_TEST_BAUDRATE_LOW;
client_param.serial.parity = UART_CFG_PARITY_NONE;
client_param.serial.stop_bits_client = UART_CFG_STOP_BITS_2;
err = modbus_init_client(client_iface, client_param);
zassert_equal(err, 0, "Failed to configure RTU client");
@ -236,6 +238,7 @@ void test_client_setup_low_odd(void)
client_param.mode = MODBUS_MODE_RTU;
client_param.serial.baud = MB_TEST_BAUDRATE_LOW;
client_param.serial.parity = UART_CFG_PARITY_ODD;
client_param.serial.stop_bits_client = UART_CFG_STOP_BITS_1;
err = modbus_init_client(client_iface, client_param);
zassert_equal(err, 0, "Failed to configure RTU client");
@ -251,6 +254,7 @@ void test_client_setup_high_even(void)
client_param.mode = MODBUS_MODE_RTU;
client_param.serial.baud = MB_TEST_BAUDRATE_HIGH;
client_param.serial.parity = UART_CFG_PARITY_EVEN;
client_param.serial.stop_bits_client = UART_CFG_STOP_BITS_1;
err = modbus_init_client(client_iface, client_param);
zassert_equal(err, 0, "Failed to configure RTU client");
@ -266,6 +270,7 @@ void test_client_setup_ascii(void)
client_param.mode = MODBUS_MODE_ASCII;
client_param.serial.baud = MB_TEST_BAUDRATE_HIGH;
client_param.serial.parity = UART_CFG_PARITY_EVEN;
client_param.serial.stop_bits_client = UART_CFG_STOP_BITS_1;
err = modbus_init_client(client_iface, client_param);