Delphi / Reading meter programmatically

10 posts / 0 new
Last post
leray
Delphi / Reading meter programmatically

Hello,

I'm writing a small program to read data from my ACE6000 meter programmatically using Delphi and Active X components.

I am able to connect to meter and send SNRM request(taken from GXDLSMDirector log file) and receive UA frame from the meter (exactly the same as in GXDLSMDirector log)

But if I generate SNRM request on my own - it differs from the original and no reply from meter received.

The problem seems to be in wrong ClientId/ServerId values in cosem component.

How should I specify client id and server id? In what format?

Client id: 1
Physical address: 11
Logical address: 1

Maybe there is a function that would do the dirty job and calculate the resulting server id from lower and upper addresses?

leray
Server id

Took me a while to understand how to set a server id

Following the explanations at http://www.gurux.fi/index.php?q=node/336

I got:
Logical address= 1(0001) -> 0010 -> hex:02
Physical address= 17 (10001) -> 100011 -> hex:23

so the results ServerID should look like logical,physical addresses, but with extra nulls, like 02 = 0002, 23= 0023

in my case, I set it in delphi as hex :=$00020023 and this seems to be ok

leray
frame length

Moving forward and still some troubles with frame length

Frame from GxDLMSDirector log is shorter than the one created with cosem.SNRMRequest()

Valid frame:
7E A00A 0002 0023 03 93 9B61 7E
40970

Mine:
7E A00D 0002 0023 00 00 00 03 93 DF84 7E
40973

I was not able to find and properties where to set frame size, so where do these nulls come from?

My configuration:

gxnet.HostName:=Xxxxxx;
gxnet.HostPort:=xxx;
gxnet.Protocol:=GX_NW_TCPIP;
gxnet.OnReceived:=GxNetOnReceived;

gxcosem.Authentication:= GXDLMS_AUTHENTICATION_LOW;
gxcosem.Password:=xxxxxx;
gxcosem.ClientID:=$03;
gxcosem.ServerID:=$00020023;
gxcosem.UseLogicalNameReferencing:=true;

gxcosem.ManufacturerType:=GXDLMS_MANUFACTURETYPE_GENERAL;

and SNRM: 7E A00D 0002 0023 00 00 00 03 93 DF84 7E

Any suggestions why it differs from original?

kurumi
kurumi's picture
Delphi / Reading meter programmatically

Hi,

You should cast Client ID as byte value or give it as byte, not as integer.

Something like this:
var
id : Integer;

begin
id = $03;
gxcosem.ClientID := id;
end;

It has been while since I last programmed with Delphi,
but idea is like this. :-)

BR,

Mikko

________________________________________
Mikko Kurunsaari
Gurux Ltd
Hermiankatu 6-8 H 33720 TAMPERE, FINLAND
Phone: +358 3 265 1244
Home page: http://www.gurux.org

leray
no success

no success in getting it to work

I can define client_id as byte, but this does not solve the problem.
Also tried with variant type for byte values, but still nothing

var
//client_id:byte;
//client_id:Variant;
begin
//client_id=03;
//client_id:=byte($03);
//client_id:=$03;

//system.VarCast(client_id,$03,varByte);
//gxcosem.ClientID:=byte(gxcosem.ChangeType($03,DLMS_DATA_TYPE_Int8));
gxcosem.ClientID:=client_id;
end;

it adds extra nulls in all cases '00 00 00 03'

kurumi
kurumi's picture
Delphi / Reading meter programmatically

Hi,

It seems that for some reason Delphi is handling Byte as 32 bit unsigned integer, not 8 bit unsigned integer.

We are trying to find a fix for this.

BR,

Mikko

________________________________________
Mikko Kurunsaari
Gurux Ltd
Hermiankatu 6-8 H 33720 TAMPERE, FINLAND
Phone: +358 3 265 1244
Home page: http://www.gurux.org

JosteinO
access from python

I am using python and have faced the same problem as you described.

My code:

# -*- coding: utf-8 -*-
import win32com.client

cosem=win32com.client.Dispatch('GuruxDLMS2.GXCOSEM.1')
cosem.ServerID=0x01
cosem.ClientID=0x10
r=cosem.SNRMRequest()

this gives the result:
7E A0 0D 00 00 00 01 00 00 00 10 93 7F BD 7E

the same Request in GXDLMSDirector:
7E A0 07 01 21 93 B7 B4 7E

Jostein

kurumi
kurumi's picture
access from Python and Delphi

Hi,

Because Delphi and Python are handling byte as integer we have added SetServerID and SetClientID methods to Gurux DLMS component. Using those methods you can set
correct Client and Server IDs.

We will add this functionality to ActiveX component later so you must use C# component. You can download C# source codes from SourceForge.net.
gurux.svn.sourceforge.net/svnroot/gurux/GXCom/Protocols/Gurux.DLMS

and combiled version here: http://www.gurux.fi/Downloads/Gurux.DLMS.zip

Here is Python example made with IronPython.

import clr
clr.AddReferenceToFile("Gurux.DLMS.dll")
from Gurux.DLMS import GXDLMSClient
cl = GXDLMSClient()
cl.SetServerID(0x01, 1)
cl.SetClientID(0x10, 1)
r=cosem.SNRMRequest()

BR,

Mikko

________________________________________
Mikko Kurunsaari
Gurux Ltd
Hermiankatu 6-8 H 33720 TAMPERE, FINLAND
Phone: +358 3 265 1244
Home page: http://www.gurux.org

JosteinO
access from Python and Delphi

Thanks for Your prompt response.
I have not been using IronPython heavily before,
but I think this is the time for it.
Hopefully I can give som progress reports later, If there are anybody interesting in
building DLMS interface in Python, please let me know

kind regards

Jostein

kurumi
kurumi's picture
access from Python and Delphi

Hi,

I think that you can use other Python interpreters as well.
There was no spesific reason why we used IronPython.

Happy Coding. :-)

BR,

Mikko

________________________________________
Mikko Kurunsaari
Gurux Ltd
Hermiankatu 6-8 H 33720 TAMPERE, FINLAND
Phone: +358 3 265 1244
Home page: http://www.gurux.org