Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Simultaneous IO with DAQmx in C or CPP

Hello,
 
I want to realise an SPI Bus with a DIO6534. Therefore I need to read and write simultaneously. In former traditional DAQ concept I simply started DIG_Block_In before DIG_Block_Out and it worked pretty fine in parallel. Hence I assume the multithreading was handled by the DAQ driver. Now I use DAQmxReadDigitalU32/DAQmxWriteDigitalU32 and it only works sequentially. I neither know if I'm doing any mistake nor can I find any suitable examples. Thanks in advance if anybody can help!
 
Here's a code snippet:

DAQmxCreateTask("", &taskHandleRead);

DAQmxCreateTask("", &taskHandleWrite);

DAQmxCreateDIChan(taskHandleRead, "Dev1/port0", "", DAQmx_Val_ChanForAllLines);

DAQmxCfgChangeDetectionTiming(taskHandleRead,"Dev1/port0/line0", "Dev1/port0/line0", DAQmx_Val_FiniteSamps , numSampsPerChanRead);

DAQmxSetDIDataXferMech(taskHandleRead, "Dev1/port0", DAQmx_Val_DMA);

DAQmxCfgInputBuffer(taskHandleRead, sampleBuffer);

//DAQmxCfgDigEdgeStartTrig (taskHandleRead, "/Dev1/PFI2", DAQmx_Val_Rising);

DAQmxCreateDOChan(taskHandleWrite, "Dev1/port2", "", DAQmx_Val_ChanForAllLines);

DAQmxSetDODataXferMech(taskHandleWrite, "Dev1/port2", DAQmx_Val_DMA);

DAQmxCfgSampClkTiming (taskHandleWrite, "OnboardClock", clockRate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, numSampsPerChanWrite);

DAQmxCfgOutputBuffer(taskHandleWrite, numSampsPerChanWrite);

DAQmxWriteDigitalU32(taskHandleWrite, numSampsPerChanWrite, false, 10.0, DAQmx_Val_GroupByScanNumber, writeArray, sampsPerChanWritten, reserved);

DAQmxStartTask(taskHandleRead);

DAQmxReadDigitalU32(taskHandleRead, numSampsPerChanRead, 5.0, DAQmx_Val_GroupByScanNumber, readArray, arraySizeInSamps, &sampsPerChanRead, reserved);

DAQmxStartTask(taskHandleWrite);

DAQmxWaitUntilTaskDone(taskHandleWrite,10.0);

DAQmxWaitUntilTaskDone(taskHandleRead,10.0);

DAQmxStopTask(taskHandleWrite);

DAQmxStopTask(taskHandleRead);

DAQmxClearTask(taskHandleWrite);

DAQmxClearTask(taskHandleRead);

0 Kudos
Message 1 of 5
(4,159 Views)
Hi!

First of all you have to start the task BEFORE you send the Read and Write Function. Otherwise there will be no comunication.
Then if you want to read and write continously you should put these funcitons into a loop. Otherwise you will just read/write once the data. That is of course wrong. Maybe you try to change this!

Greetings,
Mona
Ramona Lombardo
Applications Engineer, NI Germany
Certified LabVIEW Developer
0 Kudos
Message 2 of 5
(4,135 Views)

Hi Mona,

thanks a lot for your answer! I can't start the task for 'write' before calling 'DAQmxWriteDigitalU32'. Otherwise I would get error -200462: "Generation cannot be started, because the output buffer is empty.". In my first attempt I did it the other way around, but because of a hint of NI I changed it like it is now.

For my application, programing an SPI bus, in some cases I generate the clock with the 'write' command and use this in parallel for change detection at the 'read' command. Hence I want to use the multithreading capability of the DAQmx driver, similar to traditional DAQ driver. Implementing 'read' and 'write' in a loop would be a sequential procedure.

Regards

Tobias

 

0 Kudos
Message 3 of 5
(4,125 Views)
Hi Tobias!

Oh, ok, you are right!
Importent for your application is, that the write and read should be syncronised!!! Here you can find an example of CVI, where this is done. The only diffrence is, that they use AI instead of DI, but to change that is not that much. In line 157 is the clock set.
With that option it should work fine.

Greetings, Mona

Ramona Lombardo
Applications Engineer, NI Germany
Certified LabVIEW Developer
0 Kudos
Message 4 of 5
(4,111 Views)

Hello Mona!

Thanks for your reply.

I do not see the multithreading in the example. The way I understand the example, syncronising means sycronised by a timer tick of CVI. After a tick the digital and the analog channel are read sequentially. I'm developing my application in .NET 2003/C++. Thus I don't have a timer and I need to apply the onboard clock of the 6534 card for the 'write' functionality. But if I want to use a clock generated by the 'write' for the 'read', it can only work if 'read' and 'write' run in two independed threads!  

So, I'm missing this capability I had at the traditional DAQ driver. The description of DAQmx says it's possible. But I can neither find Examples nor any instructions...

Regards Tobias

 

0 Kudos
Message 5 of 5
(4,104 Views)