mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-24 03:06:33 +00:00
Merge pull request #16078 from jeroenst/ModbusTCP
Baudrate and serial config for modbus_bridge are now persistent
This commit is contained in:
commit
41742abfb0
@ -833,8 +833,10 @@ typedef struct {
|
|||||||
uint8_t shd_warmup_time; // F5E
|
uint8_t shd_warmup_time; // F5E
|
||||||
uint8_t tcp_config; // F5F
|
uint8_t tcp_config; // F5F
|
||||||
uint8_t light_step_pixels; // F60
|
uint8_t light_step_pixels; // F60
|
||||||
|
uint8_t modbus_sbaudrate; // F61
|
||||||
|
uint8_t modbus_sconfig; // F62
|
||||||
|
|
||||||
uint8_t free_f61[19]; // F61 - Decrement if adding new Setting variables just above and below
|
uint8_t free_f63[17]; // F63 - Decrement if adding new Setting variables just above and below
|
||||||
|
|
||||||
// Only 32 bit boundary variables below
|
// Only 32 bit boundary variables below
|
||||||
SOBitfield6 flag6; // F74
|
SOBitfield6 flag6; // F74
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
#define XDRV_63 63
|
#define XDRV_63 63
|
||||||
|
|
||||||
#define MBR_MAX_VALUE_LENGTH 30
|
#define MBR_MAX_VALUE_LENGTH 30
|
||||||
#define MBR_SPEED TM_MODBUS_BAUDRATE
|
#define MBR_BAUDRATE TM_MODBUS_BAUDRATE
|
||||||
#define MBR_MAX_REGISTERS 64
|
#define MBR_MAX_REGISTERS 64
|
||||||
|
|
||||||
#define D_CMND_MODBUS_SEND "Send"
|
#define D_CMND_MODBUS_SEND "Send"
|
||||||
@ -154,14 +154,17 @@ ModbusBridge modbusBridge;
|
|||||||
//
|
//
|
||||||
bool ModbusBridgeBegin(void)
|
bool ModbusBridgeBegin(void)
|
||||||
{
|
{
|
||||||
int result = tasmotaModbus->Begin(Settings->baudrate * 300, ConvertSerialConfig(Settings->sserial_config)); // Reinitialize modbus port with new baud rate
|
if ((Settings->modbus_sbaudrate < 300 / 300) || (Settings->modbus_sbaudrate > 115200 / 300)) Settings->modbus_sbaudrate = (uint8_t)MBR_BAUDRATE / 300;
|
||||||
|
if (Settings->modbus_sconfig > TS_SERIAL_8O2) Settings->modbus_sconfig = TS_SERIAL_8N1;
|
||||||
|
|
||||||
|
int result = tasmotaModbus->Begin(Settings->modbus_sbaudrate * 300, ConvertSerialConfig(Settings->modbus_sconfig)); // Reinitialize modbus port with new baud rate
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
if (2 == result)
|
if (2 == result)
|
||||||
{
|
{
|
||||||
ClaimSerial();
|
ClaimSerial();
|
||||||
}
|
}
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR("MBS: MBR %s ser init at %d baud"), (2 == result ? "HW" : "SW"), Settings->baudrate * 300);
|
AddLog(LOG_LEVEL_DEBUG, PSTR("MBS: MBR %s ser init at %d baud"), (2 == result ? "HW" : "SW"), Settings->modbus_sbaudrate * 300);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -172,19 +175,22 @@ void SetModbusBridgeConfig(uint32_t serial_config)
|
|||||||
{
|
{
|
||||||
serial_config = TS_SERIAL_8N1;
|
serial_config = TS_SERIAL_8N1;
|
||||||
}
|
}
|
||||||
if (serial_config != Settings->sserial_config)
|
if (serial_config != Settings->modbus_sconfig)
|
||||||
{
|
{
|
||||||
Settings->sserial_config = serial_config;
|
Settings->modbus_sconfig = serial_config;
|
||||||
ModbusBridgeBegin();
|
ModbusBridgeBegin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetModbusBridgeBaudrate(uint32_t baudrate)
|
void SetModbusBridgeBaudrate(uint32_t baudrate)
|
||||||
{
|
{
|
||||||
if (baudrate >= 300)
|
if ((baudrate >= 300) && (baudrate <= 115200))
|
||||||
{
|
{
|
||||||
Settings->baudrate = baudrate / 300;
|
if (baudrate / 300 != Settings->modbus_sbaudrate)
|
||||||
ModbusBridgeBegin();
|
{
|
||||||
|
Settings->modbus_sbaudrate = baudrate / 300;
|
||||||
|
ModbusBridgeBegin();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,8 +360,6 @@ void ModbusBridgeInit(void)
|
|||||||
if (PinUsed(GPIO_MBR_RX) && PinUsed(GPIO_MBR_TX))
|
if (PinUsed(GPIO_MBR_RX) && PinUsed(GPIO_MBR_TX))
|
||||||
{
|
{
|
||||||
tasmotaModbus = new TasmotaModbus(Pin(GPIO_MBR_RX), Pin(GPIO_MBR_TX));
|
tasmotaModbus = new TasmotaModbus(Pin(GPIO_MBR_RX), Pin(GPIO_MBR_TX));
|
||||||
SetModbusBridgeConfig(TS_SERIAL_8E1);
|
|
||||||
SetModbusBridgeBaudrate(MBR_SPEED);
|
|
||||||
|
|
||||||
#ifdef USE_MODBUS_BRIDGE_TCP
|
#ifdef USE_MODBUS_BRIDGE_TCP
|
||||||
// If TCP bridge is enabled allocate a TCP receive buffer
|
// If TCP bridge is enabled allocate a TCP receive buffer
|
||||||
@ -546,7 +550,7 @@ void CmndModbusBridgeSend(void)
|
|||||||
void CmndModbusBridgeSetBaudrate(void)
|
void CmndModbusBridgeSetBaudrate(void)
|
||||||
{
|
{
|
||||||
SetModbusBridgeBaudrate(XdrvMailbox.payload);
|
SetModbusBridgeBaudrate(XdrvMailbox.payload);
|
||||||
ResponseCmndNumber(Settings->baudrate * 300);
|
ResponseCmndNumber(Settings->modbus_sbaudrate * 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmndModbusBridgeSetConfig(void)
|
void CmndModbusBridgeSetConfig(void)
|
||||||
@ -573,7 +577,7 @@ void CmndModbusBridgeSetConfig(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ResponseCmndChar(GetSerialConfig(Settings->sserial_config).c_str());
|
ResponseCmndChar(GetSerialConfig(Settings->modbus_sconfig).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_MODBUS_BRIDGE_TCP
|
#ifdef USE_MODBUS_BRIDGE_TCP
|
||||||
|
Loading…
x
Reference in New Issue
Block a user