08-21-2014 10:03 PM
I'm writing a multithreaded application in C on Windows 7, using the DAQmx 9.6 API and the USB-6509 device. This project requires that we constantly monitor multiple lines on the 6509 for digital input, using the change detection feature of the device. We also need to write digital output without having to stop monitoring the input lines. It is very important that the input lines be continuously monitored during the entire course of the project.
From reading the DAQmx manual, it seems that it is impossible to do a digital read at the same time that a digital write is occurring, even if these tasks are run in different threads. (Likewise I understand it is impossible to have multiple digital input tasks running simultaneously.)
It seems that it would be possible to start the task for the read (configured with change detection), pause the read, start the write task, pause the write task, then re-start the read task. But--and this is the important part--during the time the write task was running, is it possible to configure it so the read task will still monitor the lines, even if it just stores the data in the buffer during these periods? The main thing is that data not be lost.
Thank you,
Danielle
Solved! Go to Solution.
08-24-2014 10:14 PM
Each channel is independent. So you can get the input data as you output a value. You don`t need to pause each task. The two tasks are parallel.
08-26-2014 08:48 PM
Thanks! I tried it out and found that I can do digital input and output simultaneously if I do them in different tasks. But am I correct that I can't run multiple input tasks simultaneously? I tried that and got an error message -50103.
08-27-2014 06:20 AM
@zo999 wrote:
Thanks! I tried it out and found that I can do digital input and output simultaneously if I do them in different tasks. But am I correct that I can't run multiple input tasks simultaneously? I tried that and got an error message -50103.
That would only be if you are trying to read and write to the same line (resource is reserved). And by running two different tasks on the same line, one read and one write, you are changing the output enable of the line, which I'm guessing you don't want to do.
If you are just trying to verify your output, do a read from another line and connect the two lines (output and input). You will be able to run both tasks at the same time this way.
08-27-2014 03:09 PM
08-27-2014 05:33 PM
I'd like to see some code. I have had a lot of digital IO tasks open at the same time with the PXI-6509 and had absolutely no issues unless I somehow didn't to close a task (the error would show up on the next run).
08-30-2014 04:21 AM
Hi,
There's a lot of code, but what I've got is a struct for the devices that will be connected to the 6509, 1 digital input device per line.
typedefstruct device{
int networkPort; //ignore this
char *NIPort;
char *NIPin;
} Device, *PDevice;
Then in the main method I've got an array of pointers to devices PDevice pDeviceArray[MAX_THREADS];
Then for each device I create a thread and within the method called when the thread is run I create and run a read task
TaskHandle taskHandle_NI_R=0;
uInt8 data_NI_R[1];
int32 numRead_NI_R;
int32 bytesPerSamp_NI_R;
char deviceStringFull [18];
//deviceStringFull is a string created dynamically to represent a single line ie "Dev4/port2/line7"
//then code to read
DAQmxErrChk (DAQmxCreateTask("",&taskHandle_NI_R));
DAQmxErrChk (DAQmxCreateDIChan(taskHandle_NI_R, deviceStringFull,"",DAQmx_Val_ChanPerLine));
DAQmxErrChk (DAQmxCfgChangeDetectionTiming(taskHandle_NI_R,deviceStringFull, deviceStringFull,DAQmx_Val_ContSamps,1));
DAQmxErrChk (DAQmxStartTask(taskHandle_NI_R));
while(1){
DAQmxErrChk (DAQmxReadDigitalLines (taskHandle_NI_R,1,-1,DAQmx_Val_GroupByScanNumber,data_NI_R,1,&numRead_NI_R,&bytesPerSamp_NI_R,NULL));
//some other code
}
This works OK with 1 thread, but like I said when I run 2 threads, that's when I get the problem.
Thanks again,
Danielle