LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Switch as control and indicator

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?

0 Kudos
Message 1 of 13
(3,551 Views)

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?)

Message 2 of 13
(3,542 Views)

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.

 

 

 

0 Kudos
Message 3 of 13
(3,520 Views)

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.

0 Kudos
Message 4 of 13
(3,497 Views)
I don't see where having a string to control the on/off states is a smart idea at all. What happens when a user enters gibberish into the string? Just having an array of Booleans or even individual switches seems better. The user can't select something invalid.
0 Kudos
Message 5 of 13
(3,477 Views)

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. 

0 Kudos
Message 6 of 13
(3,471 Views)
What are the Booleans supposed to control? I can't look at your VI. if the are supposed to control a DAQ device, then you can simply use a DAQmx channel control.
0 Kudos
Message 7 of 13
(3,466 Views)

@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!

 

Message 8 of 13
(3,438 Views)

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.

0 Kudos
Message 9 of 13
(3,376 Views)
There are numerous ways to solve this without resorting to dozens of locals or strange string parsing. Do you understand binary or hex? A single numeric control can be used - i.e. 00110101 controls the logic of 8 different lines. Break it into multiple controls for better readability. A numeric control would not allow the user to enter invalid text like your approach and would be wired directly to a DAQmx Write. The write accepts a numeric just as well as a Boolean.
Message 10 of 13
(3,358 Views)