DWORD Variables

This may be a stupid newbie question, but I’m trying to figure out how to utilize/work with Dword variables.

I’m currently extracting data from an energy meter over modbus. Most of this data is uint_16, which hasn’t given me any problems. Now I’d like to extract some data that is DWORD, and it keeps failing. are there any specific libraries I need to include to make DWORD work, or is it something more basic than that? The relevant portion of my modbus code is below.

#include "Register.h"

Register* RegisterList::list[NUMBER_OF_REGISTERS];

//constructs a ModbusRegister object
//Requires three parameters
//String for name of register, uint16_t for register address, String for register variable type
Register::Register(char* Reg_Name, uint16_t Reg_Address, String Reg_Type){
	Register_Name = Reg_Name;
	Register_Address = Reg_Address;
	Register_Type = Reg_Type;
}

void RegisterList::Initialize() {
	list[0]  = new Register((char*) "Ia",  0x1048, "int16" );  //Amps Phase A
	list[1]  = new Register((char*) "Ib",  0x1049, "int16" );  //Amps Phase B
	list[2]  = new Register((char*) "Ic",  0x104A, "int16" );  //Amps Phase C
	list[3]  = new Register((char*) "Isc", 0x104B, "sunssf");  //Current Scale Factor
...
}

@Ablock130 If you lookup the definition of Dword (it is helpfully a double word). Traditionally a word was 16 bits/2 bytes and thus Double word is 32bits. But things move on - the Photon is 32 bit and thus the variable type word is 32 bits/4bytes equivalent type is uint32_t or unsigned long. There is no double word (IMHO) but there is double 8 byte floating point. Back to the energy meter - uint16_t is a word and I am guessing dword is uint32_t. I am sure someone will correct me! What were you using to extract dword?

A good question - I am using @peergum’s modbus library. I should to interact with the RTU and extract data. I guess I should probably read through his documentation and see if there is anything in there for dword.

FWIW I am using an electron - I don’t think that that changes anything, but always good to be precise.

Just a trick: some modbus sensors use 2 registers to read 1 “double word” or “long” (2 bytes), some use 1 register to read 4 bytes… E.g. I worked with NuFlos and Trolls, and they behave differently.

In your code, you should use unions to map whatever you read to whatever the electron can understand. I think I documented (or exemplified) that, but I’m not 100% sure… Unfortunately, I have VERY little time on my hands, and doc is minimal :confused:

Thing is, it’s all trial and error with modbus… not talking about the undocumented stuff in sensors (e.g. writing strings…)

Good luck!

That may be it! The meter’s documentation does have two registers on it, and I couldn’t figure out what they were getting at there. I will have to figure out how to do a union.