03-04-2014 09:15 AM
Hello,
I have trouble running some daqmx tasks within a subvi (and I am really not sure why, they worked fine when not sub-vi'd).
When I run my code, I eventually get a timeout error in one of the daqmx tasks in the subvi (usually accsens or pulse 2, but it varies). the frustrating thing is that this error sometimes doesn't happen at all, and sometimes it occurs at the second stimulation, sometimes at the 7th, 10th, 63th etc. I think that either something is eating up all my memory, or that I have a race condition somewhere without realizing it (or perhaps it's something stupid).
What I try to do is the following:
The vi controls a stimulation mapping setup (I send two pulses to one of 64 channels and note if there is a twitch in return).
First, I need to set the correct current on an external machine, after which I can press the stimulate button. When I press the button, two pulses are generated. The output pulses are pulse 1 and 2, I trigger pulse 2 at the end of pulse 1.
I record the response with 4 acceleration sensors, also triggered by pulse 1 (records 1k samples at 1kHz), write these traces to file and show them in a graph (blip1 to 4).
I then decide if there was a twitch and where, store the result in an array (which stimulation, which channel of the array, which current and which response), and repeat for the next electrode. I also make two arrays to sort the electrodes in Y (twitch) and N (no twitch) for the next stimulation step.
Any ideas or help?
Thanks,
Susan
03-04-2014 09:35 AM - edited 03-04-2014 09:38 AM
You're closing your DAQ tasks in your subVI. I would think that cause an error on the second loop iteration so I can't understand why you would get it to run sometimes. Generally, you create a task, use it until you're done (inside your data collection loop or subVI), then destroy the task after all collection is complete.
Other than that I would suggest you set this up as a state machine so you can get better control over program flow without so many potential race conditions.
EDIT: My mistake, I see you're just stopping not clearing the task in mapstmrec.vi. Wire all the errors through that VI so you can see any potential warnings. Post the main part too. It's hard to debug a picture.
03-04-2014 10:06 AM - edited 03-04-2014 10:09 AM
Oops, I thought the snippet was magically clickable, sorry. Here is the main vi.
It's a bit big, but my problem in the second sequence frame. In the following frames of the sequence I do pretty much the same thing (I guess I'll run into the same trouble there, though), but with different current values and different arrays of channels (it's probably not the most elegant way of doing things, but it was the least confusing option for me).
I could make the daqmx tasks completely within the subvi and then clear them, but I was afraid that that would slow everything down. But if it makes my thing run more reliably, I'll take it.
ETA: there is one other subvi in there, it sends the channel number to a multiplexer.
03-05-2014 10:25 AM
No, you're right that is a snippet. It was rather big so I didn't notice. Your cleaned up version is much easier to read though. I can't really test anything without hardware. Have you tried profiling tools? You need the Full LabVIEW. Tools > Profile > ... You can check for memory leaks with Performance and Memory. I'll try to look deeper at your main VI when I have time...