stephane / libmodbus

A Modbus library for Linux, Mac OS, FreeBSD and Windows
http://libmodbus.org
GNU Lesser General Public License v2.1
3.5k stars 1.77k forks source link

Added Hardware Up and Down RTS Setting for RS485. #594

Open embeddedmz opened 3 years ago

embeddedmz commented 3 years ago

Hello,

Actually, in libmodbus, there's only RTS up or down setting via software and its accuracy depends on RTS delay value.

In this pull request, I added the possibility to use hardware RTS up or down setting (using the serial driver).

I made my tests with ModRSim2 (Modbus slave simulator running on Windows 10) and the Trizeps 7 board running Ubuntu 18.04 (i.MX6 CPU, the serial driver/UART is related to that CPU).

If this is good for you, I will add the proper documentation before you accept my changes.

Best regards.

cla-bot[bot] commented 3 years ago

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Mohamed Amine Mzoughi. This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails
cla-bot[bot] commented 2 years ago

We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, please fill https://forms.gle/5635zjphDo5JEJQSA to get added. Your document will be manually checked by the maintainer. Be patient...

embeddedmz commented 2 years ago

@cla-bot check

cla-bot[bot] commented 2 years ago

We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, please fill https://forms.gle/5635zjphDo5JEJQSA to get added. Your document will be manually checked by the maintainer. Be patient...

cla-bot[bot] commented 2 years ago

The cla-bot has been summoned, and re-checked this pull request!

stephane commented 2 years ago

This part was already complex but with the splitting between software and hardware, it's even more complex but I think you need it so it makes sense to add this code.

As you proposed, proper documentation would be nice.

embeddedmz commented 2 years ago

@stephane When you merge my other PR, let me know so I can update my master branch so you can merge this if everything is good for you.

On the other hand, if anyone needs this feature on Windows (I did it on Windows CE 7 in quick and dirty mode https://github.com/embeddedmz/libmodbus_trizeps_vii_arm_wince), in static int _modbus_rtu_connect(modbus_t *ctx), just use this statement somewhere:

/* Specifies that the RTS line will be high if bytes are available for transmission. After all buffered bytes have been sent, the RTS line will be low. */
dcb.fRtsControl = RTS_CONTROL_TOGGLE;

Maybe, I will work on that issue one day (making modbus_rtu_set_rts function also works on Windows platform).

embeddedmz commented 2 years ago

@stephane the branch is now up to date and ready to be merged.