03-13-2010 12:10 AM
Hi all,
I have a state machine with many states. I am using an enum to select state. I didn't add all the state in the enum at the beginning, so I am adding more statess to the enum and to the state machine as I go. I found the following pretty troublesome.
If after I made the first 3 state, and I realized that that next 3 states are very similar to the first 3 states. I want to copy duplicate the first 3 case all at once, instead of duplicating one case at a time.
If I duplicate one state, and the wrong enum is assigned to the state, is there a quick way to change it?
Are their anything out there that would help plan and keep track of the state machine?
Let me know if you have any cool tips to speed up state machine development, especially topic on enum and case structure (adding, deleting, multiple copy, etc).
Yik
03-13-2010 01:02 AM
Well, this really should be in the LabVIEW board rather than the Forum Feedback.
Are you using typedef's for your enum? If not, start now. You'll need to go back to all of your other constants and replace them with the typedef. That way as you add states, all constants where that enum is used can be updated and synchronized at once.
You can only duplicate one case at a time. How would you even define that you want the first 3 cases duplicated, but not other ones? Or even 1, 2, and 4, but not 3, 5, and 6.?
If the wrong enum is assigned to the state, then just go into the title bar of the case statement and edit the text that is there to be the case you want. Be sure you spell it correctly (and I think capitalization matters as well.) If you mistype it, the case selector will show up as red and of course the run arrow will break. If it's right, the text will turn black.
If you find a couple cases need to be swapped, then right click on the case structure and there is a menu choice with swapping that case for another one.
You can also reorder the cases. It won't affect the operation of your LabVIEW code any. But if you want your cases listed in a particular order when you click on the drop down, or scroll back and forth through them, then you can reorder the cases to whatever you desire.
03-13-2010 01:33 AM
jyang72211 wrote:
after I made the first 3 state, and I realized that that next 3 states are very similar to the first 3 states. I want to copy duplicate the first 3 case all at once, instead of duplicating one case at a
If at all possible, never copy and paste code that is very similar to another piece of code! Try to write modular code. If there are several states that are almost identical except for a few slight differences, wrap those differences in a small case structure within the case.
If you ever find yourself tempted to copy and paste a diagram of code that is larger than a POSTAGE STAMP, reconsider!
03-14-2010 04:50 PM
Hi,
I am trying to make my code as modular as possible, but I do have a question on that one.
For example, let say that I have a test flow, and it has 10 states in a state machine. State 1, 3, 4, and 5 have very similar code except for a few minor details. These states have a few subvi and have very minimal low level nodes. I guess I should make them into one subvi and use it for all the states that have similar needs, but I am not sure is that over modulizing or not. If I do that, I will just have one block in the whole state, and it maybe a bit unclear in terms of what I am doing with the state? I don't want to make too many subiv that may obscure what I am trying to do with a state.
Sorry, I am not sure why I posted this message on the wrong board.
Yik
03-14-2010 06:05 PM
03-14-2010 09:40 PM
The most important thing I learned about asking questions when I was a LV beginner is this: I didn't even know enough to ask the right questions. I can see from your posts that you're eager and willing to learn, and the best way to do this is to post code. Those who know more than you can in just a few seconds identify some of the things you need to work on the most, and there are a lot of participants on this forum who will very quickly give feedback on code that is posted. Although it seems you are already targeting a very important feature - modularity - why not post some code and see what else you could learn?
Since this is indeed the wrong board, don't reply again here - start a new thread on the LabVIEW general discussion, and link to this post.