03-29-2018 07:56 AM - edited 03-29-2018 07:57 AM
Hi,
I'm just worked through the CLD Success Package exercises, and I have a query about CLD 16 - State Machine with Enables and Disables. Basically, I would like to understand better how and why the Data Cluster.ctl is used in the solution.
When I attempted this, first of all I found that to increment/ decrement the Tons of Peanuts value was not possible with a local variable, so I then implemented my solution using the Value Property Nodes (in a QSM). I didn't need to use the Data Cluster.ctl. at all, and indeed I don't see how it works in terms of the basic principle of how it is used to read/ write values to the front panel. Perhaps there is just something about this approach that is radically different to my style of programming, however I would like to understand it better.
I've looked around for literature that might shed some light on this, but can't find anything. So, I'm hoping someone here can help!
04-02-2018 04:48 PM
Good question.
Let's see If I can shed a little light. As an asside, I would not have coded it that way.
However, all of our UI elements exist in this control so if the requirements changed to Have 3 Control panels and a numeric to display the active peanut bin there is on place to make the data type changes and (looking at that data as if it were a class object)
There is one "Init" method. only 1 Use (Do) Method, and a few Update Display methods tossed all over the event structure (Which has a Timeout event to poll the stop boolean) Like I said, Probably not the best way to do that.
It could be written many ways. one of the reasons wee do code reviews! so someone can point out that the control looks like a "God Object" and we can learn better
04-09-2018 04:22 AM
Thanks for the reply. Ok, so the principle behind this specific solution isn't necessarily something I will need to become familiar with for the CPD exam, I take it. I found that my solution using Property Nodes to update values came much more naturally to me, and I think (although I am obviously biased in this) it was more readable.
04-09-2018 06:40 AM
@DG76 wrote:
I found that my solution using Property Nodes to update values came much more naturally to me, and I think (although I am obviously biased in this) it was more readable.
You WILL have points marked off for using Property Nodes to set values. Property Nodes are actually WORSE than using Local Variables (1000s times slower based on my last set of benchmarks and you still have the same issues as the Local Variables). The solution is to store your values in a shift register and write to the terminals of your indicators. These can be outside of the state case structure so they get updated every iteration.
04-11-2018 10:10 AM - edited 04-11-2018 10:17 AM
At first I marked the above post as a solution, however I have just gone back to this exercise in another attempt. In CLD 16, the clusters are not indicators, they are controls, and cannot be changed to indicators without rendering the control buttons within them non-functional. Therefore it is not possible to write to the clusters using shift registers, bearing in mind local variables are not an option.
I also note that the solution utilises Property Node Values to update these values. I think the only way to solve this exercise is using Property Node Values.
I'll keep the above post as a solution, however I'm not sure there really is a good solution to this one. Perhaps the exercise requirements could be updated, so that using Property Node Values is not the only way to solve it. This would mean tweaking the front panel clusters, perhaps taking the control buttons outside the clusters and making the Tons of Peanuts into an indicator.
04-11-2018 11:02 AM
@DG76 wrote:
I also note that the solution utilises Property Node Values to update these values. I think the only way to solve this exercise is using Property Node Values.
You need property nodes for the enable/disable, but you can use local variables for the cluster.
Keep the data for each input cluster in a shift register, and whenever controls need to update, you can write the entire cluster data to a local variable of the cluster.
(Just looking at the provided "solution", I notice quite a few problems with it. Overly complicated and some potential race conditions. I probably could do it with 25% of the current code :D)
04-12-2018 02:41 AM - edited 04-12-2018 02:54 AM
Unfortunately, writing to local variables in this context is simply not possible for this CLD exercise as far as I can tell. Has anyone actually tried it? I get the attached errors when I do.
If someone has in fact implemented this, I would be interested as to exactly how they did it.
04-12-2018 05:25 AM - edited 04-12-2018 05:31 AM
After further consideration, I don't think I can accept crossrulz's suggestion as a solution (sorry crossrulz), just because I'm not sure if there is a solution for this with regards to programming the application without writing values to Property Nodes, in which case the exercise solution can be simplified as far as I am concerned. In the given exercise, indicators and controls are mixed in the cluster which significantly complicates matters and prevents successful implementation of the suggestions offered so far, unless I am missing something. I'd be happy to be proven wrong!
04-12-2018 06:23 AM
@DG76 wrote:
In the given exercise, indicators and controls are mixed in the cluster which significantly complicates matters and prevents successful implementation of the suggestions offered so far, unless I am missing something. I'd be happy to be proven wrong!
No. A cluster (and its contents) can only be a control or an indicator. You cannot have both inside of the same cluster. Now that I have looked at what the problem is, I see that what needs to happen is a single value inside of the cluster needs to be set when a certain button is pressed. Personally, I don't think I would have used a cluster here. But to update a single value in a cluster, you need to use a property node.
04-12-2018 07:08 AM - edited 04-12-2018 07:09 AM
The Tons of Peanuts control in the cluster is essentially being used as an indicator in this exercise, as it is showing the current Tons of Peanuts count, whereas the Fill and Use buttons are used to increment or decrement the count. Anyway, thanks for helping me get to the bottom of this, I think I have a much better understanding of what I need to know for the CLD exam now. I just hope that it won't involve a similar type of mixed-purpose cluster!