Discussion:
Simultaneous IO with DAQmx in C or CPP
(too old to reply)
Hans Wurst
2007-01-12 15:10:10 UTC
Permalink
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);
Hans Wurst
2007-01-15 16:10:13 UTC
Permalink
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
 
RMathews
2007-01-16 13:40:08 UTC
Permalink
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


ExampleCVI.gif:
Loading Image...
Hans Wurst
2007-01-16 14:10:10 UTC
Permalink
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
 

Loading...