Skip to main content
Home
for DLMS smart meters

Main navigation

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

Breadcrumb

  1. Home
  2. Wrong Result On Second Call Bb_compare()

Wrong result on second call bb_compare()

Profile picture for user Dmitry
By Dmitry, 7 November, 2024
Forums
Gurux.DLMS

Hi, Mikko!

I try compare two buffers twice.

unsigned char vnd[] = "VND";
gxData vndr; // here byteArr "VND"

unsigned char c = bb_compare(vndr.value.byteArr, vnd, 3); //OK, c==1
c = bb_compare(vndr.value.byteArr, vnd, 3); //Fail, c == 0

This is because if the buffers are equal, position of vndr.byteArr changes to length of comparing.

How to compare buffers multiple times?

Thanks!

Profile picture for user Kurumi

Kurumi

6 months 1 week ago

Hi, If compare succeeds, the…

Hi,

If compare succeeds, the bb_compare increases the byte array position with the length of compared str;

Try this:

unsigned char c = bb_compare(vndr.value.byteArr, vnd, 3); //OK, c==1
if (c)
{
vndr.value.byteArr-position -= 3;
}
c = bb_compare(vndr.value.byteArr, vnd, 3);

BR,
Mikko

Profile picture for user Dmitry

Dmitry

6 months 1 week ago

Thanks for you reply. It's…

Thanks for you reply.

It's work.

But i think comparing should not change internal state of buffers.

Also i try this:
if(vndr.value.vt == DLMS_DATA_TYPE_OCTET_STRING)
{
bool res = (memcmp(vndr.value.byteArr->data, vnd, sizeof(vnd)-1) == 0);
}

Profile picture for user Kurumi

Kurumi

6 months 1 week ago

Hi, It's designed this way…

Hi,

It's designed this way and used in many projects, so it can't be changed.

BR,
Mikko

  • Log in or register to post comments
  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Wed, 05/14/2025 - 08:30
    gurux.dlms.c 9.0.2505.1401
  • Tue, 05/13/2025 - 10:00
    Gurux.DLMS.Android 2.0.15
  • Fri, 05/09/2025 - 13:03
    Gurux.DLMS.Python 1.0.181
  • Wed, 05/07/2025 - 16:09
    Gurux.DLMS.Android 2.0.14
  • Tue, 05/06/2025 - 09:34
    gurux.dlms.c 9.0.2505.0601

New forum topics

  • How to create an DLMS Simulator with HighGMac authentication
  • Actaris Itron - SL7000 761 - "disconnected mode" problem
  • gxaes.c can be compiled in current version under Linux
  • how to limit frame size on client side?
  • MBUS Diagnostic
More
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin