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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

How do I get a ValueStream to record only changes in the state of one property but also record concurrent property values?

asinclair
1-Newbie

How do I get a ValueStream to record only changes in the state of one property but also record concurrent property values?

My device collects state information - a single property value - and sends the collected data in bulk to the server when a connection is available. Each record has start time and end time and the state value that held during that period. When a state change occurs the device generates two records - one that indicates the when the previous state ended and one that indicates when the next state began. What I want is every time the state value changes from A to B I want all three values logged to the ValueStream.


In Thingworx, then, I have an entity that is bound to the device, The entity has 3 properties: LastOEEStartTime, LastOEEEndTime and OEEState all marked IsLogged:true. I defined OEEState with aspect DataChange Value and the other two with DataChange:Never. I thought this would do it.

The results of QueryPropertyHistory show that I am getting a record in the Value stream for every record the device is sending. Why is that?

It seems that I am getting a new entry in the value stream every time the OEEState property is written to whether the value has changed or not. Is this what I should expect?

1 ACCEPTED SOLUTION

Accepted Solutions
PaiChung
22-Sapphire I
(To:asinclair)

Hi Andy, just use a Subscription on DataChange for the OEEState and use a regular stream vs. ValueStream

the data you get from the DataChange event is the new and old value, timestamp and quality.

You can use that to use your determination and log the information you want.

View solution in original post

7 REPLIES 7

Hi Andy,

This result is correct, because you have marked all three properties as Logged. If you just want to display the OEEState, then go to the other two properties and uncheck the Logged checkbox. The timestamp is add to the query of the value stream by default.

If you still want to record your start and end time for each state to the ValueStream, but return a result just with the State (and the timestamp), you can create your own Javascript services that makes a wrapped call to QueryPropertyHistory and then creates a new infotable (that has a data shape just with the state and/or timestamp).

Let me know if you need further clarifications.

Costin

PaiChung
22-Sapphire I
(To:costinb)

You can just do the specific QueryNamedPropertyHistory or QueryStringPropertyHistory to just recall the one column, and it will give you just that column. Something looks wrong though, I don't see any value changes between the recorded items, did you set the DataChange to Always vs. Value?

What the device is doing is recording the state every 20 seconds whether it changes or not, so the start and end times are changed with every record.

Then if the state value changes, we get a pair of records that gives the time when the previous state ended and the next state began.

What I want to do is "boil" the stream down to just the records where the state value has actually changed.

Thanks, Costin. This makes sense but it is important to understand that the device is acting as a data concentrator/historian. It is accumulating state data all the time but sending to Thingworx only when it is idle and a connection is available. So, depending on when the data is received, the Thingworx timestamp could be minutes, hours or days after the actual time that the state change took place. We need the timestamps recorded by the device to get an accurate, fine grained trace of when the state changes actually took place.

Here is what I really want to have happen ...

As each record from the device is received, I want to compare the new state value to the state value of the last record in the Thingworx repository. If the state value HAS NOT changed, all I really want to do us update the LastOEEEndTime - because the device has remained in the same state for another 20 seconds (or however long). If the state value HAS changed, then I want to add a new record to the repository with the new OEEState, LastOEEStartTime and LastOEEEndTime.

I thought the Value Stream would essentially do this form me. That is, it didn't expect it would update the LastOEEndTime like I want, but it should always have an accurate LastOEEStartTime to mark every change of state.

I suppose I will have to write a custom service to do this filtering on the incoming data values before they hit the ValueStream.

PaiChung
22-Sapphire I
(To:asinclair)

Hi Andy, just use a Subscription on DataChange for the OEEState and use a regular stream vs. ValueStream

the data you get from the DataChange event is the new and old value, timestamp and quality.

You can use that to use your determination and log the information you want.

The key point is that by using Stream instead of ValueStream I have control over when to log, what to log (Stream uses a DataShape), and can use the timestamp generated in the device instead of system time. This brought me to the solution I have now implemented. Thanks.

Top Tags