Skip to main content
1-Visitor
January 10, 2020
Solved

Using the C SDK to read String Properties from thingworx

  • January 10, 2020
  • 5 replies
  • 1952 views

Hi everyone,

 

I am trying to use the C SDK to get the thingname from the Generic thing property. The problem I am having is that my C SDK application connects using an identifier so I can bind it to different things on thingworx so that I do not have to re-build my program. I want to use the Thingname that my application has binded to in my code.

 

When I use the TW_GET_STRING_PROPERTY like this it returns null.

printf("The Name of the thing is%s\n", TW_GET_STRING_PROPERTY(thingName,"name"));

csdkerr.PNG

 

csdkerr2.PNG

 

Can anyone please give advice on how I can get the thingName that my application is bound to thanks.

Best answer by smainente

Maybe try the following API instead :

twPrimitive* p_prim;
twApi_ReadProperty(TW_THING, thingName, "name", &p_prim, DEFAULT_MESSAGE_TIMEOUT, FALSE);
TW_LOG(TW_WARN, "************* %s name %s", thingName, p_prim->val.bytes.data);

It is working on my side when using an ID for thingname.

Note that you can use this API after a successful twApi_Connect().

5 replies

raluca_edu
17-Peridot
January 13, 2020

Hi,

 

Have you tried to use TW_GET_PROPERTY(thingName, "name").string  ?

 

Please let me know what value you get with TW_GET_PROPERTY.

 

Thanks,

Raluca Edu

Yaku1-VisitorAuthor
1-Visitor
January 13, 2020

Hi @raluca_edu ,

 

When I try using TW_GET_PROPERTY(thingName, "name").string my application does not compile and returns this error.

 

error: 'union <anonymous>' has no member named 'string'
printf("The Name of the thing is%s\n",TW_GET_PROPERTY(thingName, "name").string);

raluca_edu
17-Peridot
January 13, 2020

Try char, not string

smainente16-PearlAnswer
16-Pearl
January 13, 2020

Maybe try the following API instead :

twPrimitive* p_prim;
twApi_ReadProperty(TW_THING, thingName, "name", &p_prim, DEFAULT_MESSAGE_TIMEOUT, FALSE);
TW_LOG(TW_WARN, "************* %s name %s", thingName, p_prim->val.bytes.data);

It is working on my side when using an ID for thingname.

Note that you can use this API after a successful twApi_Connect().

Yaku1-VisitorAuthor
1-Visitor
January 14, 2020

Hi @smainente,

 

Thank you for your assistance this worked.