Skip to content

Commit

Permalink
Only set SER_RS485_ENABLED bit of existing RS485 settings
Browse files Browse the repository at this point in the history
Thanks to @jcwren
  • Loading branch information
stephane committed Oct 25, 2017
1 parent 44b0083 commit 1c5d969
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/modbus-rtu.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,9 +909,13 @@ int modbus_rtu_set_serial_mode(modbus_t *ctx, int mode)
#if HAVE_DECL_TIOCSRS485
modbus_rtu_t *ctx_rtu = ctx->backend_data;
struct serial_rs485 rs485conf;
memset(&rs485conf, 0x0, sizeof(struct serial_rs485));

if (mode == MODBUS_RTU_RS485) {
// Get
if (ioctl(ctx->s, TIOCGRS485, &rs485conf) < 0) {
return -1;
}
// Set
rs485conf.flags = SER_RS485_ENABLED;

This comment has been minimized.

Copy link
@jcwren

jcwren Oct 25, 2017

This should be |=

This comment has been minimized.

Copy link
@stephane

stephane Oct 26, 2017

Author Owner

Of course 🤦‍♂️

if (ioctl(ctx->s, TIOCSRS485, &rs485conf) < 0) {
return -1;
Expand All @@ -923,6 +927,10 @@ int modbus_rtu_set_serial_mode(modbus_t *ctx, int mode)
/* Turn off RS485 mode only if required */
if (ctx_rtu->serial_mode == MODBUS_RTU_RS485) {
/* The ioctl call is avoided because it can fail on some RS232 ports */
if (ioctl(ctx->s, TIOCGRS485, &rs485conf) < 0) {
return -1;
}
rs485conf.flags &= ~SER_RS485_ENABLED;
if (ioctl(ctx->s, TIOCSRS485, &rs485conf) < 0) {
return -1;
}
Expand Down

0 comments on commit 1c5d969

Please sign in to comment.