Reading the IR port of an IEC 62056-21 Smart Meter

Forum about Smart meters for Energy, Gas and Water and all related

Reading the IR port of an IEC 62056-21 Smart Meter

Postby alias » Sat May 19, 2012 1:04 am

Lately I see more and more people trying the read energy consumption information from their smart metering device by use of the P1 port or IR port.
At first glance reading from such a IEC 62056-21 compliant metering device seems to be fairly straightforward:

1. First we send a request for communication to the device
2. The device will send identification information back
3. In return we will acknowledge that identification message
4. And finally the metering device will start sending tariff data

In practice however, seizing the tariff data from the device is often more difficult than expected. Mostly due to lack of available documentation.
In response to some questions posted on this forum, and to save you from many hours of digging and reading, here’s a little guidance on how to read the IR port of a IEC 62056-21 compliant metering device:

The IEC 62056-21 specification states that initial communication between the requester (application) and the metering device will start at 300 baud using 7 bits, one stop bit and an even parity bit.

To inform the metering device that we would like to communicate with it, we send a “request message” to the device:
Image

In code, this could look like this:
Code: Select all
SerialPort port = new SerialPort("COM1", 300, Parity.Even, 7, StopBits.One);
port.Open();
port.WriteLine("/?!");  // WriteLine adds CR+LF

The metering device will respond to our request by returning an “identification message”:
Image

This message can be read fairly easy:
Code: Select all
string data = port.ReadLine();  // Read data from the device

The returned identification message data might read something like /ISK5\2ME382-1003 (which is identifying an Iskraemeco ME382 metering device).

Now let's start deciphering what this message data means:
Image

The data starts with the Start character, followed by the manufacturer identification.

The manufacturer identification consists of three upper case letters (eg. ISK), or two upper case letters plus one lower case letter (eg. ISk). If the third letter is a lower case letter this means that the metering device has a minimum response time of 20ms instead of 200ms. Aldo this might seem not that important, not obeying to the required response time can really screw up the communication with your device (trust me, been there :) ) (a list of manufacturers identification codes can be found here: dlms.com/organization/flagmanufacturesi ... index.html.)

The Baud rate identification is used for the baud rate changeover. The "request message", the "acknowledgement/option" and the "identification message" are transmitted with an initial rate of 300 baud. Subsequent communication can be performed at higher speed. With the baud rate identification the metering device indicates the required baud rate for further communication.
Image

In this case the metering device returns the value of 5, indicating a communication speed of 9600 baud. So we have to change our baud rate to 9600 baud in order to continue communication with the device.

The Sequence delimiter "\" (0x5c) is always followed by the mode identification character and will only occur in conjunction with the Mode identification character. This field is optional and part of the 16 characters long identification.

The Mode identification character defines the used communications protocol. Currently IEC 62056-21 compliant devices only support the High-Level Data Link Control (HDLC) mode (value of 2). The field is optional and part of the 16 characters long identification. (note: interpretation and usage of this character is unclear to me)

And finally the Device identification is manufacturer-specific and may consist of maximum 16 characters. Each character is allowed, excepted are the characters "/", "!". The character "\" is only allowed as ESC character and only in conjunction with the two optional fields "sequence delimiter" and "mode identification.

Code: Select all
string manufacturersIdentification = data.Substring(1, 3);
string baudrateIdentification = data.Substring(4, 1);
string modeIdentification = data.Substring(6, 1);
string identification = data.Substring(7);

Now that we have all the necessary device information we can acknowledge the identification message and switch over the desired communication speed. We start by sending an "acknowledgement/option" message to the metering device, still at initial speed (300 baud):
Image

In this "acknowledgement/option" message we confirm to the device that we will continue communication with the following parameters:
We set the Protocol control character to zero (0), indicating a normal protocol procedure
Image
(it is unclear to me why this has to be a value of 0, but it is the only value my metering device is responding to).

We set the Baud rate identifier to a value of 5, indicating a communication speed of 9600 baud (as specified by the device in the previous “Identification message”)

And finally set the Mode control character (to a value of 0) to indicate we want to read data from the metering device:
Image

In code, this might resemble like:
Code: Select all
char protocolControl = '0';
char modeControl = '0';
string acknowledge = (char)0x006 + protocolControl + baudrateIdentification + modeControl;
port.WriteLine(acknowledge);

Thread.Sleep(200);  // Wait for 200ms (not needed for a 20ms device)

int baudRate = 300;
switch (baudrateIdentification)
{
    case "0": break;
    case "1": baudRate = 600; break;
    case "2": baudRate = 1200; break;
    case "3": baudRate = 2400; break;
    case "4": baudRate = 4800; break;
    case "5": baudRate = 9600; break;
    case "6": baudRate = 19200; break;
    default:  break;
}
port.BaudRate = baudRate;   // Change over baud rate

