07-13-2015 01:59 PM
Hello,
I am trying to make a bunch of switches where the software user can toggle on/off. However, I also want an option available where the user can enter a string of something like "ON: 0-5, 10-14" or "OFF: 0-5, 10-14" where it will toggle the switch on/off. I've heard that local variable is great for this, however, I could never get it so both options (Switch being option 1, and string being option 2) have equal precedence. It's always that the local variable has more precedence.
What would be an efficient way in doing such an operation?
07-13-2015 02:05 PM - edited 07-13-2015 02:08 PM
If you have problems with local variables, maybe you should attach the code containing the problem. I don't see any local variables.
(You have way too much duplicate code. Couldn't you combine all the DO into one? What's the point of the case structures, since both cases contain the same code? Why do you stop and clear the tasks with every iteration?)
07-13-2015 02:41 PM - edited 07-13-2015 02:56 PM
You are correct, I do not need those case structures. However, I am not sure on what you meant by combining them, or how to comine them so I don't have duplicate code. (Thank you for the feedback)
I have made a local variable near pin 0. My setup for the string control/local variable seems to work. My logic that is that if I type On into the String control, the switch should turn on, if I type Off into the string control, the switch should turn off. It seems to get a bit fidgety when I use the String Control and Switches, I want to make it so the string control and the switches both work as if they were two separate controls that controlled the same thing. They do not have to be separated but I want to get rid of that "fidgety". It seems that the string control has more precedence, I would like it so the String control and the switch have the same precedence.
For an example, if the String control is "Off" And if I turn the switch On, then the switch will turn on for an instance, and then default back to Off. Instead, I want it so if the String control is "Off" and if I turn the switch On, then the switch will stay on, and will change the String control to "On" (Vice Versa as well).
I hope this makes sense, if not please let me know and I will try to explain better.
07-13-2015 03:03 PM
You are constanty hammering a value into the local variable, meaning that whenever you change the switch, it gets overwritten by the code at ach iteration of the loop.
Again the local variable is shared by both cases, thus belong after the case structure, right. The structure only need to contain things that differ. You need to add another case aournd everything so the local variable is only written when the string changes.
07-13-2015 03:36 PM
07-13-2015 03:47 PM
altenbach
I do not think I quite understand what you are telling me. I understand that I am writing to the local variable at each loop iteration, so whenever I change the switch it gets overwritten by my case structure. But then I do not get what you mean when you say the local variable is shared by both cases and that the structure should only contain things that differ.
Dennis
You are correct that a string control may not be the best option due to the nature of strings. However, eventually I will have like 50-80 switches. So, my end game is that the user can type "0-10, 15-54, 75-76" and it will turn on those switches (In fact, that was going to be my next question, on how to do something like that: case structures would be terrible idea since it would just take a really long time to go through all the cases). Maybe a string is not the best idea because I just cannot come up with a better idea. If a user enters something gibberish I could have a case statement that prompts the user saying invalid input, please retry or something like that. I think that a string control would be the fastest way in turning on and off a great number of switches. I have not practiced much with arrays so that may be faster.
07-13-2015 03:52 PM
07-13-2015 04:33 PM - edited 07-13-2015 04:34 PM
@kenypatel wrote:
But then I do not get what you mean when you say the local variable is shared by both cases and that the structure should only contain things that differ.
Let's look at your (dysfunctional) code: In each case you have an instance of a local variable and a boolean diagram constant (A). The only thing that differs between the two cases is the boolean value, so move the local variable after the case structure and wire from the boolean in each case (B). Now you only need one local variable and nothing else has changed. You can get the same functionality by using code (C), arguably much simpler.
All that said, your code has very fundamental problems, this post is just a generic discussion about case structures.
These comments wil NOT solve your problems!
07-14-2015 07:28 AM
Dennis,
The boolean values are supposed to control the DAQmx write data terminal. It is suppose to give a true or false value to the data terminal. Right now, the boolean values directly control a local variable of the switches, which in turn control the data terminal of the DAQmx.
07-14-2015 08:30 AM