RS485 for Relay Outputs

Forum is open to all questions, answers, and discussions related to electric meters, ours or others.
Post Reply
ctacke
Posts: 5
Joined: Tue Oct 21, 2014 11:04 am

RS485 for Relay Outputs

Post by ctacke »

The documentation on the exact commands to send over RS485 to set the relay states isn't 100% clear to me.

This is my understanding so far is that it generally looks like this, but the data in the set parts I don't understand. I'm able to read data just fine.

Send Full Meter Request (Master)
Receive Meter Response
Send Password (what does this look like for a default password of "0")?
Receive Meter Responds OK
Send Set OUT1 Closed (What does this look like?)
Receive Meter Responds OK
Send Set OUT1 Open (What does this look like?)
Receive Meter Responds OK
Send Set OUT2 Closed (What does this look like?)
Receive Meter Responds OK
Send Set OUT2 Open (What does this look like?)
Receive Meter Responds OK
Send Close String (Master)
Jameson
Posts: 860
Joined: Fri Nov 04, 2011 7:42 pm
Location: Santa Cruz, CA
Contact:

Re: RS485 for Relay Outputs

Post by Jameson »

I would answer this question by using the EKM Dash software. Go to Help > Hex Inspector and select your v4 meter.

Then open the Edit meter and click the "Control" tab. Change the relays via RS485 and watch the data come into the Hex Inspector window. (default meter password is "0")

Here is the entire sequence for v4 meter 300000029 with password "0" ( I have changed the relays in the order that you mentioned), if you follow this sequence exactly with your software it will work for you as well:

Send
2F 3F 30 30 30 33 30 30 30 30 30 30 32 39 30 30
21 0D 0A

Receive
02 10 24 15 30 30 30 33 30 30 30 30 30 30 32 39
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 33 38 34 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 4C
30 39 31 43 30 30 30 43 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 36 30 30 31 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 31 31 32 30 30 31 34 31 30 32 34 30
36 30 31 35 31 31 36 30 30 21 0D 0A 03 34 03

Send
01 50 31 02 28 30 30 30 30 30 30 30 30 29 03 32
44

Receive
06

Send
01 57 31 02 30 30 38 31 28 30 30 30 30 30 29 03
21 21

Receive
06

Send
01 42 30 03 75

Send
2F 3F 30 30 30 33 30 30 30 30 30 30 32 39 30 30
21 0D 0A

Receive
02 10 24 15 30 30 30 33 30 30 30 30 30 30 32 39
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 33 38 34 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 4C
30 39 35 43 30 30 30 43 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 36 30 30 31 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 31 31 32 30 30 31 34 31 30 32 34 30
36 30 31 35 31 32 37 30 30 21 0D 0A 03 11 14

Send
01 50 31 02 28 30 30 30 30 30 30 30 30 29 03 32
44

Receive
06

Send
01 57 31 02 30 30 38 31 28 31 30 30 30 30 29 03
31 61

Receive
06

Send
01 42 30 03 75

Send
2F 3F 30 30 30 33 30 30 30 30 30 30 32 39 30 30
21 0D 0A

Receive
02 10 24 15 30 30 30 33 30 30 30 30 30 30 32 39
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 33 38 34 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 4C
30 39 30 43 30 30 30 43 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 36 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 31 33 32 30 30 31 34 31 30 32 34 30
36 30 31 35 31 33 31 30 30 21 0D 0A 03 1A 3D

Send
01 50 31 02 28 30 30 30 30 30 30 30 30 29 03 32
44

Receive
06

Send
01 57 31 02 30 30 38 32 28 30 30 30 30 30 29 03
35 51

Receive
06

Send
01 42 30 03 75

Send
2F 3F 30 30 30 33 30 30 30 30 30 30 32 39 30 30
21 0D 0A

Receive
02 10 24 15 30 30 30 33 30 30 30 30 30 30 32 39
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 33 38 34 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 4C
30 39 32 43 30 30 30 43 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 36 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 31 33 32 30 30 31 34 31 30 32 34 30
36 30 31 35 31 33 35 30 30 21 0D 0A 03 24 3C

Send
01 50 31 02 28 30 30 30 30 30 30 30 30 29 03 32
44

Receive
06

Send
01 57 31 02 30 30 38 32 28 31 30 30 30 30 29 03
25 11

Receive
06

Send
01 42 30 03 75
Jameson
EKM METERING
http://www.ekmmetering.com
831.425.7371
ctacke
Posts: 5
Joined: Tue Oct 21, 2014 11:04 am

Re: RS485 for Relay Outputs

Post by ctacke »

Thanks for the details.

I would have gone the route of using the EKM Dash software, but it has never been able to connect to my meter, even running on the same PC, using the same COM port as my own software which does communicate with it just fine.
Jameson
Posts: 860
Joined: Fri Nov 04, 2011 7:42 pm
Location: Santa Cruz, CA
Contact:

Re: RS485 for Relay Outputs

Post by Jameson »

Thanks, we would be happy to give you a hand with setting up your EKM Dash.