And now, finally, we are set to read data messages from the device!

The data message is typically used for the transmission of tariff data by the metering device. Transmission starts immediately after the transmission of the "acknowledgement/option" message. A typical data message will look like:
Image

The "Block checksum character" is the calculated length parity over the characters of the data message beginning immediately after the STX up to the included ETX .

Immediately after changing the baud rate we can start reading data from the device:
Code: Select all
const char endChar = (char)0x21;
string telegram = string.Empty;

do
{
    data = port.ReadLine();
    telegram = telegram + data;
} while (data.IndexOf(EndChar) == -1);

Console.WriteLine(telegram);

The metering device will return data in the form of a telegram containing so called COSEM objects (using OBIS, the Object Identification System).
More on how to interpret COSEM/OBIS data can be found in the Dutch Smart Meter Specification, especially the P1 companion standard:
files.domoticaforum.eu/Smartmetering/DS ... l%20P1.pdf

Happy reading! :)

Regards
alias
Member
Member
 
Posts: 60
Joined: May 2011
Location: Apeldoorn / Netherlands

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Postby Bwired » Sat May 19, 2012 10:22 am

Great posting, made it sticky
thanks!
User avatar
Bwired
Administrator
Administrator
 
Posts: 5300
Joined: March 2006
Location: Netherlands

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Postby Robke » Sat May 19, 2012 1:48 pm

Hi Alias,

Thank you very much!
I think i can do much more with those information!

Regards,
Robke
Robke
Starting Member
Starting Member
 
Posts: 22
Joined: April 2012

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Postby Robke » Sun May 20, 2012 7:55 pm

Hi,

I write a piece of code (VB.NET) and still got some questions to you:
1. After i send the acknowledge identification message the baud rate changed from 300 to 9600 kbit/sec (normally). But is it normal that i don't receive a message from my meter after i sending this message? Because i don't see any answer at all.
2. When the baud rate is changed to 9600 i have to send a message STX <data block max 3 bytes?> ! CR LF ETC and BCC. Can you show me a message how to view the 1.7.x registers from the meter? Because i read the document and i don't understand how to make this message (another thing, my English is really bad :x so it's difficult to read and understand).
3. What do you mean exactly with: N-1 and N. And the BCC is an XOR from the other values?
4. You let me see a piece of code: Char protocolControl = '0'; this means in hex 30 or 0?
5. I think you write the example code into C++ and my question is, can you send me a source code (so i can compile by myself) you used so i can test if it works with my meter?

Ps. i also have a Iskra meter.

Thank you!

Regards,
Robke
Robke
Starting Member
Starting Member
 
Posts: 22
Joined: April 2012

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Postby Robke » Mon May 21, 2012 10:20 pm

