LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Representing the state of many buttons by a string

Solved!
Go to solution
Highlighted

I have sixteen switches.

 

I need to read the status of the switches and form a string as per this format :

<S0,S1,S3........S15,> and pass it via a Serial link to a microcontroller  which will strip the switch status from the string and do something with it. 

 

I created a small sample with four switches and managed to do what I want.( looks like a college project !)  Of course I should have used a FOR loop but never could do it - it has a Concatenation tunnel option but never understood how it works.

Any better method ?  

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 1 of 5
(625 Views)

Maybe this will give you some ideas:

 

temp.png



CLA // LabVIEW 2016 // BALUG // Unofficial Forum Rules and Guidelines
Message 2 of 5
(615 Views)
Solution
Accepted by topic author MogaRaghu

Comments:

  • Do not use a Timed Loop -- they are designed for (and should probably only be used for) LabVIEW Real Time code running on LabVIEW Real Time Processors.
  • Whenever you need to do the same thing to multiple Controls (or numbers), you should think "Arrays" and "For Loops".
  • Whenever you need to build Strings, you should think "Format into String".

I was going to attach a Snippet and show you how to do this, but you'll learn far better if I tell you how to do it, and then you do it.

  1. Take 4 Booleans and wire them to Build Array.
  2. Make a For Loop and bring this Array in via an Indexing Tunnel.
  3. Also create a Shift Register (to hold the String), and initialize it with "<" (from outside the For Loop.
  4. Inside the Loop, drop a Format Into String function and wire the Shift Register into Initial String and Resulting String.
  5. Wire the Boolean (from the Array) through a Boolean-to-0,1 function to the lower input of Format Into String.
  6. Edit Format String (right-click Format Into String) by adding a "," after the default %d.
  7. On the output side of the For Loop, use one more Format Into String (with Initial String from the Shift Register and the string ">" on the lower input.  The default Format String (%s) is fine.

That does it!  Very compact, very simple, easy to generalize (for other types of inputs), etc.

 

Bob Schor

 

P.S. -- I also like GregoryJ's solution.  I tend to stay away from the LabVIEW "Spreadsheet" functions, however ...

Message 3 of 5
(599 Views)

@MogaRaghu wrote:

I have sixteen switches.

 

I need to read the status of the switches and form a string as per this format :

<S0,S1,S3........S15,> and pass it via a Serial link to a microcontroller  which will strip the switch status from the string and do something with it. 

 

I created a small sample with four switches and managed to do what I want.( looks like a college project !)  Of course I should have used a FOR loop but never could do it - it has a Concatenation tunnel option but never understood how it works.

Any better method ?  


gregoryj beat me to it. However, from your format descriptor, it looks like you need a trailing comma after the last status. This would be the format string to add that last comma

 

SW_Sim_Trailing Comma.png

Message 4 of 5
(597 Views)

Thanks to all three who responded.

 

I liked Bob's concept .. it does it quite nicely.  Attaching the assignment !! Never really had a an opportunity to use the Boolean-1/0 function. Cute .

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 5 of 5
(543 Views)