01-06-2023 11:25 AM
This seems like it should be pretty simple, but I am having some trouble. I keep getting the error shown below when I attempt to read an analog input. I'm sure that I'm just doing something fairly stupid or naive, so can someone suggest what's wrong with the DAQmx usage shown?
01-06-2023 11:33 AM
Best guess from this small piece of code is that the error comes because the hardware is in use already. You either have it open in another program (could even be test panels in NI-MAX), or in the same program you started using it but didn't stop using it, or you get this error message because this code is in a loop and you didn't stop the task in the previous loop.
01-06-2023 11:51 AM
You should add a DAQmx Clear Task after the DAQmx Read to unreserve the hardware.
Anyway, using CreateTask-Read-ClearTask in a loop is not a good idea. You should place the CreateTask before the loop and the ClearTask after the loop. I would recommend you to refer to the shipping examples.
01-06-2023 03:06 PM
Thanks, gentlemen. I will take these suggestions to heart. However, I also established that this error occurs during the very first read, so this problem involves more than just multiple iterations through the loop.
01-07-2023 11:33 AM
One other thing to consider is that you are not using the Error Line in your very minimal "program". You should almost always wire Error In and Error Out, which will give you an error when the first function that has a problem "has a problem". You don't even know if the (tiny, isolated) piece of code you attached is the source of the Error!
Next time, please attach a complete LabVIEW VI (or, even better, a complete LabVIEW Project, most easily done by right-clicking the Project folder on your disk and choosing "Send to", "Compressed (zipped) folder", then attach the result. Having executable LabVIEW code lets us "find the bug" much faster and with less "guessing".
Bob Schor
01-09-2023 04:04 PM - edited 01-09-2023 04:12 PM
Bob, you're right to say that the error line wasn't wired up. This was just a minimal initial test within a very large existing project, not yet intended as a full solution. (The problem only manifested after we added this segment, so we know that this is causing the error to occur.)
It would take quite a while before I can boil the entire project down into a reasonably sized VI. In the meantime though, I discovered that this problem occurs because we're also reading AI0 in another section of the code. The following segment produces an error. (I deliberately omitted the DAQmx reads for simplicity and because the errors appear before the read is performed.)
01-09-2023 04:54 PM
The reason you have the Error, I think, is you are asking the hardware to do two different things at the same time, namely read 250 samples from ai0 and 250 samples from ai1. The hardware knows (I certainly hope!) how to read two sequential channels at a time, so you could say "read ai0:1 at 1 kHz until you have a 2D array of size 2 x 1000 (or 1000 x 2, depending how you set up DAQmx). You might have to pry the two data channels apart (because they have different scale factors, perhaps), but you do that when you analyze (or maybe plot) the data, not when you collect it.
See if this change gets rid of the error.
Bob Schor
01-10-2023 09:07 AM
That sounds plausible. Thanks.