Skip to content

De-hardcoded RS485Class object to be used by modbus. #11

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

Closed
wants to merge 1 commit into from

Conversation

psmay
Copy link

@psmay psmay commented Aug 7, 2019

This proposed change makes it possible to use an RS485Class object other than the default RS485 with the contained libmodbus. This is useful with boards with multiple serial ports or when the user wants to specify different DE/RE pins.

@sandeepmistry
Copy link
Contributor

Hi @psmay,

Thanks for opening this pull request!

I'm curious about your use case, do you need multiple RS485 interfaces at the same time? I'm wondering if another option is to add something like RS485.setSerial(...).

@psmay
Copy link
Author

psmay commented Aug 11, 2019

This change is for supporting these use cases:

  1. Modbus-RTU on a single serial port that does not match the default RS485 configuration, without manually modifying the ArduinoRS485 and ArduinoModbus sketches.
    • For example, I might have a client sketch which uses RS485Class ourRS485(Serial1, PB6, PB9, PB8); and a different server sketch that uses RS485Class ourRS485(Serial2, PA2, PA3, PA4);. Before this change, I would have needed to maintain a custom ArduinoRS485 and ArduinoModbus libraries for each.
  2. Modbus-RTU on multiple serial ports in the same sketch.
    • I haven't tested that this PR addresses this entire use case, but it does include groundwork that would be necessary for this support.

@sandeepmistry
Copy link
Contributor

Hi @psmay,

Thank you for the explanation. What do you think about making the RS485Class a constructor argument instead of a parameter to begin? I've prepared pull request #14 for this change.

@pruwait
Copy link

pruwait commented Nov 30, 2019

How can I Use Serial1 or Serial2 with library?

@SWoto
Copy link

SWoto commented Jan 18, 2021

@pruwait , probably the only way to currently change the Serial being used is by changing it on RS485.cpp.

RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS845_DEFAULT_DE_PIN, RS845_DEFAULT_RE_PIN);

To (example)

RS485Class RS485(Serial2, RS485_DEFAULT_TX_PIN, RS845_DEFAULT_DE_PIN, RS845_DEFAULT_RE_PIN);

Also, you can check pins_arduino.h file and find the alias for Serial2, it will probably be something like SERIAL_PORT_HARDWARE2, so you will have:

RS485Class RS485(SERIAL_PORT_HARDWARE2, RS485_DEFAULT_TX_PIN, RS845_DEFAULT_DE_PIN, RS845_DEFAULT_RE_PIN);

@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Oct 6, 2023
@per1234
Copy link
Contributor

per1234 commented Oct 6, 2023

Superseded by #59

@per1234 per1234 added the conclusion: duplicate Has already been submitted label Oct 6, 2023
@per1234 per1234 self-assigned this Oct 19, 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.

5 participants