Added Resetfunktionen
modified: include/ModbusSlaveConfigToEEPROM.h
This commit is contained in:
parent
0e3024effb
commit
ec1d6a644e
@ -14,6 +14,8 @@ public:
|
||||
ModBusConfig(); // Konstruktor ohne Parameter
|
||||
void SetModbusID(int ID);
|
||||
void SetBaudRate(int BAUDRATE);
|
||||
void ResetModbusID(); // Method to reset Modbus ID
|
||||
void ResetBaudRate(); // Method to reset Baud Rate
|
||||
int GetModbusID();
|
||||
int GetBaudRate();
|
||||
|
||||
@ -26,6 +28,9 @@ private:
|
||||
static const int BAUD_RATE_ADDRESS = 1; // Speicheradresse für Baudrate
|
||||
static const int MAX_BAUD_RATE = 38400; // Maximal unterstützte Baudrate
|
||||
static const int MAX_MODBUS_ID_ADDRESS = 254; // Maximal unterstützte Baudrate
|
||||
|
||||
static const int STANDARD_MODBUS_ID = 22;
|
||||
static const int STANDARD_MODBUS_BAUDRATE = 9600;
|
||||
|
||||
unsigned long lastWriteTimeID = 0; // Last write time for Modbus ID
|
||||
unsigned long lastWriteTimeBaud = 0; // Last write time for Baud rate
|
||||
@ -39,10 +44,10 @@ private:
|
||||
ModBusConfig::ModBusConfig() {
|
||||
// Optional: Initialisieren Sie die EEPROM-Werte, falls erforderlich
|
||||
if (EEPROM.read(MODBUS_ID_ADDRESS) == 0xFF) {
|
||||
SetModbusID(22); // Setze Standard ID
|
||||
SetModbusID(STANDARD_MODBUS_ID); // Setze Standard ID
|
||||
}
|
||||
if (EEPROM.read(BAUD_RATE_ADDRESS) == 0xFF) {
|
||||
SetBaudRate(9600); // Setze Standard Baudrate
|
||||
SetBaudRate(STANDARD_MODBUS_BAUDRATE); // Setze Standard Baudrate
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,6 +64,10 @@ void ModBusConfig::SetModbusID(int ID) {
|
||||
}
|
||||
}
|
||||
|
||||
void ModBusConfig::ResetModbusID() {
|
||||
SetModbusID(STANDARD_MODBUS_ID); // Reset to standard ID
|
||||
}
|
||||
|
||||
void ModBusConfig::SetBaudRate(int BAUDRATE) {
|
||||
int dividedBaudrate = BAUDRATE / 100;
|
||||
unsigned long currentTime = millis();
|
||||
@ -76,6 +85,10 @@ void ModBusConfig::SetBaudRate(int BAUDRATE) {
|
||||
}
|
||||
}
|
||||
|
||||
void ModBusConfig::ResetBaudRate() {
|
||||
SetBaudRate(STANDARD_MODBUS_BAUDRATE); // Reset to standard Baud rate
|
||||
}
|
||||
|
||||
int ModBusConfig::GetModbusID() {
|
||||
int MbID = EEPROM.read(MODBUS_ID_ADDRESS);
|
||||
return MbID;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user