Skip to content

Fix incorrect scaler arithmetic in CGXDLMSRegister#38

Open
salma1029 wants to merge 1 commit intoGurux:masterfrom
salma1029:fix/register-scaler-calculation
Open

Fix incorrect scaler arithmetic in CGXDLMSRegister#38
salma1029 wants to merge 1 commit intoGurux:masterfrom
salma1029:fix/register-scaler-calculation

Conversation

@salma1029
Copy link
Copy Markdown

Problem:

CGXDLMSRegister::GetValue() and SetValue() had inverted scaler operations:

  1. GetValue() divided raw value by scaler multiplier (should multiply)
  2. SetValue() multiplied scaled value by scaler multiplier (should divide)

This caused incorrect value transmission between client and server.

Changes:

File: src/GXDLMSRegister.cpp

GetValue() :

  • Before: tmp = m_Value.dblVal / GetScaler();
  • After: tmp = m_Value.dblVal * GetScaler();

SetValue() :

  • Before: val *= e.GetValue().ToDouble();
  • After: val = e.GetValue().ToDouble() / GetScaler();

Problem:
--------
CGXDLMSRegister::GetValue() and SetValue() had inverted scaler operations:
1. GetValue() divided raw value by scaler multiplier (should multiply)
2. SetValue() multiplied scaled value by scaler multiplier (should divide)

This caused incorrect value transmission between client and server.

Changes:
--------
File: src/GXDLMSRegister.cpp

GetValue() :
  - Before: tmp = m_Value.dblVal / GetScaler();
  + After:  tmp = m_Value.dblVal * GetScaler();

SetValue() :
  - Before: val *= e.GetValue().ToDouble();
  + After:  val = e.GetValue().ToDouble() / GetScaler();
@salma1029
Copy link
Copy Markdown
Author

salma1029 commented Apr 26, 2026

Summary

Fixes a bug in CGXDLMSRegister where scaler was applied incorrectly during value read/write operations.

Problem

The scaler arithmetic was inverted:

  • GetValue(): Divided by scaler multiplier (should multiply)
  • SetValue(): Multiplied by scaler multiplier (should divide)

This caused incorrect value transmission in DLMS communication for all registers with non-zero scalers.

@salma1029 salma1029 changed the title fix(register): correct scaler calculation in GetValue and SetValue Fix incorrect scaler arithmetic in CGXDLMSRegister Apr 26, 2026
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant