Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Looping Digital Output from binary data file

Hello,
 
I've been trying to write a program that will output the digital data from a binary data file and loop when finished. It also exports the internal 20 MHz sample clock. However, I have found that the data stream does not seem to be very continuous. There are long periods of time when the data going out seems to be stuck at a certain value. The code is written in DAQmx. I do have a program that is suppose to do the same thing but written in Traditional NIDAQ functions. I do not seem to see the problems there. The card I have is PCI DIO-32HS
 
A code snippet is provided below:
 
    SetStatus(DAQmxCreateTask("", &myTaskHandle));
    if (StatusOK()) {
        SetStatus(DAQmxCreateDOChan(myTaskHandle, "Dev1/port2_16", "", DAQmx_Val_ChanForAllLines));
    }
    if (StatusOK()) {
        SetStatus(DAQmxCfgSampClkTiming(myTaskHandle,NULL,SAMPLEFREQ,DAQmx_Val_Rising,DAQmx_Val_ContSamps,myBufferSize));
    }
    if (StatusOK()) {
        SetStatus(DAQmxCfgBurstHandshakingTimingExportClock(myTaskHandle,DAQmx_Val_ContSamps,SAMPLEFREQ,myBufferSize,"/Dev1/PFI5",DAQmx_Val_ActiveHigh,DAQmx_Val_High,DAQmx_Val_ActiveLow));
    }
    if (StatusOK()) {
        DAQmxSetSampClkRate(myTaskHandle, SAMPLEFREQ);
    }
   if (StatusOK()) {
  SetStatus(DAQmxWriteRaw(myTaskHandle, myBufferSize, 0, DAQmx_Val_WaitInfinitely, myBufferPtr, myWritten, NULL));
        printf("Bytes written: %i\n", *myWritten);
    }
    if (StatusOK()) {
        SetStatus(DAQmxStartTask(myTaskHandle));
    }
    while (1) {
        if (StatusOK()) {
      SetStatus(DAQmxWriteRaw(myTaskHandle, myBufferSize, 0, DAQmx_Val_WaitInfinitely, myBufferPtr, myWritten, NULL));
            printf("Bytes written: %i\n", *myWritten);
        }
    }
 
Thanks for the help,
~Jerry Wu
0 Kudos
Message 1 of 26
(7,006 Views)

Hello Jerry,

I think that the problem lies with the fact that you are using DAQmxCfgBurstHandshakingTimingExportClock.  You are using DAQmxCfgSampleClkTiming to set the rate of the output, but then you use the other call to change that timing mode to burst.  This will cause the problem that you are seeing because burst mode will not operate at a certain rate.  If you need to export the sample clock, you should use DAQmxExportSignal instead.

Please let us know if you have additional questions.

Regards,
Laura

0 Kudos
Message 2 of 26
(7,003 Views)

I tried using DAQmxExportSignal, however, it does not allow me to export the sample clock along "/Dev1/PFI5".

Thanks,

~Jerry Wu

0 Kudos
Message 3 of 26
(6,989 Views)

Hi Jerry,

Can you give us more information about how this doesn't work?  Do you get an error message?  I just simulated your device and tried it and do not see a problem. 

Regards,
Laura

0 Kudos
Message 4 of 26
(6,981 Views)

I get this error when I try to run it on the real hardware.

DAQmx Error: Specified route cannot be satisfied, because the hardware does not
support it.
Property: DAQmx_Exported_SampClk_OutputTerm
Requested Value: /Dev1/PFI5
Suggested Values: PFI3, PFI7, RTSI0, RTSI1, RTSI2, RTSI3, RTSI4, RTSI5, RTSI6

Task Name: _unnamedTask<0>

Status Code: -89136

 

The hardware I'm using is PCI DIO-32HS

Thanks,

~Jerry Wu

0 Kudos
Message 5 of 26
(6,977 Views)

Hi Jerry,

From that error message, the PCI-DIO-32HS does not support routing the sample clock to PFI5.  Have you tried using PFI3 or PFI7?  I was able to export the sample clock on a device in the same family for supported PFI lines, so I believe you should be able to do this on PFI 3 or 7.

Regards,
Laura

0 Kudos
Message 6 of 26
(6,972 Views)
I'm actually trying to upgrade the original program that does the same thing but written in Traditional DAQ functions into DAQmx functions. It seems that program was able to export the sample clock along PCLK2, which is now called PFI5. It would be great if I do not have to change which pin the sample clock is coming out of because doing so would require additional changes in the peripheral as well.
 
Thanks,
~Jerry Wu
0 Kudos
Message 7 of 26
(6,962 Views)

Hi Jerry,

That is certainly understandable.  I have a work-around for using PFI5 that I just tested with the hardware.  Before starting your task, use DAQmxConnectTerms to connect RTSI0 to PFI5.  Then, use DAQmxExportSignal to export the sample clock to RTSI0.  This will route the sample clock signal onto PFI5.  Just be aware that once you use DAQmxConnectTerms, those terminals are connected until you run DAQmxDisconnectTerms or reset the device, so you may want to disconnect the terminals at the end of your program.

Hope this helps,
Laura

0 Kudos
Message 8 of 26
(6,952 Views)

Hi Laura,

Another question, is there a maximum number of samples that functions such as DAQmxWriteRaw can handle at one time?

 

Thanks,

~Jerry Wu

0 Kudos
Message 9 of 26
(6,943 Views)

Hi Jerry,

There is not a maximum, however, you will run into memory problems with your computer and development environment if you try to handle too much data at a time.  If you have a large file that you are reading data from, you should break the data into smaller chuncks before using any write function.  I know this isn't a very concrete answer, but it will be system dependent.  How much data are you planning on writing at a time?

Regards,
Laura

0 Kudos
Message 10 of 26
(6,923 Views)