05-07-2020 07:29 AM
Hello,
I am currenly making a simulation of using a chromatography column using LabVIEW NXG. I haven't come far yet, but I already see that I have too many nested case structures.
Some of the logic I have in there is:
Has the user pressed "condition"-button?
If True: Is the column empty?
If True: Is the selected conditioning volume less than or equal to 0? (invalid number)
If False: Is the conditioning volume less than or equal to 10? (maximum volume this specific column can hold)
If True: valves open and conditioning starts.
The question is: Is there a cleaner way to do this?
Thank you in advance!
05-07-2020 08:20 AM
Start reading up on state machines. Each of the "landing points" inside your nested case structure (the places where there's some code rather than just another nested case structure) will probably end up being distinct states.
Instead of evaluating all the logic for the case structures every iteration, you'll only be evaluating the logic that applies to the particular state you're in. What could cause you to stay in the same state? What could cause you to leave it, and what state(s) could you go to next? These kinds of questions help you work out a state diagram like the one shown in the linked article.
-Kevin P
06-21-2023 01:53 PM
Please, explain me, how does it work? I tryed to do it and I do not understand. The result from type cast is always the same - the last value of enum - it doesn't depends on the loop index.
So, in this case, what is the sence and why I can't just use a while loop with this bool connected to the terminal if I want to wait untill the condition will be true?
This is from oficial NI documentation (https://www.ni.com/pl-pl/support/documentation/supplemental/16/simple-state-machine-template-documen...), so, please explain it to me.
06-21-2023 04:11 PM
@bob3ro wrote:
Please, explain me, how does it work? I tryed to do it and I do not understand. The result from type cast is always the same - the last value of enum - it doesn't depends on the loop index.
So, in this case, what is the sence and why I can't just use a while loop with this bool connected to the terminal if I want to wait untill the condition will be true?
This is from oficial NI documentation (https://www.ni.com/pl-pl/support/documentation/supplemental/16/simple-state-machine-template-documen...), so, please explain it to me.
It really looks like that, doesn't it? But looks can be deceiving, and in this case, if you turned on "Highlight Execution" mode, you would discover that it goes through all the different enum items until the iteration number is greater than what can be represented by the enum, in which case it will be coerced to the last enum item. The problem is it happens too fast for you to see and it just seems like it is always the last item.
06-21-2023 05:01 PM
You might also want to look into something known as a "Natt Sequence".
A Natt Sequence runs through each case once and only once per item in the enum. I find it to be a pretty good alternative to multiple nested case structures.
If you post more details about what you specifically are trying to do then we might be able to give more specific advice. If you do, it might help to start a new thread since you've just posted in one that's 3 years old.
08-17-2023 03:13 AM
Sorry, but I think it's always the first value, and nothing changes trough the cycle. Ii tryed to test it again, and I always see "zero" on both indicators.
08-17-2023 04:28 AM - edited 08-17-2023 04:42 AM
Hi bob,
@bob3ro wrote:
Sorry, but I think it's always the first value, and nothing changes trough the cycle. Ii tryed to test it again, and I always see "zero" on both indicators.
You forgot to attach your code - we cannot debug/run/edit images with LabVIEW!
Example:
My enum consists of {3, 2, 1, 0}…
08-17-2023 04:50 AM
@bob3ro wrote:
Sorry, but I think it's always the first value, and nothing changes trough the cycle. Ii tryed to test it again, and I always see "zero" on both indicators.
"i" is I32, Enums are typicaly U16, you need to convert.
08-17-2023 12:49 PM
Stop using "type cast" and start using "coerce to type".
"Type cast" could be thought of as being a brute force conversion, it just tells LabVIEW to do its best to change the raw bit data of one data type to another.
"Coerce to type" is a much more intelligent conversion, which is what you need in this case.