Skip to main content
Jan 10, 2020 9:56 AM UTC
Solved

Using the C SDK to read String Properties from thingworx

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.

smainenteAnswer
Jan 13, 2020 4:11 PM UTC

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

Jan 13, 2020 1:51 PM UTC

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

YakuAuthor
Jan 13, 2020 2:03 PM UTC

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);

Jan 13, 2020 3:15 PM UTC

Try char, not string

smainenteAnswer
Jan 13, 2020 4:11 PM UTC

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().

YakuAuthor
Jan 14, 2020 10:45 AM UTC

Hi @smainente,

 

Thank you for your assistance this worked.