Skip to content
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

Add config parameter to RS485 initialization #27

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/RS485CommClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RS485CommClass::RS485CommClass(arduino::UART& uart_itf, PinName rs_tx_pin, PinNa
RS485CommClass::~RS485CommClass()
{ }

void RS485CommClass::begin(unsigned long baudrate, int predelay, int postdelay) {
void RS485CommClass::begin(unsigned long baudrate, uint16_t config = SERIAL_8N1, int predelay, int postdelay) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void RS485CommClass::begin(unsigned long baudrate, uint16_t config = SERIAL_8N1, int predelay, int postdelay) {
void RS485CommClass::begin(unsigned long baudrate, uint16_t config, int predelay, int postdelay) {

/* Pinout configuration */
pinMode(PinNameToIndex(MC_RS485_TX_PIN), OUTPUT);
pinMode(PinNameToIndex(MC_RS485_RX_PIN), OUTPUT);
Expand Down Expand Up @@ -45,7 +45,7 @@ void RS485CommClass::begin(unsigned long baudrate, int predelay, int postdelay)
_enable();

/* Call begin() base class to initialize RS485 communication */
RS485Class::begin(baudrate, predelay, postdelay);
RS485Class::begin(baudrate, config, predelay, postdelay);

return;
}
Expand Down Expand Up @@ -92,4 +92,4 @@ void RS485CommClass::_disable() {

arduino::UART _UART4_ {MC_RS485_TX_PIN, MC_RS485_RX_PIN, NC, NC};
RS485CommClass MachineControl_RS485Comm(_UART4_);
/**** END OF FILE ****/
/**** END OF FILE ****/
3 changes: 2 additions & 1 deletion src/RS485CommClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ class RS485CommClass : public RS485Class {
* This method initializes the RS485 communication protocol with the specified baud rate and pre/post delays.
*
* @param baudrate The desired baud rate for the RS485 communication.
* @param config The desired Serial config (bits, parity and stopbits), see HardwareSerial.h
* @param predelay The delay before sending data in the RS485 communication (default: RS485_DEFAULT_PRE_DELAY).
* @param postdelay The delay after sending data in the RS485 communication (default: RS485_DEFAULT_POST_DELAY).
*/
void begin(unsigned long baudrate = 115200, int predelay = RS485_DEFAULT_PRE_DELAY, int postdelay = RS485_DEFAULT_POST_DELAY);
void begin(unsigned long baudrate = 115200, uint16_t config = SERIAL_8N1, int predelay = RS485_DEFAULT_PRE_DELAY, int postdelay = RS485_DEFAULT_POST_DELAY);

/**
* @brief Close the RS485 communication protocol.
Expand Down
Loading