Skip to content
Merged
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
5 changes: 4 additions & 1 deletion src/Comms/AuxDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ void AuxDevice::SetMode(AuxMode p_mode) noexcept
#if SUPPORT_MODBUS_RTU
uart->SetOnTxEndedCallback((p_mode == AuxMode::device) ? GlobalTxEndedCallback : nullptr, CallbackParameter(this));
#endif
uart->begin(baudRate);
AsyncSerial::UARTModes config = AsyncSerial::Mode_8N1;
if (serialParity == SerialParity::even) { config = AsyncSerial::Mode_8E1; }
else if (serialParity == SerialParity::odd) { config = AsyncSerial::Mode_8O1; }
uart->begin(baudRate, config);
mode = p_mode;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/Comms/AuxDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ class AsyncSerial;
class AuxDevice
{
public:
enum class SerialParity : uint8_t { none = 0, even, odd };

AuxDevice() noexcept;

void Init(AsyncSerial *p_uart, uint32_t p_baudRate) noexcept;
bool IsEnabledForGCodeIo() const noexcept { return mode == AuxMode::raw || mode == AuxMode::panelDue; }
void SetMode(AuxMode p_mode) noexcept;
void SetSerialParity(SerialParity p_parity) noexcept { serialParity = p_parity; } // applied on next SetMode; affects device/Modbus mode only
void SetBaudRate(uint32_t p_baudRate) noexcept { baudRate = p_baudRate; } // must call SetMode after calling this to actually change the baud rate
void Disable() noexcept;
AuxMode GetMode() const noexcept { return mode; }
Expand Down Expand Up @@ -91,6 +94,8 @@ class AuxDevice
uint32_t baudRate;
AuxMode mode = AuxMode::disabled; // whether disabled, raw, PanelDue mode or Modbus RTU mode

SerialParity serialParity = SerialParity::none; // device/Modbus serial parity: none=8N1, even=8E1, odd=8O1

#if SUPPORT_MODBUS_RTU
IoPort txNotRx; // port used to switch the RS485 port between transmit and receive
uint8_t *_ecv_array receivedData;
Expand Down
8 changes: 8 additions & 0 deletions src/Platform/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2303,6 +2303,14 @@ GCodeResult Platform::HandleM575(GCodeBuffer& gb, const StringRef& reply) THROWS
}
}
# endif
// Serial parity for device/Modbus mode. Always applied so that omitting F restores
// the pre-existing behaviour (no parity, 8N1) rather than keeping a previous setting.
switch (gb.Seen('F') ? gb.GetLimitedUIValue('F', 3) : 0)
{
case 1: dev.SetSerialParity(AuxDevice::SerialParity::even); break;
case 2: dev.SetSerialParity(AuxDevice::SerialParity::odd); break;
default: dev.SetSerialParity(AuxDevice::SerialParity::none); break;
}
# endif
}

Expand Down
Loading