cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Using the C SDK to read String Properties from thingworx

Yaku
6-Contributor

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.

1 ACCEPTED SOLUTION

Accepted Solutions
smainente
16-Pearl
(To:Yaku)

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

View solution in original post

5 REPLIES 5
raluca_edu
17-Peridot
(To:Yaku)

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

Yaku
6-Contributor
(To:raluca_edu)

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
(To:Yaku)

Try char, not string

smainente
16-Pearl
(To:Yaku)

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

Yaku
6-Contributor
(To:smainente)

Hi @smainente,

 

Thank you for your assistance this worked.

Top Tags