Skip to main content
1-Visitor
June 25, 2015
Solved

How to start a service from C SDK?

  • June 25, 2015
  • 1 reply
  • 1736 views

Hi,

I would like to call a service of my thing on Thingworx from my C program created with the model C SDK. I already tried to use the function "twApi_InvokeService" but it doesn't work. If someone can give me more explanations about this function.

I am using Thingworx 6.0.1 and the C SDK

Regards,

Anthony

    Best answer by christianb1

    Have you checked the debug output of the c application?

    Here is a simple example how to call a SteamSensors service named "CountDataCollectionTasks"

    ...

    // in void dataCollectionTask of SteamSensor example

    int res = 0;

    twInfoTable * values = NULL;

    twInfoTable * result = NULL;

    values = twInfoTable_Create(twDataShape_Create(twDataShapeEntry_Create("values", NULL, TW_INFOTABLE)));

    res = twApi_InvokeService(TW_THING, thingName, "CountDataCollectionTasks", values, &result, -1, FALSE);

    TW_LOG(TW_INFO, "invokeService: %d", res);

    // we are responsible to clean the result

    twInfoTable_Delete(values);

    twInfoTable_Delete(result);

    ...

    in api/twApi.c is an example how the twApi_PushProperties invokes the "UpdateSubscribedPropertyValues" service of the thing.

    Do not forget to create the service in TWX at your Thing.

    1 reply

    1-Visitor
    June 25, 2015

    Have you checked the debug output of the c application?

    Here is a simple example how to call a SteamSensors service named "CountDataCollectionTasks"

    ...

    // in void dataCollectionTask of SteamSensor example

    int res = 0;

    twInfoTable * values = NULL;

    twInfoTable * result = NULL;

    values = twInfoTable_Create(twDataShape_Create(twDataShapeEntry_Create("values", NULL, TW_INFOTABLE)));

    res = twApi_InvokeService(TW_THING, thingName, "CountDataCollectionTasks", values, &result, -1, FALSE);

    TW_LOG(TW_INFO, "invokeService: %d", res);

    // we are responsible to clean the result

    twInfoTable_Delete(values);

    twInfoTable_Delete(result);

    ...

    in api/twApi.c is an example how the twApi_PushProperties invokes the "UpdateSubscribedPropertyValues" service of the thing.

    Do not forget to create the service in TWX at your Thing.

    anthony11-VisitorAuthor
    1-Visitor
    June 26, 2015

    Thank you, it works fine now .