Skip to main content
Home
for DLMS smart meters
Open source solutions for DLMS smart metering

Main navigation

  • Home
  • Products
  • About us
  • Open Source
  • Community
  • Forum
  • Downloads
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Forums
  3. Error In GXDLMSTokenGateway When Executing Action Enter(data)

Error in GXDLMSTokenGateway when executing action enter(data)

Forum Rules

Before commenting read Forum rules

Don't comment the topic if you have a new question.

You can create a new topic selecting correct category from Gurux Forum and then create a new topic selecting "New Topic" from the top left.

By Rubent , 20 May, 2022
Forums
Gurux.DLMS

Good morning!

First of all, thank you in advance for any reply. I have developed a device simulator using Gurux as a server.

I'm trying to execute the action defined in the bluebook as enter(data)

protected override void PreAction(ValueEventArgs[] args)
{
foreach (var valueEventArg in args)
{
Logger.Information("{Method} {Target}:{LogicalName}", nameof(PreAction), valueEventArg.Target.GetType(),
valueEventArg.Target.LogicalName);
_companionServer.CompanionPreAction(valueEventArg, this);
}
}

------------------------------------------------------------------

public void CompanionPreAction(ValueEventArgs preActionArgs, DlmsServer dlmsServer)
{
switch (preActionArgs.Target)
{
case GXDLMSImageTransfer _:
HandleImageTransferActions(preActionArgs);
break;
case GXDLMSSecuritySetup _:
HandleSecuritySetupActions(preActionArgs);
break;
case GXDLMSClock _:
HandleClockRelativeTimeSetActions(preActionArgs);
break;
case GXDLMSDisconnectControl _:
HandleDisconnectControlActions(preActionArgs, dlmsServer);
break;
case GXDLMSTokenGateway _:
HandleTokenGatewayActions(preActionArgs);
break;
}
}

------------------------------------------------------------------

When it arrives to the server I try to assign the value of the structure in the response and I get no result.

1. If I just assign the value to the token it returns success but no data.

protected void HandleTokenGatewayActions(ValueEventArgs preActionArgs)
{
if (!(preActionArgs.Target is GXDLMSTokenGateway gxdlmsTokenGateway)) return;

switch (preActionArgs.Index)
{
case 1:
{
gxdlmsTokenGateway.Token = (byte[])preActionArgs.Parameters;

preActionArgs.Handled = true;

break;
}
}
}

-------------------------------------------------------------------

Request: C301C100730000132800FF0101090AAAAAAAAAAAAAAAAAAAAA

Response: C701C10000

<ActionResponse>
<ActionResponseNormal>
<!--Priority: HIGH ServiceClass: CONFIRMED invokeID: 1-->
<InvokeIdAndPriority Value="C1" />
<Result Value="Success" />
</ActionResponseNormal>
</ActionResponse>

2. If I try to assign the value of the attribute with the GetValues I get a ReadWriteDenied error.

protected virtual void HandleTokenGatewayActions(ValueEventArgs preActionArgs)
{
if (!(preActionArgs.Target is GXDLMSTokenGateway gxdlmsTokenGateway)) return;

switch (preActionArgs.Index)
{
case 1:
{
gxdlmsTokenGateway.Token = (byte[])preActionArgs.Parameters;
gxdlmsTokenGateway.StatusCode = TokenStatusCode.TokenExecutionOk;
gxdlmsTokenGateway.DataValue = Convert.ToString((byte)(101));

preActionArgs.Value = gxdlmsTokenGateway.GetValues()[5];

preActionArgs.Handled = true;

break;
}
}
}

Request: C301C100730000132800FF0101090AAAAAAAAAAAAAAAAAAAAA
Response: C701C10300

<ActionResponse>
<ActionResponseNormal>
<!--Priority: HIGH ServiceClass: CONFIRMED invokeID: 1-->
<InvokeIdAndPriority Value="C1" />
<Result Value="ReadWriteDenied" />
</ActionResponseNormal>
</ActionResponse>

3. If I try to assign a structure it also gives an error ReadWriteDenied

