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.
Solved! Go to Solution.
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
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
Hi Nelson,
Is your issue resolved? Please mark correct answer or Helpful for the answer if that helps you.
Thanks,
Br,
Anna
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);
}
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?
Hi nquirindongo,
There is an article on our support website to introduce the difference between InfoTable and DataTable:
https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS224499&lang=en_US
I pasted it here in case you have no access to the support webside:
It is quite easy to add data entries into a DataTable(Remember DataTable has primary key like what we have in database table).
You could use like this:
var values = Things["DT1"].CreateValues();//DT1 is an entity with Thing Template of DataTable
values.parentname = undefined; // you could add any of your data field; parentName, name ,id is just my example
values.name = undefined; //STRING
values.id = undefined; //INTEGER [Primary Key]
var params = {
sourceType: undefined /* STRING */,
values: values /* INFOTABLE*/,
location: undefined /* LOCATION */,
source: undefined /* STRING */,
tags: undefined /* TAGS */
};
// result: STRING
var id = Things["DT1"].AddDataTableEntry(params);
Please let me know if you have any more questions.
Thanks,
Br,
Anna
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?
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.
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
No... I'm still with ThingWorx 7.1 and KEPServer EX 6.0
In the process to upgrade both.
Hi nquirindongo,
Glad to know you are trying to upgrade both.
Please keep me updated or let me know if any issue you may have.
Thank you,
Br,
Anna
Dear quirindongo,
How about your issue? Is it resolved or still have any issue? Please let us know of your progress.
Thanks,
Br,
Anna
Hi Anna,
We put that effort on hold until thingworx 8.0 is release. In the meantime I have been playing around with the other capabilities of thingworx 7
I'll keep you posted.
Regards,
Nelson Q