0
votes

I'm using an ElNet energy&power meter that communicates with my processor via Modbus RTU protocol.

There are two 16-bit ElNet registers that contain information about the Date and Time (separately) in a Win Format (registers 85-86, page 6 of this document). I'm able to read these two registers. However, I'm unable to extract information about the Date and Time.

For example, Date register contains decimal value of 17841 for today's date (31/07/2015). Is there any person willing to explain me how to convert 17841 into 31/07/2015?

I have the same problem with the time. My time register contains a decimal value of 55296. Can you help me extract the time from this number?

This thread addresses the same problem: HEX/Decimal to date and time from modbus However, I'm not sure I understand the extraction algorithm applied there. My point of operation is processor with the code written in C or C++.

Thank you very much for your time and effort to help me.

Sincerely,

Bojan.

1

1 Answers

1
votes

The MS-DOS date/time format is described here: https://archive.is/2bVlz (was http://proger.i-forge.net/MS-DOS_date_and_time_format/OFz but is gone)

It makes sense for the 17256 value mentioned in the other question, as it translates to 2013-11-08. See here how to do it:

Register bit description: 0bYYYYYYYMMMMDDDDD

Registervalue: 17256 0b0100001101101000

Yearmask: 0b1111111000000000
Yearpart: 0b0100001000000000
Yearpart rightshifted 9 steps: 0b0000000000100001 = 33 years after 1980

Monthmask: 0b0000000111100000
Monthpart: 0b0000000101100000
Monthpart rightshifted 5 steps: 0b0000000000001011 = 11

Daymask: 0b0000000000011111
Daypart: 0b0000000000001000 = 8

Unfortunately your register value 17841 does not make sense, as it translates to 2014-13-17 (That is month 13).

Are you sure that:

  • you read the correct register? (change the time setting in the instrument, and see what happens to the register value)
  • you do not mix up the two bytes in the register?
  • the time setting is correct?