You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.6 KiB

  1. From 1c5d969f46ccd5333f602dfbe2b0a1295650b9b0 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?St=C3=A9phane=20Raimbault?= <stephane.raimbault@gmail.com>
  3. Date: Wed, 25 Oct 2017 20:35:47 +0200
  4. Subject: [PATCH 1/2] Only set SER_RS485_ENABLED bit of existing RS485 settings
  5. Thanks to @JCWren
  6. ---
  7. src/modbus-rtu.c | 10 +++++++++-
  8. 1 file changed, 9 insertions(+), 1 deletion(-)
  9. diff --git a/src/modbus-rtu.c b/src/modbus-rtu.c
  10. index 8d9f386..f2911d6 100644
  11. --- a/src/modbus-rtu.c
  12. +++ b/src/modbus-rtu.c
  13. @@ -909,9 +909,13 @@ int modbus_rtu_set_serial_mode(modbus_t *ctx, int mode)
  14. #if HAVE_DECL_TIOCSRS485
  15. modbus_rtu_t *ctx_rtu = ctx->backend_data;
  16. struct serial_rs485 rs485conf;
  17. - memset(&rs485conf, 0x0, sizeof(struct serial_rs485));
  18. if (mode == MODBUS_RTU_RS485) {
  19. + // Get
  20. + if (ioctl(ctx->s, TIOCGRS485, &rs485conf) < 0) {
  21. + return -1;
  22. + }
  23. + // Set
  24. rs485conf.flags = SER_RS485_ENABLED;
  25. if (ioctl(ctx->s, TIOCSRS485, &rs485conf) < 0) {
  26. return -1;
  27. @@ -923,6 +927,10 @@ int modbus_rtu_set_serial_mode(modbus_t *ctx, int mode)
  28. /* Turn off RS485 mode only if required */
  29. if (ctx_rtu->serial_mode == MODBUS_RTU_RS485) {
  30. /* The ioctl call is avoided because it can fail on some RS232 ports */
  31. + if (ioctl(ctx->s, TIOCGRS485, &rs485conf) < 0) {
  32. + return -1;
  33. + }
  34. + rs485conf.flags &= ~SER_RS485_ENABLED;
  35. if (ioctl(ctx->s, TIOCSRS485, &rs485conf) < 0) {
  36. return -1;
  37. }
  38. --
  39. 2.21.0