LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

multiple boolean values to be used in case structure

Solved!
Go to solution

Hi,

 

I am trying to implement a case structure with multiple boolean cases and am having trouble with that. What I want to do here is : I have a set of 5 values, each of them being "true" or "false". For each "true" value, I have a certain set of steps to be executed. The "false" of each can be ignored. Ideally, I would like to have a case structure for the 5 "true" cases. I am not sure how to go about wiring these boolean outputs to my case structure. Also am using LabView 6.1.

Any ideas?

 

Thanks,

Sukanya

0 Kudos
Message 1 of 16
(15,615 Views)

Are the value mutually exclusive? If so, you can simply build an array out of them and search for the one that's true. The index number can be used to drive your case.

 

If they are not mutually exclusive then you can build an array out of them and drive a for-loop using auto-indexing. In the for-loop you can have one case structure inside another. The outer case structure can be driven from the loop's iteration terminal. The inner case structure either does the steps or not, depending on the value of the current Boolean.

0 Kudos
Message 2 of 16
(15,604 Views)
Yes, they are mutually exclusive. I did build an array with all five boolean outputs and did a search for "true". The default case always gets executed. I'm not sure where I'm going wrong!
0 Kudos
Message 3 of 16
(15,602 Views)

Personally I like this method.

 

http://forums.ni.com/ni/board/message?board.id=170&message.id=453760&query.id=112270#M453760

 

Edit: My bad, mutual exclusivity makes this a pain.

 

Message Edited by Darin.K on 02-05-2010 11:17 AM
0 Kudos
Message 4 of 16
(15,597 Views)

sukanya wrote:
Yes, they are mutually exclusive. I did build an array with all five boolean outputs and did a search for "true". The default case always gets executed. I'm not sure where I'm going wrong!

I'm not either unless you can show us what you did.

0 Kudos
Message 5 of 16
(15,578 Views)

This is what I'm trying to do. I did put a few checkpoints to figure out where the problem is and I found out that, the problem is at the point of comparison. It does not return a "TRUE" for any of the cases despite one of them being true. I was under the impression you could compare two strings using the "=" operator. But looks like it isn't working.

 

analyze.JPG

0 Kudos
Message 6 of 16
(15,514 Views)
Solution
Accepted by topic author sukanya

Funnily, I actually got it working! I tried using a string comparison function instead of a "=". It works!!

Thanks all!

0 Kudos
Message 7 of 16
(15,512 Views)

sukanya wrote:

Funnily, I actually got it working! I tried using a string comparison function instead of a "=". It works!!

Thanks all!


The reason for that is because the string you read from the serial port would have contained a carriage return and/or linefeed. Your equality is not accounting for that, which is why you never got a True out of any of them. A string comparison just checks for the existence of the text within the read string, so that would find a match.

0 Kudos
Message 8 of 16
(15,507 Views)
Yeah, I realized that when I changed the display pattern to "\" Codes display! There were some carriage returns, line feeds etc. Can't believe I wasted so much time on something this simple.
0 Kudos
Message 9 of 16
(15,501 Views)

Additional comments regarding code:

  • It is a mistake to configure the serial port inside the loop. This is a waste of time and resources. Configure outside, read in the loop, and close outside after the loop is done. The flushing of the buffer would be part of the "configure outside".
  • The default values of the controls for the VISA Configure Serial Port VI are such that the termination character for reads is enabled, and the character is set to a linefeed. This means the VISA Read will read until it sees a linefeed or reaches the value wired to its byte count input. Thus, the VISA Bytes at Serial Port isn't really necessary.
  • You should not rely on the settings in the LabVIEW option for automatic error handling. You should explicitly handle errors in your code. Thus, you probably want to stop the loop on an error and provide a dialog via the Simple Error Handler.
Message 10 of 16
(15,500 Views)