I tried some other commands and these are the results:
Code: Select all
/?!<\r><\n> <-- i send the message
/ISK5\2MT372-3102<\r><\n> <-- Reply from ISKRA
<6>000<\r><\n> <-- i send this message (baudrate 300, 9k6 doesn't work ?)
<\r><\n><2>C.1.0(38956577)<\r><\n>0.0.0(38956577)<\r><\n>1.8.0(22530.937*kWh)<\r><\n>1.8.1(12428.800*kWh)<\r><\n>1.8.2(10102.137*kWh)<\r><\n>2.8.0(00000.011*kWh)<\r><\n>2.8.1(00000.004*kWh)<\r><\n>2.8.2(00000.007*kWh)<\r><\n>0.9.1(231354)<\r><\n>0.9.2(120521)<\r><\n>F.97.0(00000000)<\r><\n>! <- reply from ISKRA

That's all :(
Robke
Starting Member
Starting Member
 
Posts: 22
Joined: April 2012

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Postby alias » Tue May 22, 2012 1:23 pm

Hi Robke,

You're (almost) there already!

First of all below a VB.NET translation of the C# code I posted before.
(please note this code is off the top of my head, I do'nt use VB.NET, so I hope it compiles :))

Code: Select all
Dim port As New SerialPort("COM1", 300, Parity.Even, 7, StopBits.One)
port.Open()
port.WriteLine("/?!")   

Dim data As String = port.ReadLine()   ' Read data from the device

Dim manufacturersIdentification As String = data.Substring(1, 3)
Dim baudrateIdentification As String = data.Substring(4, 1)
Dim modeIdentification As String = data.Substring(6, 1)
Dim identification As String = data.Substring(7)

Dim acknowledge As String = ChrW(&H6) + "0" & baudrateIdentification & "0"

port.WriteLine(acknowledge)      ' We acknowledge to the device, still at 300 baud!

Thread.Sleep(200)         ' Wait for 200ms (not needed for a 20ms device)

Dim baudRate As Integer = 300
Select Case baudrateIdentification
   Case "1" : baudRate = 600
   Case "2" : baudRate = 1200
   Case "3" : baudRate = 2400
   Case "4" : baudRate = 4800
   Case "5" : baudRate = 9600
   Case "6" : baudRate = 19200
End Select
port.BaudRate = baudRate      ' Now it’s time to change over the baud rate
                              ' and start reading data

Dim telegram As String = ""

Do While data.IndexOf("!") = -1     ' Our telegram is complete when we encounter the ! char
   data = port.ReadLine()           ' Read a block of data
   telegram = telegram & data       ' Add it to the telegram
Loop

Console.WriteLine(telegram)


But more imortant, your data dump shows your Iskra meter is sending you a telegram with tariff data:
Code: Select all
<\r><\n><2>C.1.0(38956577)<\r><\n>0.0.0(38956577)<\r><\n>1.8.0(22530.937*kWh)<\r><\n>1.8.1(12428.800*kWh)<\r><\n>1.8.2(10102.137*kWh)<\r><\n>2.8.0(00000.011*kWh)<\r><\n>2.8.1(00000.004*kWh)<\r><\n>2.8.2(00000.007*kWh)<\r><\n>0.9.1(231354)<\r><\n>0.9.2(120521)<\r><\n>F.97.0(00000000)<\r><\n>! <- reply from ISKRA

Here's how to interpret OBIS codes in the telegram:

C.1.0(38956577): C.1.0 is the meter identifier (id) as specified by manufacturer = 38956577
0.0.0(38956577): 0.0.0 is the meter identifier (id) as specified by energy supplier = 38956577
0.9.1(231354): 0.9.1 is the timestamp of the reading (in HH:MM:SS) = 23:13:54
0.9.2(120521): 0.9.2 is the date of the reading (in YY-MM-DD) = 2012-05-21 (may 21, 2012, so yesterday)
1.8.0 (22530.937*kWh): 1.8.0 is the sum of electricity delivered to you = 22530.937 kWh (tariff 1 & 2 combined)
1.8.1(12428.800*kWh): 1.8.1 is the amount of electricity delivered to you = 12428.800 kWh (tariff 1, in the Netherlands also called "Nacht- of Laag tarief")
1.8.2(10102.137*kWh): 1.8.2 is the amount of electricity delivered to you = 10102.137 kWh (tariff 2, in the Netherlands also called "Dag- of Hoog tarief")
2.8.0(00000.011*kWh): 2.8.0 is the sum of electricity you delivered back to your energy supplier = 00000.004 kWh (tariff 1 & 2 combined)*
2.8.1(00000.004*kWh): 2.8.1 is the amount of electricity you delivered back to your energy supplier = 00000.004 kWh (tariff 1)*
2.8.2(00000.007*kWh): 2.8.2 is the amount of electricity you delivered back to your energy supplier = 00000.007 kWh (tariff 2)*
* The latter three records (2.8.0, 2.8.1 and 2.8.2) are only applicable when you have an energy-generating system installed (like for example solar panels).
(since the readings of the two records are extremely low, either your energy-generating system isn't functioning or you're not using one.)
F.97.0(00000000): I'm unfamiliar with this OBIS code (if it is one?)

Hope this can be of any help.

Regards
alias
Member
Member
 
Posts: 60
Joined: May 2011
Location: Apeldoorn / Netherlands

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Postby Robke » Tue May 22, 2012 8:50 pm

Thank you again!
But i want more information from my meter how can i get those information? (like the gas usage for example)
Robke
Starting Member
Starting Member
 
Posts: 22
Joined: April 2012

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Postby Robke » Tue May 22, 2012 10:06 pm

I modificate the code here and there and i add the VB.NET code to this topic.
This code only works with the ISKRA meter!

Thank you Ronald!

Code plain:

Code: Select all
Public Class Form1
    Dim telegram As String = ""

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        SerialPort1.BaudRate = 300
        SerialPort1.DataBits = 7
        SerialPort1.StopBits = 1
        SerialPort1.Parity = IO.Ports.Parity.Even
        SerialPort1.PortName = "COM8"
    End Sub


    Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        Dim data As String = SerialPort1.ReadLine()   ' Read data from the device

        If InStr(data, "/?!") > 0 Then
            'do nothing
        Else
            If InStr(data, "ISK") > 0 Then

                Dim manufacturersIdentification As String = data.Substring(1, 3)
                Dim baudrateIdentification As String = data.Substring(4, 1)
                Dim modeIdentification As String = data.Substring(6, 1)
                Dim identification As String = data.Substring(7)

                Dim acknowledge As String = ChrW(&H6) + "0" & baudrateIdentification & "0" & vbCrLf

                SerialPort1.WriteLine(acknowledge) ' We acknowledge to the device, still at 300 baud!

                Threading.Thread.Sleep(200) ' Wait for 200ms (not needed for a 20ms device)

                Dim baudRate As Integer = 300
                Select Case baudrateIdentification
                    Case "1" : baudRate = 600
                    Case "2" : baudRate = 1200
                    Case "3" : baudRate = 2400
                    Case "4" : baudRate = 4800
                    Case "5" : baudRate = 9600
                    Case "6" : baudRate = 19200
                End Select
                SerialPort1.BaudRate = baudRate ' Now it’s time to change over the baud rate
                data = ""
            End If

            If InStr(data, "C.1.") > 0 Then
                Do While data.IndexOf("!") = -1     ' Our telegram is complete when we encounter the ! char
                    data = SerialPort1.ReadLine()           ' Read a block of data
                    telegram = telegram & data       ' Add it to the telegram
                Loop
                Me.BeginInvoke(New MethodInvoker(AddressOf display)) ' Start "Display" on the UI thread
            End If
        End If
    End Sub

    Private Sub display()
        TextBox1.AppendText(telegram)
    End Sub
Attachments
Smart_meter.rar
(66.57 KiB) Downloaded 387 times
Robke
Starting Member
Starting Member
 
Posts: 22
Joined: April 2012

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Postby Robke » Tue May 22, 2012 10:27 pm

Something else strange:
When i'm connected at 9k6 i receive the information from the meter ONCE.
When i send the acknowledge again i don't see any infomation from the meter.
When i disconnect the comport and reconnect the comport i get the information twice (after a init).

And the last question, how can i read the other values like gas :)
Robke
Starting Member
Starting Member
 
Posts: 22
Joined: April 2012

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Postby alias » Tue May 22, 2012 11:02 pm

Hi Robke,

Can you tell me if your gas meter is connected (wired or wireless) to your Iskra electricity meter? And if so, is gas usage data shown on the display of your Iskra electricity meter? If this is the case, the gas usage information is useally found in OBIS records 0-n:24.1.0 to 0-n:24.4.0 of the received telegram (these records reflect connected M-Bus devices). If these records don't show up in the telegram, this might indicate you did not receive the full telegram or your meters aren't connected to each other.

To make shure your code is correct you might want to check out this tool meter-test-equipment.com/download/pdf/e ... 07pack.exe, and check if both application receive the same (complete) telegram from the Iskra meter.

Tool can also be downloaded here files.domoticaforum.eu/Smartmetering/Te ... 07pack.exe

Regards
Last edited by Bwired on Thu May 24, 2012 8:28 am, edited 1 time in total.
Reason: added extra link for tool download
alias
Member
Member
 
Posts: 60
Joined: May 2011
Location: Apeldoorn / Netherlands

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Postby Robke » Wed May 23, 2012 7:10 pm

Hi Ronald,

The gasmeter and energie meter are connected by wire and the Iskra meter shows the gas usage (last month i also received a nota from Essent about the gas usage read by GSM).

When i use that tool (i used it before!) i only see the following information:

==> /?!<0D><0A>
<== /?!
<== --- 0x2F ---
<== --- 0x49 ---
<== --- 0x53 ---
<== --- 0x4B ---
<== --- 0x35 ---
<== --- 0x5C ---
<== --- 0x32 ---
<== --- 0x4D ---
<== --- 0x54 ---
<== --- 0x33 ---
<== --- 0x37 ---
<== --- 0x32 ---
<== --- 0x2D ---
<== --- 0x33 ---
<== --- 0x31 ---
<== --- 0x30 ---
<== --- 0x32 ---
<== --- 0x0D ---
<== --- 0x0A ---
<== -- Tout --

And i see that Tout what i don't understand because i received the other information very well.
Robke
Starting Member
Starting Member
 
Posts: 22
Joined: April 2012

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Postby alias » Wed May 23, 2012 10:23 pm

Hi Robke,

Under normal circumstances the output of the test tool should read something like:
Image

What seems clear is that there is a communications problem between your computer and your metering device. Both your VB code and the third party tool suffer from communication failure; your VB app is receiving incomplete telegrams and the test tool communication times out (TOUT) on the baud rate changeover.
My guess is there is something wrong with either your computer COM port or the connected IR probe. Did you confirm you are using the latest drivers (for the IR probe/COM port)? Or have you already tried adjusting COM port settings, like enabling or disabling FIFO, I/O buffer size etc? Perhaps the IR probe manufacturer has some recommended settings?

Regards
alias
Member
Member
 
Posts: 60
Joined: May 2011
Location: Apeldoorn / Netherlands

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Postby Udo » Fri Jun 22, 2012 11:53 am

alias wrote:My guess is there is something wrong with either your computer COM port or the connected IR probe. Did you confirm you are using the latest drivers (for the IR probe/COM port)? Or have you already tried adjusting COM port settings, like enabling or disabling FIFO, I/O buffer size etc? Perhaps the IR probe manufacturer has some recommended settings?


I don't believe in this. Its a FTDI-chip FT232RL and it works in over hundred other systems.

Robke wrote:When i use that tool (i used it before!) i only see the following information:

==> /?!<0D><0A>
<== /?!
<== --- 0x2F ---
<== --- 0x49 ---
<== --- 0x53 ---
<== --- 0x4B ---
<== --- 0x35 ---
<== --- 0x5C ---
<== --- 0x32 ---
<== --- 0x4D ---
<== --- 0x54 ---
<== --- 0x33 ---
<== --- 0x37 ---
<== --- 0x32 ---
<== --- 0x2D ---
<== --- 0x33 ---
<== --- 0x31 ---
<== --- 0x30 ---
<== --- 0x32 ---
<== --- 0x0D ---
<== --- 0x0A ---
<== -- Tout --


That looks good, because:
==> /?!<0D><0A>
<== /?!
<== --- 0x2F --- = /
<== --- 0x49 --- = I
<== --- 0x53 --- = S
<== --- 0x4B --- = K
<== --- 0x35 --- = 5
<== --- 0x5C --- = \
<== --- 0x32 --- = 2
<== --- 0x4D --- = M
<== --- 0x54 --- = T
<== --- 0x33 --- = 3
<== --- 0x37 --- = 7
<== --- 0x32 --- = 2
<== --- 0x2D --- = -
<== --- 0x33 --- = 3
<== --- 0x31 --- = 1
<== --- 0x30 --- = 0
<== --- 0x32 --- = 2
<== --- 0x0D --- = CR
<== --- 0x0A --- = LF
<== -- Tout -- <----the MeterTest1107 don't work with MT372.

You have to use Hterm or your own script in this way:
==> /?!<\r><\n>
<== /ISK5\2MT372-3102<\r><\n>
==> /?!<\r><\n> and then, without waiting for answer, at once in max.1,5 sec:
==> <6>000<\r><\n> then you receive an answer like this:
<== <2>F.97.0(00000000)<\r><\n>
<== 0.0.0(24000557)<\r><\n>
<== C.1.1(00000000)<\r><\n>
<== C.1.0(24000557)<\r><\n>
<== 0.9.1(175102)<\r><\n>
<== 0.9.2(120619)<\r><\n>
<== 1.8.0(00132.149*kWh)<\r><\n>
<== 1.8.1(00132.149*kWh)<\r><\n>
<== 1.8.2(00000.000*kWh)<\r><\n>
<== 1.8.3(00000.000*kWh)<\r><\n>
<== 1.8.4(00000.000*kWh)<\r><\n>
<== !<\r><\n>
<== <3><9>

so you can put the strings together in Hterm to:
"/?! CR LF NUL NUL NUL NUL NUL NUL ACK 0 0 0 CR LF "(hex 2F 3F 21 0D 0A 00 00 00 00 00 00 00 06 30 30 30 0D 0A)
You can vary the numbers of NUL, depends on your system latency.
If it don't work in ascii, try it in hex in Hterm.

Regards
Udo
Udo
Starting Member
Starting Member
 
Posts: 11
Joined: May 2012

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Postby Robke » Sun Jun 24, 2012 7:31 pm

Hi Udo,

Thank you for your reply, this week the electric company let me know that i have an old meter.
So i can't read the gas usage :(
Anyway my cable / software works perfect right now!
Thanks for all the support!

Robke
Robke
Starting Member
Starting Member
 
Posts: 22
Joined: April 2012

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Postby hgestel » Fri Dec 14, 2012 3:30 pm

Hai Robke,

Do you have the C++ program smart meter?

Is it possible to share it?

Henry
hgestel
Starting Member
Starting Member
 
Posts: 1
Joined: December 2012

Next

Return to Smart Metering Forum

Who is online

Users browsing this forum: No registered users and 1 guest