This commit is contained in:
Emmanuel HC
2025-10-27 18:26:08 -05:00
parent 900f38fb5c
commit 0eaa0232e9
5 changed files with 14 additions and 13 deletions

View File

@@ -66,12 +66,11 @@ template<>
State<ModbusIP>* RunningState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
// STATE control, add conditions if change to a different state is needed
Serial.println("Running update function");
Serial.println("Running update function");
float State_Ctrl = getPointValue(equipment, "State Control");
if (State_Ctrl == 0){
if (State_Ctrl == 0.0f){
return new StandbyState<ModbusIP>();
}
if (State_Ctrl == 2){
if (State_Ctrl == 2.0f){
return new StandbyState<ModbusIP>();
}
// Apply any strategies defined for the standby state
@@ -98,8 +97,8 @@ State<ModbusIP>* RunningState<ModbusIP>::update(Equipment<ModbusIP>* equipment)
float pf = getPointValue(equipment, "PF");
float kva = (1.732f * ((volts_AB + volts_BC + volts_AC)/4.0f) * real_load * (pf/100.0f))/100.0f;
float kw = (1.732f * ((volts_AB + volts_BC + volts_AC)/4.0f) * real_load )/100.0f;
float kva = (1.732f * ((volts_AB + volts_BC + volts_AC)/4.0f) * real_load * (pf/100.0f))/100000.0f;
float kw = (1.732f * ((volts_AB + volts_BC + volts_AC)/4.0f) * real_load )/10000.0f;
setPointValue(equipment, "kW", kw);
setPointValue(equipment, "kVA", kva);
@@ -119,7 +118,8 @@ void RunningState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
// Logic to run when the equipment enters this state
Serial.println("Enter Running State...");
// You could also update a Modbus register to show the "standby" state
setBitValue(equipment, "CB Position", 1, true);
setBitValue(equipment, "CB Position", 0, true);
setBitValue(equipment, "CB Position", 12, false);
}
/**

View File

@@ -57,14 +57,14 @@ State<ModbusIP>* StandbyState<ModbusIP>::update(Equipment<ModbusIP>* equipment)
// STATE control, add conditions if change to a different state is needed
Serial.println("Standby update function");
float State_Ctrl = getPointValue(equipment, "State Control");
if (State_Ctrl == 1){
if (State_Ctrl == 1.0f){
return new RunningState<ModbusIP>();
}
if (State_Ctrl == 0){
if (State_Ctrl == 0.0f){
setBitValue(equipment, "CB Position", 12, false);
}
if (State_Ctrl == 2){
if (State_Ctrl == 2.0f){
setBitValue(equipment, "CB Position", 12, true);
}
// Apply any strategies defined for the standby state

View File

@@ -23,7 +23,7 @@
#include <ModbusIP_ESP8266.h>
const char *ssid = "QTS_CDR_Arduino"; /**< @brief The SSID of the WiFi network. */
const char *password = "123abc456"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(172, 17, 33, 150); /**< @brief The static IP address for the device. */
IPAddress local_IP(172, 17, 33, 154); /**< @brief The static IP address for the device. */
IPAddress gateway(172, 17, 33, 1); /**< @brief The gateway IP address. */
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
@@ -63,7 +63,7 @@ modbusMap mb_map[] =
{HR, 9, 0, "State Control"}, //Open-Close Cmd
{HR, 10, 0, "Load"}, //Adjustble Load
{HR, 11, 0, "Rating"}, //Max amp to calculate kw, kVA, etc
{IR_LONG, 41, 0, "CB Position"}, //b0 close open b12 tripped
{IR, 41, 0, "CB Position"}, //b0 close open b12 tripped
{IR_LONG, 101, 0, "Amps A"},
{IR_LONG, 103, 0, "Amps B"},
{IR_LONG, 105, 0, "Amps C"},

View File

@@ -64,11 +64,12 @@ modbusMap mb_map[] =
{HR, 10, 0, "Load"},
{HR, 11, 0, "Rating"},
{IR, 2, 0, "Status"},
{IR, 2, 0, "Status"}, //bit 2 open-close,
{IR, 3, 0, "Amps A"},
{IR, 5, 0, "Amps B"},
{IR, 7, 0, "Amps C"},
{IR, 9, 0, "Amps N"},
{IR, 13, 0, "Tripped"}, //bit 0 tripped
};
//Size of modbus map used in FOR cycles, automatically calculated.

View File

@@ -64,7 +64,7 @@ modbusMap mb_map[] =
{HR, 10, 0, "Load"},
{HR, 11, 0, "Rating"},
{IR, 207, 0, "CB Position"},
{IR, 207, 0, "CB Position"}, //bit 9 tripp bit 12 open closed
{IR_FLOAT, 215, 0, "Amps A"},
{IR_FLOAT, 217, 0, "Amps B"},
{IR_FLOAT, 219, 0, "Amps C"},