Skip to content

Commit e2c8ad2

Browse files
panickingqipengzha
authored andcommitted
modbus: cancel the server_work in modbus disable
Allow to periodically initializes/disables the modbus interface. Switch from modbus line discipline to serial and switch back to modbus. This can be required when the serial is shared by two sensors Signed-off-by: Michael Trimarchi <[email protected]>
1 parent 713f3e3 commit e2c8ad2

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

subsys/modbus/modbus_core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ int modbus_init_client(const int iface, struct modbus_iface_param param)
338338
int modbus_disable(const uint8_t iface)
339339
{
340340
struct modbus_context *ctx;
341+
struct k_work_sync work_sync;
341342

342343
ctx = modbus_get_context(iface);
343344
if (ctx == NULL) {
@@ -358,6 +359,7 @@ int modbus_disable(const uint8_t iface)
358359
LOG_ERR("Unknown MODBUS mode");
359360
}
360361

362+
k_work_cancel_sync(&ctx->server_work, &work_sync);
361363
ctx->rxwait_to = 0;
362364
ctx->unit_id = 0;
363365
ctx->mode = MODBUS_MODE_RTU;

0 commit comments

Comments
 (0)