From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event Structure and data taking

Hi everybody,

 

I am a bit confused by the Event Structure so I hope somebody can tell me if it is the right tool for what I want to do.

Basically, I am designing an interface for our daq system: the main panel should have a button to configure the boards and a button to start the acquisition and save data to disk.

 

The configure case works fine because typically I will press the button, have a subvi to do the configuration and then go back to the idle state.

 

What I am not sure about is the "datataking" case. What I would like is a way to have my datataking subvi to run until I turn it off, for instance to change the configuration again. The example attached is clearly wrong because once I start the datataking, the button locks to the true state and there is no way to change it back. I included a rudimental time-out after 100 loops to prevent my VI to get stuck forever. On the other hand, if I remove the inner while loop, the datataking is only executed once.

 

Is it correct to use the Event Structure for such an application or should I just stick with a state machine, evaluating the value of my LED at every loop?

 

I hope this request is not too confusing.

 

Cheers,

Paolo

0 Kudos
Message 1 of 9
(2,820 Views)

Noramally for data acquisition you need to have a producer consumer design pattern where the producer generates the command and the consumer acquires the data. You can pull the design pattern from the Project template wizard that is availabel in File>> New>> From Template.

 

Good luck.

-----

The best solution is the one you find it by yourself
Message 2 of 9
(2,817 Views)

Hi,

 

thanks for the reply. I am looking at the template but I still fail to understand how to stop the producer loop if I put the structure in an Event case.

Or shall I just get rid of the Event structure? In this case, though, how do I select whether I want to read data or configure the board?

 

 

0 Kudos
Message 3 of 9
(2,812 Views)

Moon,

From a brief glimpse at your code I can say two things:

1) P.Anand offered some good advice.  Really look into the PC (Events) template.  A "Queue Driven State Machine" or QSM appears to be an ideal design pattern for this type of application.  Search the forum for QSM to get some foundational knowledge.  Use the example finder too!  the current PC-Events template is less than ideal.  Us users have developed some better practices- look through my posts (click my name I keep my profile open) within the last 2 months I posted my PC-Events template and that would serve you well. 

2) NEVER place code that takes time to run inside an event.  (As a rule of thumb-"never say never") your start data takining value change event takes at least a whole half second to complete- meanwhile the user is expecting the controlls he/she is clicking on the GUI to DO something- and slamming his/her mouse in frustration since the events queued up by the user actions can't be processed untill the event is complete.  This is not "User Friendly"

 

And one last tip: Document your code!  Someday you might not be the maintainer of this code.  If you run into the person who does have the job that person will want to do one of two things: Punch you in the nose or, Buy you a beer.  Well documented code will prevent you having as crooked a nose as I sport!


"Should be" isn't "Is" -Jay
Message 4 of 9
(2,787 Views)

@JÞB wrote:
And one last tip: Document your code!  Someday you might not be the maintainer of this code.  If you run into the person who does have the job that person will want to do one of two things: Punch you in the nose or, Buy you a beer.  Well documented code will prevent you having as crooked a nose as I sport!

Thats a very good thing that people miss (Even am one among them) to document a code and it take some time even to understand your own code on later times. Well said Jeff I like to read these kind of threads. Smiley Happy

-----

The best solution is the one you find it by yourself
0 Kudos
Message 5 of 9
(2,783 Views)

Hi Jeff,

 

thanks for your reply. I am looking into the Producer-Consumer template and I will try to understand how that would work for me. I just want to say that the code I am developing will be mainly used by me (it is a DAQ system for some lab equipment) so no one but me will suffer for my poor programming skills. 🙂

That said, I would like to explain better what I am trying to do and how I am now planning to do it:

we have a custom made data acquisition board which will be used for data taking. Typically, the board will be powered up, configured and then used to take data whenever a trigger occurs.

Triggers are random so there is no precise timing but as a rule of thumb the rate should be lower than 1 KHz. After each trigger, the board puts the data in a circular buffer and my code needs to read it out before it is overwritten (loss of data is tolerable; mixing of data from different triggers is not).

The code itself will not manipulate the data but it is required to poll it from the buffer and save it to disk. Further analysis is done offline on the data file.

 

So, I understand I have to abandon my previous structure and move toward a design where there is a main case structure, acting as a state machine and, external to this, a while loop which puts new data in a queue. I am still a bit confused about how the external loop should work: in principle I would not want to read data while I am configuring the board, as this operation puts some rubbish in the buffer (which gets cleared when a real trigger occurs).

 

I guess I'll try to write some code and then submit it here for comments.

 

Thanks again.

Paolo

0 Kudos
Message 6 of 9
(2,754 Views)

Could you please have a look at the attached code and give me some advice on it?

It is just a skeleton program and it does what I need (sort of) but it looks ugly and the selection done in the "Idle" case is really horrible.

I tried to replace the "Case Structure" with an "Event Case" but then I did not know how to tell the code to keep reading new data.

 

Any advice would be welcome.

 

Cheers,

Paolo

 

 

p.s. To control the end of the program I took advantage of this code.

 

0 Kudos
Message 7 of 9
(2,733 Views)

@Moonself wrote:

I tried to replace the "Case Structure" with an "Event Case" but then I did not know how to tell the code to keep reading new data.


You could keep reading data using the timeout event of an event structure (with a reasonable timeout value). 

0 Kudos
Message 8 of 9
(2,726 Views)

Yes, I tried that approach but the "reasonable timeout value" is where I am afraid my code could fail badly.

Unfortunately at the moment I can only build on theoretical specifications since the hardware is being manufactured. As soon as I will have the board in my hands I will try that.


Cheers,

Paolo

0 Kudos
Message 9 of 9
(2,720 Views)