Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I write to the DIO 653X onboard memory then start the task?

Alright, I'm attempting to write data to the onboard memory of a 653X series PXI DIO board.  I want to do this because buffering data using the computer's RAM will be too slow for the higher speed applications I am trying to program for.  I'm using Lab Windows CVI and the latest DAQmx drivers.  Here is the code I have come up with:

#include <ansi_c.h>
#include <NIDAQmx.h>
void main()
{
 int32
  sampsWritten = 0;
int i;
 TaskHandle
  Output = 0;
 
 char
  chrBuffer[80];
 
 uInt8
  WriteArray[8]={1,0,0,0,0,0,0,0},
  WriteArray2[8]={0,0,0,0,0,0,0,0};
 
for(i=0; i < 10000; i++)
{
 DAQmxCreateTask("",&Output);
 DAQmxCreateDOChan(Output, "Output/port0/line0:7", "test", DAQmx_Val_ChanForAllLines);
 DAQmxCfgSampClkTiming (Output, "OnboardClock", 100, DAQmx_Val_Rising,DAQmx_Val_FiniteSamps, 10);
 DAQmxCfgOutputBuffer (Output, 10); 
 DAQmxWriteDigitalLines (Output, 1, 0, 10.0, DAQmx_Val_GroupByChannel, WriteArray,&sampsWritten, NULL);
 DAQmxStartTask(Output);
 DAQmxClearTask(Output);
 
 DAQmxCreateTask("",&Output);
 DAQmxCreateDOChan(Output, "Output/port0/line0:7", "test", DAQmx_Val_ChanForAllLines);
 DAQmxCfgSampClkTiming (Output, "OnboardClock", 100, DAQmx_Val_Rising,DAQmx_Val_FiniteSamps, 10);
 DAQmxCfgOutputBuffer (Output, 10);
 DAQmxWriteDigitalLines (Output, 1, 0, 10.0, DAQmx_Val_GroupByChannel, WriteArray2,&sampsWritten, NULL);     
 DAQmxStartTask(Output);
 DAQmxClearTask(Output);
}
 
 printf("\nPress ENTER to exit");
 gets (chrBuffer);
   
 
Basically I'm just trying to toggle Port0 pin 0 high and low. 
I have had problems trying to find decent examples of this application in CVI, so please don't criticize too much.
Any advice on what else I need to configure or any ways I can optimize this code?
0 Kudos
Message 1 of 4
(3,793 Views)

Hello Jakeus. 

Thank you for contacting National Instruments.

At first glance, your code appears to make sense.  When you build and run the program, does it work as you expect or are you running into some issues? 

A good program for you to get started on Digital I/O applications is available online at:

NI-DAQmx: Simple Digital I/O Example for CVI
http://zone.ni.com/devzone/cda/epd/p/id/4995

It is fairly simple, but it should give you a good outline for the process to follow when using DAQmx to write to a digital line. 

I hope this helps in your application.  If you have any further questions, we would be happy to help!

Brian F
Applications Engineer
National Instruments

0 Kudos
Message 2 of 4
(3,765 Views)
When I view the output on an oscilloscope, I do infact get a square wave, however, at a low frequency.  I did get help from another NI engineer, and he suggested using "DAQmxWriteDigitalU8" to write the data because those functions create a buffer then use DMA to perform the transfer.  Thanks for respondong and the example, I'll try it shortly to see what I can come up with.
0 Kudos
Message 3 of 4
(3,760 Views)
I managed to manipulate one of the examples to achieve what i was doing.  The maximum frequency I could achieve without any buffer problems was 500kHz (as viewed on the oscilloscope).
0 Kudos
Message 4 of 4
(3,756 Views)