protected virtual void HandleTokenGatewayActions(ValueEventArgs preActionArgs)
{
if (!(preActionArgs.Target is GXDLMSTokenGateway gxdlmsTokenGateway)) return;

switch (preActionArgs.Index)
{
case 1:
{
gxdlmsTokenGateway.Token = (byte[])preActionArgs.Parameters;
gxdlmsTokenGateway.StatusCode = TokenStatusCode.TokenExecutionOk;
gxdlmsTokenGateway.DataValue = Convert.ToString((byte)(101));

var structure = new GXStructure
{
(byte)gxdlmsTokenGateway.StatusCode,
gxdlmsTokenGateway.DataValue
};

preActionArgs.Value = structure;

preActionArgs.Handled = true;

break;
}
}
}

-----------------------------------------------------------------

Request: C301C100730000132800FF0101090AAAAAAAAAAAAAAAAAAAAA
Response: C701C10300

<ActionResponse>
<ActionResponseNormal>
<!--Priority: HIGH ServiceClass: CONFIRMED invokeID: 1-->
<InvokeIdAndPriority Value="C1" />
<Result Value="ReadWriteDenied" />
</ActionResponseNormal>
</ActionResponse>

4. On the other hand, if I assign a string it returns an OctetString, but of course this is not what the client system expects.

protected virtual void HandleTokenGatewayActions(ValueEventArgs preActionArgs)
{
if (!(preActionArgs.Target is GXDLMSTokenGateway gxdlmsTokenGateway)) return;

switch (preActionArgs.Index)
{
case 1:
{
gxdlmsTokenGateway.Token = (byte[])preActionArgs.Parameters;
gxdlmsTokenGateway.StatusCode = TokenStatusCode.TokenExecutionOk;
gxdlmsTokenGateway.DataValue = Convert.ToString((byte)(101));

var buff = new GXByteBuffer();
buff.SetUInt8((byte)DataType.Structure);
buff.SetUInt8((byte)2);
SetData(new GXDLMSSettings(), buff, DataType.Enum, (object)gxdlmsTokenGateway.StatusCode);
SetData(new GXDLMSSettings(), buff, DataType.BitString, (object)gxdlmsTokenGateway.DataValue);
var result = (object)buff.Array();

preActionArgs.Value = result;

preActionArgs.Handled = true;

break;
}
}
}

-----------------------------------------------------------------------

request: C301C100730000132800FF0101090AAAAAAAAAAAAAAAAAAAAA
response: C701C10001000907020216030403A0

<ActionResponse>
<ActionResponseNormal>
<!--Priority: HIGH ServiceClass: CONFIRMED invokeID: 1-->
<InvokeIdAndPriority Value="C1" />
<Result Value="Success" />
<ReturnParameters>
<Data>
<OctetString Value="020216030403A0" />
</Data>
</ReturnParameters>
</ActionResponseNormal>
</ActionResponse>

Can someone help me? I am desperate. Thanks again for your trouble.

Rubent

Profile picture for user Kurumi

Kurumi

4 years 2 months ago

Hi,

Hi,

#1.
if you set Handled = true then you need to return the value in preActionArgs.Value. Because there is no data, the reply is empty.

#2. and #3.
Is HandleTokenGatewayActions invoked or is error returned before? Are there any exceptions thrown?

BR,
Mikko

  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Mon, 07/27/2026 - 12:37
    gurux.dlms.cpp 9.0.2607.2701
  • Thu, 07/23/2026 - 16:19
    gurux.dlms.java 4.0.96
  • Thu, 07/09/2026 - 14:34
    Gurux.DLMS.Python 1.0.201
  • Fri, 06/26/2026 - 16:32
    Gurux.Service 3.0.2606.2601
  • Wed, 06/24/2026 - 08:36
    Gurux.DLMS.Python 1.0.200

New forum topics

  • Service not known error on gprs communication
  • Help Needed: Interfacing Saral 100 Energy Meter with Microcontroller via RS232
  • Connecting Meter to Agent via serial
  • Reading block profile with Compact array
  • DLMS server - serving multiple similar datasets gathered from multiple meters across distinct logical addresses
More

Who's new

  • cWYHszETmudslY…
  • Aij
  • vondamc1
  • JosephNok
  • IUJbutxeSTSNcNRN
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin