Skip to main content
11-Garnet
March 16, 2017
Solved

Get tags from Kepware -> add them to a thing in Thingworx

  • March 16, 2017
  • 3 replies
  • 8647 views

Hi all,

 

I just started using thinkworx and I'm trying to pull all the tags from Kepware to a thing in Thingworx (add it to a thing's properties). How I can do it using Javascript? I'm still learning what are the capabilities of the Thingworx Composer and its API. BTW I have the RemoteKEPServerEXThing installed.

Best answer by AnnaAn

Hi nquirindongo,

Are you using ThingWorx 7.4 and connect directly with Kepware? If so it's much easier to connect kepware to ThingWorx and you will find it very easy to bind Tags(In Thingworx 7.4, you could discover the tag directly from new-generation composer), and you do not need to bind it with Browse Items or AddItems. Here is how to connect Kepware to ThingWorx in Help Center. Keep in mind ThingWorx 7.4 or higher is needed, and KEPServerEX 6.1 or higher is needed.

Let me know if this could give you any hint or any questions.

Thanks,

Br,

Anna

3 replies

14-Alexandrite
April 7, 2017

Dear Nelson,

I believe the thing You've created RemoteKEPServerEXThing is based on Thing Template IndustrialGateway correct?

If everything are configured properly according to our Help Center guide on How to Connect Kepware to ThingWorx, then you could create a new service on the thing you created:

 

var params = {

 

                filter: undefined /* STRING */,

 

                path: "Simulation Examples.Functions" /* STRING */

 

};

 

 

// result: INFOTABLE dataShape: "IndustrialItems"

 

var items = me.BrowseItems(params);

 

logger.warn(items.length);

 

var tableLength = items.rows.length;

 

for (var x = 0; x < tableLength; x++) {

 

                var row = items.rows;

 

                logger.warn(row.Name);

 

    logger.warn(row.BaseType);

 

   

 

var params = {

 

                defaultValue: undefined /* STRING */,

 

                description: undefined /* STRING */,

 

                readOnly: undefined /* BOOLEAN */,

 

                type: row.BaseType /* BASETYPENAME */,

 

                remote: undefined /* BOOLEAN */,

 

                remotePropertyName: row.Name /* STRING */,

 

                timeout: undefined /* INTEGER */,

 

                pushType: undefined /* STRING */,

 

                dataChangeThreshold: undefined /* NUMBER */,

 

                logged: undefined /* BOOLEAN */,

 

                name: row.Name /* STRING */,

 

                pushThreshold: undefined /* NUMBER */,

 

                dataChangeType: undefined /* STRING */,

 

                category: undefined /* STRING */,

 

                persistent: undefined /* BOOLEAN */,

 

                dataShape: undefined /* DATASHAPENAME */

 

};

me.AddPropertyDefinition(params);

}

 

And here you could pass a parameter to the path: "Simulation Examples.Functions" instead using a static one in my example.

Btw, I keep other setting as undefined so you could give it definite value if you have special requirement for these settings.

please let me know if it works for you.

Thanks,

Br,

Anna

14-Alexandrite
April 11, 2017

Hi Nelson,

Is your issue resolved? Please mark correct answer or Helpful for the answer if that helps you.

Thanks,

Br,

Anna

11-Garnet
April 11, 2017

Anna,

Sorry for my delayed response and thanks for replying to my question.

Your response was my first approach but running a "for loop" was not ideal. So, while I was learning how to use the tool I was able to write a service to browse groups from Kepware, get the items I want based on a filter expression and add them as properties.

3 inputs: add (boolean), path (string), filter (string)

1 output: result (infotable)

// code start here

var add = add;

var inPathWithFilter = {
    filter: filter /* STRING */,
    path: path /* STRING */,
};

var result = me.BrowseGroups(inPathWithFilter);

if(result.getRowCount() < 1) {  // function isEmpty() is not working for me
    result = me.BrowseItems(inPathWithFilter);
}

if(add == true) {
    //add additional fields to match the addItems infotable
    var LoggedField= new Object();
    LoggedField.name = "Logged";
    LoggedField.baseType = 'BOOLEAN';
    result.AddField(LoggedField);

 

    var ScanRateMSField = new Object();
    ScanRateMSField.name = "ScanRateMS";
    ScanRateMSField.baseType = 'NUMBER';
    result.AddField(ScanRateMSField);

 

    var PersistentField= new Object();
    PersistentField.name = "Persistent";
    PersistentField.baseType = 'BOOLEAN';
    result.AddField(PersistentField);

 

    var whichTags = {
        items: result /* INFOTABLE */
    };
   
    result = me.AddItems(whichTags);
}

11-Garnet
April 11, 2017

I would like to do the same using data tables. How I can store the end results in a data table instead of an infotable.

BTW... Do you know what are the main difference between a datatable and infotable?

1-Visitor
April 12, 2017

Why do you need to connect using javascript? if you can connect the kepware tags to proprties of things directly. you are aware of it right?

11-Garnet
April 12, 2017

What do you mean? Manually? If so, will not work for me.

I'm looking for a solution where I can have a mash up or dashboard where I can select/deselect the channels from the kepserver.

AnnaAn14-AlexandriteAnswer
14-Alexandrite
April 13, 2017

Hi nquirindongo,

Are you using ThingWorx 7.4 and connect directly with Kepware? If so it's much easier to connect kepware to ThingWorx and you will find it very easy to bind Tags(In Thingworx 7.4, you could discover the tag directly from new-generation composer), and you do not need to bind it with Browse Items or AddItems. Here is how to connect Kepware to ThingWorx in Help Center. Keep in mind ThingWorx 7.4 or higher is needed, and KEPServerEX 6.1 or higher is needed.

Let me know if this could give you any hint or any questions.

Thanks,

Br,

Anna