05-29-2015 03:02 PM
Hello all,
I am using USB-6001 and want to develop a multiple task app in C++. I am trying to read multiple analog inputs at the same time, but get some errors. To make it simple, I copy one of the example code to read in analog data in one channel then turn it into a function. Then I call this function in thread with different pin names (such as Dev1/ai0, Dev1/ai1) and I come cross this error:
"The specified source is reserved. The operation could not be complete as specified" status code -50103
I search the forums, this may because I use hardware timing in this function, and this hardware timing cannot be use at the same time by several tasks. I may have to put all lines I want to read in one single task (such as Dev1/ai0:1). In this way I can read two lines at the same time. However, when I try this, I meet other error:
"buffer is too small to fit read data" status code -200299
So, here is my question, what should I do if I do want to read multiple analog inputs at the same time? Is the thing that hard timing cannot be use by multiple tasks true? If I have to read multiple lines at a single task, how do I set the parameters?
Solved! Go to Solution.
05-29-2015 04:37 PM
05-29-2015 04:46 PM
Thank you for your reply! I have tried to put "Dev1/ai0:1" to a single task, but I still have error, saying the buffer is 100 but the data read is 200 (I read 100 samples per channel, but now I have two channels). Can you give me some hints about this?
05-29-2015 04:55 PM
05-29-2015 06:00 PM
This is my .VI file, I stuck with this same problem.
Could you recommend me for more?
05-29-2015 11:08 PM - edited 05-29-2015 11:11 PM
Hi,
I think I have partially solved the problem. But I am using C++, so I am not sure if I can help you. Here is what I did. It is sure that we cannot read separated lines in different tasks at the same time, because there is only one internal clock inside the device. The solution is reading multiples lines in the same task. The key is, when defining the data array into which we will put the acquired data (when using the function "DAQmxReadAnalogF64 "), you have to make its size big enough to hold all acquired data, otherwise you will get a buffer error like I had before. For example, you are reading 3 lines at the same time (e.g. Dev1/ai0:2), each line you want 100 samples. Then you need to defined the data array as:
data[300]
so that you have enough space to hold all data. I hope this can help you a little bit. Good luck!
06-01-2015 12:05 AM
Now I can read Analog signal but still stuck with read only first time then not to read anymore. Any Ideas?
06-01-2015 06:47 AM
You are only reading the data once and passing those values into the loops. As I stated here, you need to take your two loops and make them one. You will have to mess around with how you stop your loop, but it will work.
Alternatively, you could have one loop that just does the reading and then use queues or notifiers to send the data to these processing loops. You may want to have a look at the Producer/Consumer.
06-01-2015 08:38 AM
Do you have more Examples with Daq Assistant? (.vi file) Thank a lot
06-01-2015 08:44 AM
Hello,
Thank you for replying, but I think you are well advanced in the topic! For most end-users, they just try to use the functions provided, once, not in a loop, without trying to look into how the function works. The problem is that, the description of the C functions are sometimes confusing. I always have to guess how actually I should set the parameters. For example, I know that the analog input ports have a "differential mode", but I still cannot find any documentation about this. I think NI has put too much attention to the Labview support, while C users are less taken care off.