Please post a screenshot of your EKM Dash setup window. Showing the meter number, the meter type, port, etc. The error message you are seeing in the activity window would be helpful too.

Thanks,
Jameson
EKM METERING
http://www.ekmmetering.com
831.425.7371
ctacke
Posts: 5
Joined: Tue Oct 21, 2014 11:04 am

Re: RS485 for Relay Outputs

Post by ctacke »

What would be extremely useful for people trying to create software would be a breakdown of those commands, like you do with the parsing of the v4 read.

For example, you have the "send password" as this:

01 50 31 02 28 30 30 30 30 30 30 30 30 29 03 32 44

What are the components of this? Which part is the actual password? The '28' could be a length, since there look to be 8 zeros after it, but that's not documented anywhere, and even if it is, what are the 4 byes before it and the 4 after (I assume the last 2 is a CRC).

Same for the relay. I can look at your example and deduce some of it, but clear documentation of the command would be helpful.

So this is what you sent:

01 57 31 02 30 30 38 31 28 30 30 30 30 30 29 03 21 21 <- out1 closed
01 57 31 02 30 30 38 31 28 31 30 30 30 30 29 03 31 61 <- out1 open
01 57 31 02 30 30 38 32 28 30 30 30 30 30 29 03 35 51 <- out2 closed
01 57 31 02 30 30 38 32 28 31 30 30 30 30 29 03 25 11 <- out2 open

The meanings are:
Bytes 1-7? Unknown.
Byte 8 = output number. 31 == out1, 32 == out 2
Byte 9? unknown.
Byte 10 = state. 30 == closed, 31 == open.
Bytes 11-16? Unknown
Bytes 17-18. CRC

The CRC polynomial you use would also be helpful.
Jameson
Posts: 860
Joined: Fri Nov 04, 2011 7:42 pm
Location: Santa Cruz, CA
Contact:

Re: RS485 for Relay Outputs

Post by Jameson »

Here again I will use the EKM Dash to answer the question. You are right that the "Settings" document is a bit vague, but when combined with the Dash Hex Inspector a lot more of it begins to make sense.

If I say Turn Relay "On" for 8765 seconds, the EKM Dash sends the meter:

Send
01 57 31 02 30 30 38 31 28 31 38 37 36 35 29 03
15 60

From this document: http://documents.ekmmetering.com/Omnime ... otocol.pdf
on the Developer Portal: http://www.ekmmetering.com/developer-portal

01 57 31 02: lead in characters for meter settings

30 30 38 31: Relay 1

28: Spacer

31: On

38 37 36 35: Seconds to in this case turn "On" the relay

29 03: CRC16 checksum

===

Your question about this password string: 01 50 31 02 28 30 30 30 30 30 30 30 30 29 03 32 44

In this case the password is "0" it is the 8 ASCII characters 30 30 30 30 30 30 30 30

Everything else is essentially lead in characters and following characters and 32 44 is the CRC16 checksum

===

Send us an email and I will send you my CRC16 information dump (waaay too much information to post here). It is essentially a jumble of code, byte arrays, and hints from users that have gone through the pain of figuring out our CRC16. I dont understand it well myself. All I do know is the hangup usually centers around that we use 7 bit data and that CRC16 assumes 8 bit data (you have to fake the 8th bit)
Jameson
EKM METERING
http://www.ekmmetering.com
831.425.7371
ctacke
Posts: 5
Joined: Tue Oct 21, 2014 11:04 am

Re: RS485 for Relay Outputs

Post by ctacke »

Yep, I figured out the CRC (I determined it was the modbus polynomial of 0xa001). In C# it looks like this:

Code: Select all

private static byte[] AppendCRC(IEnumerable<byte> data)
{
    var message = data.ToArray();

    // skip the first byte
    var offset = 1;
    var length = message.Length - 1;

    var seed = 0xffff;
    byte high = 0xFF;
    byte low = 0xFF;

    for (int i = offset; i < length + offset; i++)
    {
        seed = (ushort)(seed ^ message[i]);

        for (int j = 0; j < 8; j++)
        {
            var lsb = (char)(seed & 0x0001);
            seed = (ushort)((seed >> 1) & 0x7FFF);

            if (lsb == 1)
            {
                seed = (ushort)(seed ^ 0xA001);
            }
        }
    }
            
    high = (byte)((seed >> 8) & 0x7F); // EKM strips the MSB on each CRC byte
    low = (byte)(seed & 0x7F); // EKM strips the MSB on each CRC byte

    var result = new byte[message.Length + 2];
    Buffer.BlockCopy(message, 0, result, 0, message.Length);
    result[result.Length - 2] = low;
    result[result.Length - 1] = high;

    return result;
}
Jameson
Posts: 860
Joined: Fri Nov 04, 2011 7:42 pm
Location: Santa Cruz, CA
Contact:

Re: RS485 for Relay Outputs

Post by Jameson »

Thanks for posting, I will add this to the ever growing "CRC16 information dump" ;)
Jameson
EKM METERING
http://www.ekmmetering.com
831.425.7371
Post Reply