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

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

New BaseType Function and workaround solutions

bbeuckSIG
15-Moonstone

New BaseType Function and workaround solutions

Dear Community,


I am building a Template for Things to periodically read and buffer data. In my configuration I maintain a list of properties to read on every timer event, it basically looks like this

Id Property
1 Status
2 Speed
...  

 

Unfortunately only the property alone is not enough information, I may have more complex access patterns (e. g. reading from an InfoTable), conversions, checks, etc. Hence my idea is to provide the function code along with the property in the configuration, like this

Id Property Access function
1 Status function f() {return me.Status;}
2 Speed function f() {return Math.abs(me.Speed);}
...    

 

Using Thingworx 8.4.4 I have not found a datatype to hold the function code. Any chance we would get something like that one day? Or is it even available in later Releases?

 

I can think of two possible workarounds.
1. Store the code as string and run with eval.
I am not going to do that because one should never use eval. Additionally I am not sure about performance if the functions have to be parsed every time.

 

2a. Put the code in a separate Service and put the Service name into the configuration.
2b. Put all code in one Service and use switch command based on the property name.
I am working on this at the moment, probably I will prefer 2b. On the downside I am losing the desired flexibility because all access functions have to be available as code on my Template. It is not possible to dynamically extend my configuration without adding code to my Template.

 

Would be happy to get some thoughts.

 

Thank you
Benny

4 REPLIES 4
slangley
23-Emerald II
(To:bbeuckSIG)

Hi @bbeuckSIG 

 

Infotables weren't really meant to be used in the way you describe, and there may be a number of reasons for this including security related implications.  If you are interested in submitting this as a request, please feel free to post it on the ThingWorx Ideas page.

 

Regards.

 

--Sharon

bbeuckSIG
15-Moonstone
(To:slangley)

Hello @slangley ,

 

thanks for your reply.

 

I am also interested in other/better workarounds than what I suggested.

 

Thank you

Benny

Hi @bbeuckSIG ,

One potential way to look at this is the following: looking at the example functions there is it possible to create additional properties that are really what you aim to obtain (like for example speedAbs and so on). I mean if those accessors are really important ones that really require a function, maybe it's better to "propertize" them, and populate them via the Data Change?

Another idea is this: whatever you need to do still implies code will be modified somewhere (infotable in your desired case, or service/subscription in the current behavior). If this is correct, then what is the advantage of storing it in infotable?

 

Thx!

Hi @VladimirRosu ,

 

thanks for your valuable feedback.

 

I agree, creating additional properties on the source is another option. But in my opinion not optimal for my particular case as it requires the additional properties on the data source. I would lose my idea to be dynamic.

 

In an optimal world I would like to have an unmodified data source (no additional properties, services, etc.) as well as an unspecific template/thing to access and buffer the data. Unspecific means my template/thing needs zero knowledge about the data source, it only defines the organization like scheduling, buffer management, etc. The logic to access an arbitrary data source is then to be defined in the configuration (which I do not consider as code).

 

Thank you
Benny

Top Tags