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. Got OctetString - How To Convert Data To C String or Std::string?

Got OctetString - how to convert data to C string or std::string?

By latonita, 18 September, 2024
Forums
Gurux.DLMS

Hi.
I'm getting data from the meter, it is the manufacturer name.

7E.A0.22.41.03.74.F7.D0.E6.E7.00.C4.01.C1.00.09.10.45.6E.65.72.67.6F.6D.65.72.61.00.00.00.00.00.00.19.92.7E

So it has OctetString
<Data>
<OctetString Value="456E6572676F6D657261000000000000" />
</Data>

This is a hex view of a string "Energomera".

I used cl_updateValue(), then I did var_toString() and what I got is same hex string but separated by spaces.

So I had to do stupid thing and manually convert hex view to null terminated C string

I believe there is a proper way to get proper bytes out of this hex-octet-string.
How do I properly get this octet string converted to bytes?

Thank you.

Profile picture for user Kurumi

Kurumi

9 months ago

HI, The easiest way to show…

HI,

The easiest way to show this as a string is cast it to the char*.

dlmsVARIANT* value = //Get Value.
//Add '\0'
bb_setInt8(value->byteArr, 0);
const char* str = value->byteArr->data;
//Remove '\0'
--value->byteArr->size

BR,
Mikko

latonita

8 months 4 weeks ago

Thank you! This works…

Thank you! This works perfect. I didn't notice there is raw-bytes array available.

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

Hire Us!

Latest Releases

  • Thu, 06/19/2025 - 09:33
    Gurux.DLMS.Python 1.0.185
  • Wed, 06/18/2025 - 15:11
    Gurux.DLMS.Python 1.0.184
  • Wed, 06/18/2025 - 10:05
    Gurux.DLMS.Python 1.0.183
  • Wed, 06/18/2025 - 09:06
    GXDLMSDirector 9.0.2506.1801
  • Wed, 06/18/2025 - 08:41
    Gurux.DLMS.Net 9.0.2506.1801

New forum topics

  • Unable to read parameter values from Landis+Gyr E550 meter using GXDLMSDirector - NoAccess status
  • data.SetComplete(false); But all data recieved
  • Crash (endless loop)
  • Server is not able to download object list with maxPduSize 64 or 128 (or anything below 156-bytes PDU size)
  • Day profile action item add error (String is not recognized as valid DateTime value)
More
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin