Storing a large number in the Modbus Registers


I want to store a large number (upto 10 digits long, its a Unix timestamp) in my OpenEMS component. I am currently storing the value in the holding input register but I see very odd values in the OpenEMS channels.
Currently, I use FC3ReadRegisterTask to read the register and it is using a SignedWordElement. However, I see very wrong and reduced values in the channel.

How should I be storing such large values, in terms of the Modbus element, the Task and Element? Alternatively, is there a way to send the unix timestamp to the OpenEMS Edge instance?

Thank you :slight_smile:

There are couple of things - the signed vs unsigned and also size of raw byte sequence used to store/read register. For modbus both sides must assume same representation. For large values, such as java.lang.Long, you need 64 bits which translates to 4 modbus registers, each having 16 bits. As far I remember WORD will cover 32 bit values (2 registers), what you might need is DWORD (double word) which will span over 4 registers.
Final remark - the unsigned representation of Long will exceed range defined by java, so you need to map unsigned value to BigInteger.

Hi @dsen,

as ldywicki explained, you need a Modbus table provided by the hardware manufacturer. This should give you sufficient information to find out how many registers or WORDs are to be combined to a single value.

OpenEMS by default supports a large number of different modbus formats - see → openems/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/api/element at develop · OpenEMS/openems · GitHub

  • SignedWordElement is for 16 bit signed integers
  • UnsignedWordElement is for 16 bit unsigned integers
  • UnsignedDoublewordElement is for 32 bit unsigned integers
  • is for 64 bit unsigned integers

That’s usually sufficient. Longer data is often stored as String - use a

  • StringWordElement for that.

There are plenty examples for all of these classes in the code.


1 Like


Thank you very much for the resources. I’m working on a simulator for power systems (HIL Typhoon) so I was able to create the modbus tables I needed.

Warm regards

1 Like