Skip to main content
Home
for DLMS smart meters

Main navigation

  • Home
  • Products
  • About us
  • Open Source
  • Community
  • Forum
  • Downloads
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Scaler Doesn't Behave Correctly In Gurux DLMS Server

Scaler doesn't behave correctly in Gurux DLMS Server

Profile picture for user jack 001
By jack 001, 27 August, 2025
Forums
Gurux DLMS for ANSI C++

Hi, hope you have a good day. I try to add current register in my DLMS Server:

// add current
    CGXDLMSRegister *pRegister_curr = new CGXDLMSRegister("1.0.31.7.0.255");
    pRegister_curr->SetAccess(2, DLMS_ACCESS_MODE_READ);
    // set unit
    unsigned char cr_unit = DLMS_UNIT_CURRENT;
    pRegister_curr->SetUnit(cr_unit);
    // set scaler
    double curr_scaler;
    curr_scaler = 0.01;
    pRegister_curr->SetScaler(curr_scaler);
    // set value
    // query from db
    std::cout << (db.connect() ? "Connected to database." : "Failed to connect to database.") << std::endl;
    auto rows1 = db.rawQuery("SELECT * FROM `dt_meter1_register`");
    CGXDLMSVariant curr_val;
    curr_val = rows1[0]._0_0_1_0_0_255;
    pRegister_curr->SetValue(curr_val);
    std::cout << "Current value: " << curr_val.ToString() << std::endl;
    // debug
    double scaler_curr = pRegister_curr->GetScaler();
    std::cout << "Scaling factor: " << scaler_curr << std::endl;
    // double scaled_curr = curr_val.ToDouble() * scaler_curr;
    // std::cout << "Scaled value: " << scaled_curr << std::endl;
    GetItems().push_back(pRegister_curr);

I set the scaler to 0.01, but the value doesn't get scaled properly. Let's say the value is 90, it would not be shown as 0.9 in Gurux GXDLMSDirector. I tried setting it as (-2), assuming the power of base10 of that is 0.01. What's the proper way to do this?

Thank you

jack

Profile picture for user Kurumi

Kurumi

2 months 1 week ago

Hi Jack, The scaler is used…

Hi Jack,

The scaler is used when the value is read from the meter, and if the scaler is set.

pRegister_curr->SetValue only updates the value. Scaler is used when the value is write to the meter.

You also need to set the Force read or read the association view again if you change the scaler because it's static and read only once.

You can set the Force read by selecting "View" and "Force Read".

BR,
Mikko

Profile picture for user jack 001

jack 001

2 months 1 week ago

Hi Mikko, thank you for the…

Hi Mikko, thank you for the response. I did re-associate by refreshing the device/pressing F5 each time I add/modify something to the server code, so the edit would take effect. 
When tinkering with the server code, if I only do SetValue with no scaler, say 199, the value would show 199 in GXDLMSDirector. Then I try SetScaler and put it right after the SetValue
Regarding the value, i already put the value after i set the scaler, to my understanding If the scaler is used when the value gets written to the meter, that value should be updated with the scaler applied, isn't it? 
Here's my updated code, this time i try another GetValue which takes two arguments. The value is still static:

// add voltage
    CGXDLMSRegister *pRegister_volt = new CGXDLMSRegister("1.0.32.7.0.255");
    pRegister_volt->SetAccess(2, DLMS_ACCESS_MODE_READ);
    unsigned char volt_unit = DLMS_UNIT_VOLTAGE;
    pRegister_volt->SetUnit(volt_unit);
    pRegister_volt->SetScaler(0.01);
    // set value
    CGXDLMSVariant volt_val;
    volt_val = (double)1234;
    pRegister_volt->SetValue(volt_val);
    GetItems().push_back(pRegister_volt);

	
    // debug
    CGXDLMSSettings& settingsTest = GetSettings(); 
    CGXDLMSValueEventArg e(pRegister_volt, 2);
    
    double scaler_volt = pRegister_volt->GetScaler();
    std::cout << "Scaling factor: " << scaler_volt << std::endl;
    double scaled_volt = volt_val.ToDouble() * scaler_volt;
    std::cout << "Scaled value: " << scaled_volt << std::endl;
    
    // CGXDLMSValueEventArg ee(&settings, pRegister_volt, 1)
    int retScalerTest;
    if ((retScalerTest = pRegister_volt->GetValue(settingsTest, e)) == 0) {

        double scaledVoltVal = e.GetValue().ToDouble(); // after this should be scaled value (?)
        std::cout << "pRegister_volt after scaled value: " << scaledVoltVal << std::endl;
    } else {
        std::cout << "Error getting value: " << retScalerTest << std::endl;
    }

The result i get is this:

Scaling factor: 0.01
Scaled value: 12.34
pRegister_volt after scaled value: 0
pRegister_volt scaled value: 123400

Help me to understand this better

 

Regards

jack

Profile picture for user Kurumi

Kurumi

2 months 1 week ago

Hi, Are you trying to make a…

Hi,

Are you trying to make a meter where you are adding the values from the database?

You don't need to call GetValue. The framework will handle that. You just need to set the correct value and scaler for the register object.

BR,
Mikko

Profile picture for user jack 001

jack 001

2 months 1 week ago

Hi Mikko, yes I do. I don't…

Hi Mikko, yes I do. I don't have my sensors handy with me, but I have some data from my meter that i store in a database.
I think I get it now, but the scaled value only appears in profile generic where i have some registers as the capture object. when i read it from the "Register" list, it doesnt get multiplied. Is it some limitation when using static data instead of dynamic data gathered from sensor?

Regards,
jack

Profile picture for user Kurumi

Kurumi

2 months 1 week ago

Hi, There are no limitations…

Hi,

There are no limitations. Ensure that you have only one instance of the register object that you share with profile generic capture objects.

Check your register scaler value.

BR,
Mikko

  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Wed, 10/29/2025 - 08:51
    gurux.dlms.c 9.0.2510.2901
  • Thu, 10/16/2025 - 09:59
    gurux.dlms.java 4.0.83
  • Wed, 10/08/2025 - 10:21
    gurux.dlms.c 9.0.2510.0801
  • Fri, 09/26/2025 - 10:02
    gurux.dlms.cpp 9.0.2509.2601
  • Fri, 09/26/2025 - 09:45
    gurux.dlms.c 9.0.2509.2601

New forum topics

  • Guidance on using the source codes
  • How to get/convert user readable format data from readRowsByRange
  • Insufficient memory to continue the execution of the program.
  • The client instance code failed to connect to the electricity meter for authentication
  • Unable to Release Request when closing connection with meter.
More
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin