LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to trigger data acquisition with a mouse click

Solved!
Go to solution

Hallo, I wonder if even in this troubled times there is somebody kind enough to answer an apparently simple question that  I've not been able to solve. Here it is:

I use a NI PCIe-6320 board and LabView 2014 SP1.

The board will have to acquire an analog signal on four channels, with N samples = 7K and  sampling rate= 10K

using the reference trigger so that 5K samples are acquired before the trigger and 2K samples after it. The procedure will have to be repeated many times (about 1000) with variable rate, say between 1 every 2 or 3 secs. 

Acquisition is fairly straightforward when using a digital trigger, but what I want to do is to use as a trigger the click of the mouse (or any other mouse event). And here I got stuck. Coudn't find a clue nor in the LV help, nor in the blog. To a similar question I've seen that somebody suggested to generate a digital output by a mouse click, and hardware connect the digital output of the board to the trigger input of the analog section. Not tried yet, but it looks like there must be something better than that.

Thanks a lot for your help!

Massimo

 

 

0 Kudos
Message 1 of 12
(2,632 Views)

What exactly is the problem?

 

Starting DAQ without a trigger?

Or catching a mouse event to execute the trigger?

 

Usually, starting DAQ from code is a lot easier then setting it up to wait for a trigger. I don't have DAQmx installed, so I can't help. But I'm sure the basic examples cover this.

 

Catching a mouse down is easy with an event structure. It can be done on event basis per VI and per control. For a global mouse down, you'd have to poll with the device interface. Or hook windows messages.

 

I'd also consider continues acquisition, and add the data to a buffer. Then, keep data from that buffer when an event occurred (optionally with pretrigger), dismiss the data when the wasn't a recent event. 

0 Kudos
Message 2 of 12
(2,622 Views)

Hi, thanks for the quick reply, I'll embed my answers in your text

 

Q: Problem: Starting DAQ without a trigger?

A: Yes, this is the problem. To start DAQ without a hardware trigger

 

 

Q: Or catching a mouse event to execute the trigger?

A:No, this is very easily done 

 

Q: Usually, starting DAQ from code is a lot easier then setting it up to wait for a trigger. I don't have DAQmx installed, so I can't help. But I'm sure the basic examples cover this.

A: Sorry, not so easy for me, could you identify an example? I coudn't find it

 

Q: I'd also consider continues acquisition, and add the data to a buffer.

A: Theorethically this could work, and I already tried it. But, whatever the buffer dimension, unlfess the software empies it fast enough, it will get overflowed. With the kind of sampling I'm using it does not work. It works only with very few data sampled and at a very slow pace. Not praticable. Thanks anyway.

0 Kudos
Message 3 of 12
(2,599 Views)

@neurophysiomonger wrote:

Q: I'd also consider continues acquisition, and add the data to a buffer.

A: Theorethically this could work, and I already tried it. But, whatever the buffer dimension, unlfess the software empies it fast enough, it will get overflowed. With the kind of sampling I'm using it does not work. It works only with very few data sampled and at a very slow pace. Not praticable. Thanks anyway.


You can do this very efficiently, but it has to be done the right way. With a pre allocated amount of memory, arranged in a circular buffer, it will be as efficient as it can get.

 

I don't know what you tried, but if it didn't involve pre allocated memory, it's expected to be slow. Concatenating data to an array is slow, as it rescales the array, involving potentially moving the memory...

 

Can't help you with the DAQmx, I haven't installed it. I suppose you can use an express VI, and then convert it to see it's content.

0 Kudos
Message 4 of 12
(2,531 Views)

Hi, thanks for your answer.

Unfortunately the express.vi for DAQ does not contemplate software triggering. Nor does any other .vi for the DAQ functions or .vi. 

 

About preallocated memory, I tried to allocate a very large amount of memory in the buffer (of course not in an an array), but it the time interval between triggers is too long, there will be an overflow anyway. A circular buffer might be a solution, I'll see what I can do. But still it looks to me as a rather complicated way around. What I wonder is: why can't the acquisition board be simply triggered by software and not just by an hardware input? Can NI answer that?? 

 

0 Kudos
Message 5 of 12
(2,526 Views)

@neurophysiomonger wrote:

Hi, thanks for your answer.

Unfortunately the express.vi for DAQ does not contemplate software triggering. Nor does any other .vi for the DAQ functions or .vi. 

 

About preallocated memory, I tried to allocate a very large amount of memory in the buffer (of course not in an an array), but it the time interval between triggers is too long, there will be an overflow anyway. A circular buffer might be a solution, I'll see what I can do. But still it looks to me as a rather complicated way around. What I wonder is: why can't the acquisition board be simply triggered by software and not just by an hardware input? Can NI answer that?? 


Don't program a trigger, simply start the task. IIRC; that will start it. I think you're looking for a software trigger, but you don't want a trigger at all. Without a trigger, things will start when your software tells it to.

0 Kudos
Message 6 of 12
(2,524 Views)

Hallo, I've been experimenting a little. Unfortunately, because of the lockdown, coudn't get into my lab and use the real 6320 board, so I had to simulate it in my computer at home, but shoudn't make much of a difference. 

Since the DAQ board already requires allocation of a software buffer, I was somehow reluctant to use another buffer to store data. But coundn't find any other way to synchronize DAQ with a mouse click (or any other software event). So circular buffer be it!

A nice circular buffer API developed in LV can be found here: http://www.ni.com/tutorial/7188/en/

With that, the appllication I've built works well and, inserting a proper delay, data sets can be read occurring before and after the click of the mouse.

Still, I'm wondering if there is a more straightforward way to handle DAQ directly from software. Perhaps NI may answer that?

 

0 Kudos
Message 7 of 12
(2,472 Views)
Solution
Accepted by topic author neurophysiomonger

Yours sounds like a good candidate for a technique I've posted snippets about before (and more than once).

 

This technique assumes that you don't care about what's going on during idle times between "mouse click triggers".  Just that on each mouse click, you'd like to retrieve a chunk of data from the immediate past (and perhaps some from the future too).

 

You can get behavior similar to a software-driven reference trigger this way.  (Note that you'll need to tweak the posted code with appropriate values and only fire off the DAQmx Read call in response to your mouse click.)

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 8 of 12
(2,460 Views)

Hallo Kevin, I've had a look at your snippet and sounds that it might be the right solution. Going to try that and let you know. 

Thanks a lot.

 

Massimo

0 Kudos
Message 9 of 12
(2,451 Views)
Solution
Accepted by topic author neurophysiomonger

Hi, Kevin's suggestion works great. Problem solved!

0 Kudos
Message 10 of 12
(2,429 Views)