Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

simultaneous monitoring of digital input lines while running digital write task

Solved!
Go to solution

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

0 Kudos
Message 1 of 7
(5,633 Views)
Solution
Accepted by topic author zo999

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.

0 Kudos
Message 2 of 7
(5,592 Views)

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.

0 Kudos
Message 3 of 7
(5,560 Views)

@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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 7
(5,548 Views)
Thanks for answering, crossrlz, but actually I was not trying to read and write simultaneously to the same line when I got that error message. I was trying to run 2 digital input tasks simultaneously on separate lines. I was trying to create and run each task in a thread, but when I ran the 2 threads, the program created both input tasks, and started one input task, then I got the error message -50103 as the program was trying to start the second input task. So I am thinking that I can't run 2 digital input tasks at same time.
0 Kudos
Message 5 of 7
(5,541 Views)

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).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 7
(5,539 Views)

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

 

0 Kudos
Message 7 of 7
(5,504 Views)