There was an issue on obj_toString that is now fixed. Scaler is shown correctly. Value is not convert using scaler in ANSI C, so you need to multiply the value with a scaler.
Quantity: Voltage(U), Unit name: Volt, SI definition: V.
cosem_init(BASE(reg1), DLMS_OBJECT_TYPE_REGISTER, "1.0.12.7.0.255"); // For DLMS India Voltage
com_read(BASE(reg1), 3);
sprintf(str,"%s",®1.scalar); // Also tried reg1.unit
GXTRACE(PSTR("Unit:"), str);
This gave junk value. I need to get scalar value to multiply with Voltage value to get the float value result.
This gave correct value 242568. The voltage was 242.568V
How do I extract scalar value so I can multiply the scalar by voltage value as advised by you.?
I should get a float value of multiplication.
When read by DLMS Director the scalar is showing 0.001 which is correct. Please advise how to extract this value as a float value.
cosem_init(BASE(reg1), DLMS_OBJECT_TYPE_REGISTER, "1.0.12.7.0.255"); // For DLMS India Voltage
com_read(BASE(reg1), 3);
sprintf(str,"%s",®1.unit); // Also tried reg1.unit
GXTRACE(PSTR("Unit:"), str);
I changed the code to original like this
gxRegister reg1;
double scale;
cosem_init(BASE(reg1), DLMS_OBJECT_TYPE_REGISTER, "1.0.12.7.0.255");
com_read(BASE(reg1), 3);
com_read(BASE(reg1), 2);
obj_toString(BASE(reg1), &data);
GXTRACE(PSTR("Voltage"), data);
obj_clear(BASE(reg1));
free(data);
I got the following output.
:Start reading :com_initializeConnection SUCCEEDED 0 :VoltageIndex: 3 Value: Scaler: 1 Unit: Voltage
Index: 2 Value: 246175
The value is correct but the scaler is still wrong.
In DLMS director the scaler is 0.001.
Hi,
Hi,
There was an issue on obj_toString that is now fixed. Scaler is shown correctly. Value is not convert using scaler in ANSI C, so you need to multiply the value with a scaler.
Quantity: Voltage(U), Unit name: Volt, SI definition: V.
BR,
Mikko
Thank You sir,
Thank You sir,
I meant to ask how to get the value of individual voltage and scaler as integers rather than a converted string &data.
Regards
Ajit
Hi,
Hi,
reg1.scaler, reg1.unit and reg1.value.
BR,
Mikko
Respected Sir
Respected Sir
I tried the following
gxRegister reg1;
cosem_init(BASE(reg1), DLMS_OBJECT_TYPE_REGISTER, "1.0.12.7.0.255"); // For DLMS India Voltage
com_read(BASE(reg1), 3);
sprintf(str,"%s",®1.scalar); // Also tried reg1.unit
GXTRACE(PSTR("Unit:"), str);
This gave junk value. I need to get scalar value to multiply with Voltage value to get the float value result.
com_read(BASE(reg1), 2);
t_val=var_toInteger(®1.value);
sprintf(str, "%d\n", t_val);
GXTRACE(PSTR("Voltage"), str);
This gave correct value 242568. The voltage was 242.568V
How do I extract scalar value so I can multiply the scalar by voltage value as advised by you.?
I should get a float value of multiplication.
When read by DLMS Director the scalar is showing 0.001 which is correct. Please advise how to extract this value as a float value.
Thank You
BR
Ajit
Hi,
Hi,
You need to multiply value with scaler like this:
var_toInteger(®1.value) * pow(10, reg1.scaler);
ANSI C differs from other programming languages and it shows the value that is read from the meter and doesn't multiply it with a scaler.
BR,
Mikko
Thank You Sir,
Thank You Sir,
Further how do I extract unit?
I tried like this
cosem_init(BASE(reg1), DLMS_OBJECT_TYPE_REGISTER, "1.0.12.7.0.255"); // For DLMS India Voltage
com_read(BASE(reg1), 3);
sprintf(str,"%s",®1.unit); // Also tried reg1.unit
GXTRACE(PSTR("Unit:"), str);
It didnt work. Please advise correct method?
BR
Ajit
HI,
HI,
This is the correct way. Do you want to show the unit as a string? If so, use obj_getUnitAsString-method.
BR,
Mikko
Respected Sir
Respected Sir
As advised by I used the following code to get voltage value
I get some strange output like this
Unit# :Voltage-740319.000000
gxRegister reg1;
double scale;
cosem_init(BASE(reg1), DLMS_OBJECT_TYPE_REGISTER, "1.0.12.7.0.255");
com_read(BASE(reg1), 3);
sprintf(str, "%s", ®1.unit);
GXTRACE(PSTR("Unit"), str);
com_read(BASE(reg1), 2);
scale=var_toInteger(®1.value)*reg1.scaler;
sprintf(str, "%f\n", scale);
GXTRACE(PSTR("Voltage"), str);
I changed the code to original like this
gxRegister reg1;
double scale;
cosem_init(BASE(reg1), DLMS_OBJECT_TYPE_REGISTER, "1.0.12.7.0.255");
com_read(BASE(reg1), 3);
com_read(BASE(reg1), 2);
obj_toString(BASE(reg1), &data);
GXTRACE(PSTR("Voltage"), data);
obj_clear(BASE(reg1));
free(data);
I got the following output.
:Start reading :com_initializeConnection SUCCEEDED 0 :VoltageIndex: 3 Value: Scaler: 1 Unit: Voltage
Index: 2 Value: 246175
The value is correct but the scaler is still wrong.
In DLMS director the scaler is 0.001.
Please help
BR
Ajit
Hi,
Hi,
Use scaler like this:
var_toInteger(®1.value) * pow(10, reg1.scaler);
Respected Sir,
Respected Sir,
Thank you. It worked.
BR
Ajit