05-22-2014 09:22 AM
Hi all,
Forgive me I'm a noob, trying to make my way here.
I have a sound level meter that I am interrogating over serial to make up a little measurement system.
I have a series of serial commands I want to make, and so far I've been using a flat sequence to do so, one after the other:
*RST = reset the meter
INIT START = Start measurement cycle
MEAS:START = start the measurment required
MEASure:TIMEr? = get the amount of time ran for, when enough, move on
INIT STOP = stop the measurment.
The issue I am having is the cblock where I need to continuously interrogate for the time to stop it when it gets to the correct level. At the moment I have it in a for loop, and it is measuring until it hits a level specified by a constant on a greater than. This is supposed to trigger a boolean to stop the larger loop.
The problem I am having is that while my for loop is iterating, it doesnt' seem to be continuously reading in the data for time. I need help making it continuopusly read...
Any help would be greatly appreciated, VI attached.
Thanks!
05-22-2014 09:33 AM
What you describe is a State Machine, code that runs and does different things depending on what "State" (RST, INIT START, etc.) it is in. If you go to LabVIEW Help and look for State Machine, you'll see that there is a Sample Project called Simple State Machine. This should give you some very helpful ideas to help accomplish your task.
BS
05-22-2014 10:19 AM
Thanks Bob, I'm looking into state machines as a concept. They look fairly complex compared to what I have now potentially. Will they allow me to loop a read on serial?
Thanks for the help so far!
05-22-2014 10:37 AM - edited 05-22-2014 10:37 AM
If I understand you, you will probably need two loops. Depending on when exactly you want to acquire data, you may need to communicate between the loops. Probably a local/shared/global variable, queue, etc.
[State Machine Loop] --> Issues commands listed in your OP
^
|
Communication
|
V
[Data Acquisition Loop] --> Continuously reads data
05-22-2014 10:45 AM
I don't see the point of the FOR loop. The WHILE loop that it is in should be good enough. As is now, you have to request and read the time 9,999,999 times. That will be a VERY long time.
A state machine is not complicated. It is actually a lot more powerful and flexible. With the sequence structure, you are stuck having to go step by step. With a state machine, you can skip around states and even repeat easily. So let's say you get an error somewhere. With the sequence structure, you still have to go through each case. With a state machine, you can go straight to the error handling routine and/or abort. You should definately go this route.
05-22-2014 10:51 AM
The problem I'm getting however is that it doesn't read it more than once. It gets into that loop, and the loop iterates, but it doesn't read more than once, I can't work out why...
I take your point about the state machine structure, but going step by step isn't a problem for this project. Even if this code is within a state machine, I can't see how I can get it to continuously read over and over...
05-22-2014 11:01 AM
Here is my simple state machine example. Take a look at it and see if it gives you a better understanding of a simple state machine.
This one was made to contimually record data to a file and create a new file every day.
05-22-2014 11:34 AM
Read the manual for your device. Check to see if it can only accept so many messages at a given rate.
07-29-2016 11:08 AM
Leeps,
The code looks like it should do what youre asking. A state machine would give you a lot more flexibility, but that is up to you. It may not be working properly because youre getting unexpected values.
Suggestion for debugging would be to turn on highlight execution and probe the response read, since im sure thats the read youre refering to as only happening once. There is a possibility that the device isnt even sending any data even you are utilizing it properly.