Skip to content

Make RS485Class a constructor arg to ModbusRTUClientClass and ModbusRTUServerClass #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

sandeepmistry
Copy link
Contributor

This is an alternative to pull request #11

Instead of having a parameter to begin(...) a new ModbusRTUClientClass or ModbusRTUServerClass instance can be declared with an alternative RS485Class instance.

@nud
Copy link

nud commented Oct 3, 2019

What about going even further and calling it "transport" rather than "rs485"? I myself would very much like to have a RS232 transport as well.

@sandeepmistry
Copy link
Contributor Author

@nud that's a good suggestion! I didn't know RTU also supported RS232.

Have you tested this pull request?

Would you be update for adding RS232 support? Let me know, we can merge this one and you can submit another pull request for it.

@willwilder
Copy link

Have you had success getting this to work? I have a use case for specifying the hardware serial port I want to use, trying to get the Sparkfun AST-CAN485 running as a ModbusRTU slave. The RS-485 chip is hard wired to Serial1.

@ADCTechnologyGroup01
Copy link

I'd also like to see the interface abstracted from the protocol. For use with RS232 and also the native USB Serial Port (which is typically only used for debugging with "Serial Monitor").

@cheetor5923
Copy link

I like this idea... Realistically the best option would be to have each layer of the OSI model as a separate modular bit of code.

@SWoto
Copy link

SWoto commented Jan 18, 2021

@sandeepmistry, I've tested your code with the KitchenSink's example, ModbusRTUServerKitchenSink and ModbusRTUClientKitchenSink.

Steps:

  1. Download your commit - ea16c79920ec62cc96d1c0ca8be973d8cb853559
  2. Change Serial port
[...] some code before here 

RS485Class _RS485(Serial2, txPin, dePin, rePin);

void setup() {
  ModbusRTUClient = ModbusRTUClientClass(_RS485);

[...] some code after here 
  1. Run Server in one board and client in another.

Results:

16:17:10.627 -> Writing Coil values ... success
16:17:10.667 -> Reading Coil values ... success
16:17:10.667 -> 0 0 0 0 0 0 0 0 0 0 
16:17:10.667 -> Reading Discrete Input values ... success
16:17:10.708 -> 0 0 0 0 0 0 0 0 0 0 
16:17:10.708 -> Writing Holding Registers values ... failed! Connection timed out
16:17:11.715 -> Reading Input Register values ... failed! Connection timed out
16:17:12.717 -> Reading input register values ... failed! Connection timed out
16:17:18.754 -> 
16:17:18.754 -> Writing Coil values ... success
16:17:18.754 -> Reading Coil values ... success
16:17:18.787 -> 1 1 1 1 1 1 1 1 1 1 
16:17:18.787 -> Reading Discrete Input values ... success
16:17:18.787 -> 1 1 1 1 1 1 1 1 1 1 
16:17:18.787 -> Writing Holding Registers values ... failed! Connection timed out
16:17:19.840 -> Reading Input Register values ... failed! Connection timed out
16:17:20.840 -> Reading input register values ... failed! Connection timed out

If I turn the Server off, I get all the results as Connection timed out, so they are communicating.

I've also changed Serial2 to Serial3 and I also receive Connection timed out every time, so the modification worked just fine.

Sugestion

Would be really good to have this option in the ModbusRTUServer too.

@SWoto
Copy link

SWoto commented Jan 18, 2021

@sandeepmistry, please let me know if there are any other tests that you would like me to run.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@SWoto
Copy link

SWoto commented Apr 19, 2021

This branch is working like a charm.

RS485 = RS485Class(Serial2, Serial2, txPin, dePin, rePin);
ModbusRTUClient = ModbusRTUClientClass(_RS485);

Solves the problem that the RS485 class is hardcoded in the ArduinoModbus.

@sandeepmistry

facchinm added a commit that referenced this pull request Apr 28, 2021
Can be changed by either the constructor or begin()

Ports and replaces #14
@facchinm facchinm closed this Apr 28, 2021
@per1234 per1234 added conclusion: duplicate Has already been submitted type: enhancement Proposed improvement topic: code Related to content of the project itself labels Oct 6, 2023
@per1234 per1234 self-assigned this Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: duplicate Has already been submitted topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants