Case Structure and String
Hello everyone.
I'm having some problems with my VI on Labview. I have as input a String that have in sequence: "Number of Sample/X Value/Y Value/Z Value", each of them separated by a comma. In the serial port I receive a loop of 500 samples from an accelerometer.
I'd like to have Labview receive the values only when the String "Number of Sample" is 0 and graph them until the 499th sample is send and discard the data when is different from 0.
My problem is the Case Structure, I can't manage to send data when the string is 0 and discard the data when is different from 0.
I've attached my VI, any help would be greatly appreciated.
Solved!
Go to Solution.
Attachments:
Serial Port String.vi 17 KB
Well, you appear to have LabVIEW 2013. Did you know about the Conditional Tunnels that were indtroduced in 2012 and improved in 2013? a quick mod to your code is attached.
There are other opportinities to improve that code but, I'm assuming its only part of a larger vi (and a BD clean-up is in order) Comments can also help make your code more readable
Jeff
Attachments:
Serial Port StringJJB MOD.vi 23 KB
Similar Messages
-
How do I use a Case Structure with Strings?
I need to use a string list to set up a set of cases to be performed. Is it possible to tell a single case structure to do "a, b, c, and d, but not e or f" or "do a, c, d, and f, but not b or e" etc... when you use a string containing the cases to be used?
Blackavar,
A case structure will only execute a single case at a time. If you want to have multiple cases execute in parallel, then you would need to have multiple copies of the case structure and split the string apart and wire them to all of the needed case structures.
This could be done with reentrant subVIs to run truely in parallel. Anther method would be to have 6 different case structures, all with 7 cases each. The 7 cases would be "a", "b", "c", "d", "e", "f", and "0". Your input sting will need to be built up so that it will always be 6 characters long and then split up so that each character goes to one of the case structures. You would have your needed code for cases a - f. Case "0" would do nothing.
Randy Hos
kin
Applications Engineer
Nationsl Instruments
http://www.ni.com/ask -
How to change the case structure to string input?
Hi,
I have the inner case structure that it will decide to set "DC Voltage" or "DC Current" mode. The "Output Function" contained the selection of function "DC Voltage" or "DC Current". So far it only work with DC Voltage not DC Current. My question is how do I change the case structure to string selector? When the output function is selected to DC Voltage then the case structure is selected DC voltage case. Please help Thanks.
Attachments:
test.vi 35 KBYou don't really need to convert the value to a string? The problem is that the value of the individual ring items are not 0 and 1, as you assumed. The values generated by the controls are:
DC Voltage: 1006
DC Current: 1007.
You can find this out by viewing the properties for the "Output Function" and going to the "Edit Items" tab.
So, all you need to do is change the 0 to 1006 and the 1 to 1007 for your case items.
By the way, your sequence frame serves no purpose. -
Calculate maximum value of subarray while creating it using a case structure and shift registers
I have two 1D arrays that contain cyclical information (kind of like a sine wave). One that contains information on position in degrees and another that contains torque. I would like to calculate the maximum torque value each time the position is within a certain range (e.g. from 30-80 degrees). The ranges are repeated - that's why it is cyclical. I use the "in range" function, a case structure and shift registers to build a new array with values that fall within the range I specify - this was the easy part (see VI attached). I'm struggling with a way to calculate a maximum value for each subarray formed when values are "in range". Your help is much appreciated.
Solved!
Go to Solution.
Attachments:
Simple Calculate between anatomical position range.vi 16 KBIt's not really noise - it's more inconsistency. So a position output can run: 20, 30, 40, 50, 60 etc. OR, it could run: 21, 24, 32, 41, 44, 51, 59 etc. But, it is always cyclical.
Attached you will find a .csv file with the data arrays - I'm using POS (ANAT) degrees column (column D if you open in excel). There you also see torque in ft-lbs along with some other information.
Attachments:
025C.csv 224 KB -
Case structure and dynamic data, maybe once again
Hi there,
I`m a beginner in Labview. I´d like to know, how to handle the attached case-structure so that the structure works with each point of the signal.
Right know the signal is only analyzed one time.
Thanks for your help
Michael
Attachments:
prob.jpg 26 KBThank you Lars!!
Now it works
Solution is given as attachment
Attachments:
lsg.jpg 46 KB -
How to use integer in case structure on FPGA
Hi there,
I was trying to use a case structure on FPGA module. The input to case selector terminal could be arbitrary integer like 0x1EEE or 0x2000 or 0x3FFF. Since I cannot find integer-string conversion on FPGA, how can I do it? ThanksHello!
If you want to create a case structure to handle arbitrary integer values, you can always use the decimal representation of the hex value (i.e. instead of 0x00FF, use 255). If you want to create cases for the hex values, you can right-click on the case structure, and choose Radix>>Hex. You should notice that all cases are now preceded with an 'x' to denote hex values. This will allow you to create cases called x00FF, which sounds like what you're looking for.
Cheers,
Matt Pollock
National Instruments -
CASE structure limits - dynamic?
Hello everybody
Is this possible, and if, then how, to make the CASE structure
condition dependent on variable in my program.
Egsample: I have integer and the value of this is changing during
program running, and I need from some reasons, to make the CASE
structure sensitive for the values of this integer. How I can do
this?
I know there is always way around, but I am interested in this
solution.
thanks in advance
regards
PPHi Pawel,
I am starting a new thread because I think I know what you are asking for.
First of all, you can not change the values of the case structure itself BUT,
there is a way.
What I suggest is the following;
1) Code your second case as normal. Pretend it has 3 cases 0,1 &2.
2) Code the first case (just example) such that is has two cases A&B.
3)Have the first case state A return an array of (3)strings that is "Good", "Bad", and "Ugly".
4)Have the first case state B return an array of (3) strings that is "Bad", "Ugly", and "Good".
Feed the above mentioned arrays into a serach 1-d array function. Use the retuned index to select the proper case of "the second case".
If you now pass "A" to the first case structure, and "Good" to the "se
arch 1-d array" it will return an index of 0 and the second case will execute case "0".
If you pass the first case "B" and again pass "Good" to the "serach...." it will return an index of 2 and the second case will execute state "2".
So,
by manipulating the arrays returned by the first case structure, you can "dynamically" influence which of the states of the second case is called.
There are many variations on this idea that are possible. A similar approach would make it possible to select states based on wildcards and simulate "sparse enums".
Did I nail it this time?
Ben
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction -
Case structure & event structure
1.What are the disadvantages of case strucure?
2.What are the advantages of event structure?Are these test questions? I could name 10 for each, but why are you asking?
While there are often many ways to accomplish the same thing, Case structures and Event structures serve different purposes. Straight from the Help file:
Case Structure
Has one or more subdiagrams, or cases, exactly one of which
executes when the structure executes. The value wired to the selector terminal
determines which case to execute and can be Boolean, string, integer, or
enumerated type. Right-click the structure border to add or delete cases. Use
the Labeling tool to enter value(s) in the case selector label and configure the
value(s) handled by each case.
Event Structure (Not in Base Package)
Has one or more
subdiagrams, or event cases, exactly one of which executes when the structure
executes. The Event structure waits until an event happens, then executes the
appropriate case to handle that event.
Right-click the structure border to add new event cases and configure which
events to handle. Wire a value to the Timeout
terminal at the top left of the Event structure to specify the number of
milliseconds the Event structure should wait for an event to occur. The default
is –1, indicating never to time out. -
Why does Labview insert quotations in the case structure selector box?
I was building a case structure with an array of strings. So, I copied the strings from the array on the FRONT PANEL directly into the SELECTOR LABEL. My 3 strings have the form; to me, these are 5- character strings with spaces, or 7 characters if you count the spaces as string characters
A, B, C
A, B, D
A, B, E
So, when I copied and pasted them directly into the selector box A, B, C appeared as "A", "B", "C" and A, B, D appeared as "A", "B", "C" and then I got an error for selector values not unique. Why didn't it appear as "A, B, C"?
Why did it transform the string I pasted and insert the quotation marks? I used no quotation marks in my array. Does the selector label interpret commas as functional characters that require quotation marks??
Thanks,
Davedav2010 wrote:
I was building a case structure with an array of strings. So, I copied the strings from the array on the FRONT PANEL directly into the SELECTOR LABEL. My 3 strings have the form; to me, these are 5- character strings with spaces, or 7 characters if you count the spaces as string characters
A, B, C
A, B, D
A, B, E
So, when I copied and pasted them directly into the selector box A, B, C appeared as "A", "B", "C" and A, B, D appeared as "A", "B", "C" and then I got an error for selector values not unique. Why didn't it appear as "A, B, C"?
Why did it transform the string I pasted and insert the quotation marks? I used no quotation marks in my array. Does the selector label interpret commas as functional characters that require quotation marks??
Thanks,
Dave
Actually in CASE STRUCTURE, any frame can have multiple values as 'Case Selector value' and these are separated by a comma. Also if you choose to operate a CASE STRUCTURE using string, it will automatically prefixs & suffixs quotes (") to that string.
But you can enter "A, B, C" manually and it will remain as it is. But if you copy and paste A, B, C, the CASE STRUCTURE will automatically change it to "A", "B", "C".
I am not allergic to Kudos, in fact I love Kudos.
Make your LabVIEW experience more CONVENIENT. -
My case structure values chnged form words to numbers.
I have a case structure and the values changed to numbers, also i am not sure why it is not cycling through? any help would be appreciated.
Attachments:
version2.vi 121 KBYou have too many cases (167) That is a number you can't maintain.
The reason you get a numeric as datatype and not an enum is because you should change the enum into a type def control.
To do this right click the instance left of the while loop->Create control. On the control on the front panel right click->advanced->Custimize control and set the control to type-def (see attachment).
Then save this control, and use this everywhere.
But first limit you cases, or use a plain string to explain the state...
Ton
Message Edited by TonP on 10-16-2006 08:05 AM
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas
LabVIEW, programming like it should be!
Attachments:
labviewTD.PNG 6 KB -
Can I use a formula node to start the execution of a case structure?
Hi,
I am working on editing a VI to make it much easier to understand (for colleagues and non LV users). For one reason or another, the VI's creators did not fully make use of the power of case structures and other structure types. In the application we need it for, the instrument cycles and repeats measurements on several objects. We are interested in measuring the motor currents for several motors in the system. As it stands now, for each sample object's run, there is a separate sub-vi diagram which displays its waveform trace and several indicators such as max current, time at max, etc. That code was contained within a T/F case structure and copied and pasted 20 plus times.... Obviously the vi became extrememly cluttered and needed a huge screen to see. The trigger for the current case structures is an EQUALS comparison between one input (which is the sample object counter; and this part I will likely leave unchanged since it makes a lot of sense already) and a constant which was defined 1 through 20+ for case.
I have since made one case structure and 20+ instances of that case and have labeled them (at the top selection box near the detent arrows) "1", "2", 3, etc. I am wondering if I can use a formula node to act as the "trigger" which sets each case structure running? I believe that a simple IF statement should work. Please see a snippet of my attempt at making this in C below.
For the node, I defined X as the input and Y as the output. The input to the node, X, is connected to the sample object counter. The output, Y, is connected to the case selector of the case structure. My attempt at the code is below:
int32 y
For(x == 1)
y = "1";
For(x == 2)
y = "2";
etc, etc.
Is that above code snippet correct? Do i need something like "ENDIF" or "end if" at the end? Does "y" have to be defined as "int32" or can it be something else?
Thanks for the help!Is your formula node doing anything else besides what is shown?
Why don't you just wire the value that is going into it at X directly into the selector of the case structure?
Attachments:
Example_VI_BD.png 2 KB -
How to get a case structure to execute only once in a loop
I have a while loop that is monitoring temperature. Once the temperature meets or exceeds a given setpoint I want to start a timer. At this point I don't want to monitor the temperature anymore. That is, if the temperature should drop below the setpoint, I don't want to execute the case structure again when the temperture meets or exceeds the setpoint(the temp may oscillate about the setpoint for a given period of time). In any event, I need the case structure to execute only one time, not every iteration of the loop.
You can put a local Boolean variable "Flag" inside that case structure and
set "Flag" to False. Outside the case structure, use an "AND" function
output to control the case structure. The "AND" function has two inputs. One
goes to the comparison results between real temp and setpoint. The other
inputs connects to the "Flag" variable. In this way, once you entered that
case structure, the "Flag" will be turned to False, and then in next
iteration, you won't get into the case again because the "AND" function will
be False as your "Flag" is False now.
Hope this helps.
Rentian
1. Inside the case structure, put a
"BB Herman" wrote in message
news:[email protected]..
>I have a while loop that is monitori
ng temperature. Once the
> temperature meets or exceeds a given setpoint I want to start a timer.
> At this point I don't want to monitor the temperature anymore. That
> is, if the temperature should drop below the setpoint, I don't want to
> execute the case structure again when the temperture meets or exceeds
> the setpoint(the temp may oscillate about the setpoint for a given
> period of time). In any event, I need the case structure to execute
> only one time, not every iteration of the loop. -
How can I put a numeric indicator into a case structure using VI scripting
I'm using VI scripting and I'm trying to add a numeric indicator inside a case structure. I'm able to add the case structure and the numeric indicator just fine, but as soon as I specify the case structure as the "owner" of the numeric (as opposed to the block diagram being the owner) I get error 1060. Is there any way around this?
Note: The reason I am doing this is because this specific pattern (indicator in a case structure) will prevent a VI from being inlined when it is being built. This pattern will provide no functionality in itself, it only prevents the inlining. It is added to a larger VI which is use to initialize objects in a simulation, and there are many of them in the total simulation. If they are inlined, it takes a VERY long time to generate the C code, and performance on this VI isn't an issue since it is performed only once at the beginning of the simulation. The rest of the VIs do need to be inlined for performance reasons. Therefore, I'm open to other options to prevent a VIs from being inlined if the "indicator in a case structure" cannot be performed via scripting.
If any of this is unclear please let me know and I can clarify. Thanks.
Solved!
Go to Solution.I now understand what you were saying about inlining a subvi. I did as you said and made a subvi with a case structure and an indicator within it. I use the New VI Object node to add that subvi to the slow-inlining parent VI. Then I tried to inline it using the invoke node, but I got error 1399, which make sense. Is this what you meant for me to do, or did I misunderstand?
Also, I tried the ControlTerminal reference approach you mentioned earlier. Unfortunately when I called the move method on the control terminal property and had the 0th frame of the case structure as the owner I got error 1060 again.
I really appreciate your help. Do you have any other thoughts? -
Hello,
I am using LabVIEW 8.0 and I am attempting to create a sub-panel that displays the front panel of a sub-vi depending on the selection made by the user via the Enum dropdown menu. I have wired the Enum to a case structure and applied identical coding to each individual case structure except for obviously changing the sub-vi source. However, I receive an error "The VI is not in a state compatible with this operation." I was able to successfully make a single sub-vi work within a sub-panel using a true/false case structure and the exact same coding. However, now that I am using an Enum box wired to a case structure, I receive this error. I have attached my block diagram as well. Could anyone assist me as to where it is that I am going wrong?
Thanks in advance!
Solved!
Go to Solution.
Attachments:
enum subpanels.JPG 22 KBtorm wrote:
I have attached my block diagram as well
I only see a picture. Can you attach the VI instead? At what point do you close the reference?
torm wrote:
I have wired the Enum to a case structure and applied identical coding to each individual case structure except for obviously changing the sub-vi source.
Well, if the code is identical except for the source, only the source should be inside the case, right? Why duplicate code?
LabVIEW Champion . Do more with less code and in less time . -
In the attached VI I don't understand why data from the inner case structures are not being transmitted to the array.
Thank you.
Solved!
Go to Solution.
Attachments:
TEMP.vi 25 KBIt took me some time to figure what you are trying to do but I think I have it now.
The SR is still required.
What is happening is your "Bundle By Name" is replacing all of the fields of the cluster, not just the value coming out of the case structure. So to maintain the cluster stuff you do in earlier iterations you can either...
1) Put the "Index array, Bundle by name, and Replace array" inside the case structure and ONLY bundle the value you are setting in that iteration. (as you will see Tim post shortly)
OR
2) Move the Index array before the Case, unbundle all of the fields and feed teh case structure and run them across the case so that ALL of your output tunnels come from the coresponding input tunnel EXCEPT for the filed you are trying to set.
Ben
Message Edited by Ben on 05-05-2010 01:31 PM
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction
Maybe you are looking for
-
How do I allow parental controlled users to access third party apps on the admin account?
I just set my son up with a separate parental controlled user account and he can't seem to access some third party games that we installed for him under my admin account. He has saved progress on these games that we don't want to lose, so I don't wan
-
Tcode MIGO Background Job Not working
Hi All, I am facing problem in TCode : MIGO for Background JOB of BDC Program with below details, CALL_TRANSACTION MIGO returncode: 1,001 RECORD: 0 MIGO 017 S The front end is not suitable for the transaction (see long text)
-
Hi Gurus, i have two requirements, for that i am using IF condition but its not giving proper results. for first requirement iam using code like this 1) <?xdofx:if QuantityActual='' or QuantityActual=0 then 'N/A' else if AcceptableFlagDisplay = 'Yes'
-
I have an iPod 5thGen 30 GB. My tracks on my playlists are rarely in the correct order on the iPod, tho the order is correct when viewed on iTunes. Is there anything I can do?
-
I recently installed Montain Lion on my 2009 iMac. Now when I try to access my iTunes library through my second generation Apple TV I receive the following message: "Could not connect to ...Library". I have done the following to resolve the problem