Using analog output in the background

Hi,
I need to use the analog output channel on a NI PCIe-6351 to play an audio signal, and while the signal plays i need make some changes the UI dialog box, is it possible for me to move the playing of the audio to the background and proceed with program execution?
Here is a simple piece of code that explains what I'm trying to do: 
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<math.h>
#include<string.h>
#include<memory.h>
#include<wchar.h>
#include "sndfile.h" //include file for the sound library
#include "NIDAQmx.h"
#define DAQmxErrChk(functionCall) { if( DAQmxFailed(error=(functionCall)) ) { goto Error; } }
float *fWavSample;
SNDFILE *SoundFile;
SF_INFO SoundFileInfo;
int iNoOfSamples=0;
int32 error=0;
TaskHandle AOtaskHandle = 0;
float64* AIOSample;
char errBuff[2048]={'\0'};
int32 fnCreateTask(TaskHandle *AOTaskHandle)
int32 error=0;
DAQmxErrChk(DAQmxCreateTask("", AOTaskHandle));
Error:
return error;
int ReadWavFile()
//Open the wav file for reading
SoundFile=sf_open("sin_10s.wav",SFM_READ,&SoundFileInfo);
//Check if file is opened sucessfully
if (SoundFile == NULL)
puts("File not opened");
return FALSE;
//allocate memory for the buffer that is to hold the wav data&colon;
fWavSample = new float[SoundFileInfo.channels * SoundFileInfo.frames];
iNoOfSamples = SoundFileInfo.channels * SoundFileInfo.frames;
//Read data into the float structure that has been copied in
sf_readf_float(SoundFile, fWavSample, SoundFileInfo.frames);
//Allocate memory for the structure that is to hold the sound samples
AIOSample = new float64[iNoOfSamples+660];
//Copy wavefile data into the new float64 array (needs to be typecasted to float64)
int i=0;
for(i=0;i<(SoundFileInfo.channels * SoundFileInfo.frames);i++)
AIOSample[i] = (float64)fWavSample[i];
//After the float64 array has been filled, release the memory used by fWavSample
free(fWavSample);
return 0;
int main(int argc, char** argv)
DAQmxErrChk(fnCreateTask(&AOtaskHandle));
//Create an analog out channel
DAQmxErrChk (DAQmxCreateAOVoltageChan(*(&AOtaskHandle),"Dev1/ao1","",-10.0000000,+10.00000,DAQmx_Val_Volts,NULL));
//16 bit output resolution needed, sampling rate matched to the WAV file's
DAQmxErrChk (DAQmxCfgSampClkTiming(AOtaskHandle,"",44100.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
//Set the output to trigger on a rising edge on PFI6
//DAQmxErrChk (DAQmxCfgDigEdgeStartTrig (AOtaskHandle,"PFI6",DAQmx_Val_Rising));
//Start the task in the background
DAQmxStartTask(AOtaskHandle);
ReadWavFile();
DAQmxErrChk(DAQmxWriteAnalogF64(AOtaskHandle,(SoundFileInfo.channels * SoundFileInfo.frames),true,10.0, DAQmx_Val_GroupByChannel,AIOSample,NULL,NULL));
printf("Playing audio\n");
Error:
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
//puts(errBuff);
puts(errBuff);
return TRUE;//DefWindowProc(hwndmon,message,wParam,lParam);
getch();
The program reads a 10 seconds long 1kHz sine wave signal from a WAV file and plays it over AO0.
I want the program to  print "Playing Audio" on the console window while the audio is still playing, i.e when DAQmxWriteAnalogF64 is executing.
I'm using Visual Studio 2005 on Windows XP and an NI PCIe6351.
I'd really appreciate any help I can get.
Thanks a lot!
RaziM

Hi RaziM, 
It sounds like you will need to implement some sort of multithreading to accomplish playing audio in the background and also making changes in the UI dialog box in the foreground. Since DAQmx is thread safe this should definitely be possible, but it will probably take a little more work on your part.
You may want to take a look at this page which gives a walkthrough to Multithreading with a Background component, http://msdn.microsoft.com/en-us/library/ywkkz4s1.aspx
Here is another forum post about how DAQmx runs multiple threads, http://forums.ni.com/t5/Measurement-Studio-for-VC/DAQmx-how-does-it-multithread/td-p/221953
I hope some of this helps!
Rachel M.
Applications Engineer
National Instruments

Similar Messages

  • Smartform output in the background

    Hello all,
    Now I met a problem about smartform output in the background:
    The default printer is LP01. When I execute the program which calls this smartform in background, I change the printer to LP03.
    Then I use the t-code:SP02 and find the printer is LP01 not LP03.
    (But if I use the hardcode 'LP03', the printer is changed to LP03)
    What can i do change the printer to LP03?
    ---part of my code:
    DATA: ls_pri_params         TYPE pri_params,
          ls_control_parameters TYPE ssfctrlop,
          lv_print              TYPE sypdest,
          lv_valid              TYPE bool,
          ls_output             TYPE ssfcompop,
          lv_repid              TYPE syrepid.
      CALL FUNCTION 'GET_PRINT_PARAMETERS'
        EXPORTING
          mode                   = 'BATCH'
          report                 = lv_repid
        IMPORTING
          out_parameters         = ls_pri_params
          valid                  = lv_valid.
      lv_print = ls_pri_params-pdest.
      ls_output-tddest = lv_print.
    ls_output-tddest = 'LP03'.
      CALL FUNCTION '/1BCDWB/SF00000004'
        EXPORTING
          output_options     = ls_output
          user_settings      = space.
    Thanks in advance!

    Hi Nina,
    You can use sy-batch. See the following codes:
    IF SY-BATCH = 'X'. "means program is executed in the background.
       ls_output-tddest = 'LP03'.
    ELSE.
       ls_output-tddest = lv_print.
    ENDIF.
    Regards,
    Hendy

  • PCI Card for Analog output in the range of 10mv

    dear ni,
                    I want to know about the PCI card that can be generate analog output in the range of maximum 10mv. i  am going to use for caliberation of loadcell, strain gauges devices.
    could you tell me on which PCI card will support this type of application.
    Regards,
    Balaji DP

    Try:  http://www.ni.com/dataacquisition/
    These have analog output voltages < 10V:   http://sine.ni.com/nifn/cds/view/main/p/sn/n12:7604,n3:7853/lang/en/nid/1036/ap/daq
    You need something with a high bit count to get good resolution at 10 mV, such as the PCI-6010 which has a 16 bit D/A.   
    Here are the minimum voltage specs for the 6010:
    Minimum Voltage Range
    -0.2..0.2 V
          Range Accuracy
    283 µV
          Range Sensitivity
    6.4 µV
    Message Edited by vt92 on 11-18-2009 07:56 AM
    "There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal

  • How can i deliver a single pulse of varying amplitude using Analog output and USB-6251?

    I am trying to generate an analog output for the following waveform:
    Pulse width: 300 usec, Frequency 40 Hz, Amplitude is following a sine wave with a 2 second period.
    My approach is: Use an async timer with 1/[40 Hz] sec  interval. I set the DAQ output rate at 1 MHz and the approach has been to generate and write 300 samples of the amplitude I need to send out, then wait for the next async interval callback , update amplitude etc etc.  The assumption is that once the 300 samples are written and the task started , a 300 usec pulse would be sent out , task then stopped and then the analog output would be set to 0 waiting for he next pulse.  The reality is that I get a stream of pulses of 300 usec which last the whole timer interval. 
    So , trying to establish whether what I am trying to do is feasible without actually sending a large array to the USB-6251 which would write zeros for the period after 300 usec.
    Here is my timercallback code for review:
        switch (event)
            case EVENT_TIMER_TICK:
                DAQmxErrChk(DAQmxStopTask(TaskAnalog));
    Determine Voltage value algorithm here
                //Generate Waveform and start Task
                //Prepare AO arr
                for (k=0;k<300;k++)
                    AOArr[k] = 0;
                    if (k<G_PulseWidth)
                    AOArr[k] =  VOLTAGE_OUTPUT;
                if (AOArr!=NULL)
                    DAQmxErrChk(DAQmxWriteAnalogF64 (TaskAnalog, (int32) 300 , 0, DAQmx_Val_WaitInfinitely, DAQmx_Val_GroupByChannel , AOArr, &sampsPerChanWritten, NULL));
                DAQmxErrChk(DAQmxStartTask(TaskAnalog));
                break;
    Thanks

    I did resovle the issue I encountered. It was due to bad configuration of the Task.
    My initial configuration was:
    DAQmxErrChk(DAQmxCfgSampClkTiming(TaskAnalog, "",1.0E+06, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps , 300 * 1.0E+06));
    which should be:
    DAQmxErrChk(DAQmxCfgSampClkTiming(TaskAnalog, "",1.0E+06, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps , 300));      
    THis did it. works very well.
    THanks

  • Count 4th consecutive pulses from the analog output of the encoder

    Hi
    Iam getting analog output from the encoder and i want to count the 4th peak of the analog signal. Kindly suggest the best method Once 4th pulse is detected counter will increments.
    Pl refer the encoder output .
    Thanks
    Attachments:
    encoder sig.JPG ‏26 KB

    Whatever you've counted using your logic, divide it by 4 and convert it to an integer (towards negative infinity)..!!
    This should work.
    I am not allergic to Kudos, in fact I love Kudos.
     Make your LabVIEW experience more CONVENIENT.

  • Using a photo as the background when creating a book.

    In the 08 version, the photo background could be used no matter which page layout was selected. For some unknown reason with 09, you can only use a photo as the background when you select "two" and click on the choice that has one picture frame as the page layout. When other layouts are selected, to include "two" with the two pictures frames, when you try to drag a photo into the background it will take that picture and add a photo to the page, but not as the background. Instead of having a photo in the background you went from two frames to three, or three to four, etc., with a blank background.

    I got it to work. I went to another theme, added the photo to the background and then went back to the Travel theme. I got it to stick. I also could change the layout to more or fewer photos per page and keep the background photo. Not the best solution but at least it worked. Be sure to post a bug report at http://www.apple.com/feedback/iphoto.html
    OT

  • When using the analog inputs and analog outputs of the PCI-7344, what is the conversion between the voltage entering the card to counts? Similarly, what is the conversion between counts to voltage at the output of the card?

    I am using the PCI-7344 to control my system. The analog inputs are connected to the output of my system while the analog outputs serve as feedback to the system. The system is a servo. I want to know what is the conversion between the voltage read at the input, to card counts, and finally to the voltage output to the system.

    Carole,
    If you are trying to do analog feedback with a servo motor, Chapter 14 of the manual talks about how to set up the torque feedback. Also linked below is a LabVIEW example of analog feedback.
    Chapter 14
    NI-Motion User Manual
    Automatic Analog Feedback with FlexMotion example
    A. Talley
    National Instruments

  • How do I configure 128 channels of DIO and 128 channels of Analog output with the availabili​ty of 3 pci slots

    I have only 3 slots of PCI or 4 slots of ISA bus, I want to configure with the minimum possible modules to attain 128 channels of DIO and 128 channels of analog output. This is inturn fed to the PCM (Pulse code Modulator). The cards will be placed in industrial PC.

    Associate Engineer-Marketing,
    Using just those 3 PCI slots you're not going to be able to get the 128 analog output channels. You will probably want to go either the MXI-3 (PCI bus extender) to a PXI chassis or E Series DAQ card to a SCXI chassis for such a high channel count system. Which analog output cards and which digital I/O cards you will want depends on your application. You will have to decide whether you will need static or dynamic analog output as well as whether you need clocked digital I/O or not. I highly recommend contacting our internal sales department at 1-800-433-3488. They are great at helping specify systems.
    Ames
    Applications Engineering
    National Instruments

  • Using analog outputs in labview with

    I have recently started using the USB personal measurement device PMD1208-LS from measurement computing with labview. I am having problems with using the analog outputs in labview i keep getting error message 41 "This function can not be used with this board" The outputs are working fine when tested with the supplied software but not when using the Aout vi in labview. has anybody else had problems with this and know how to resolve them? I have the analog inputs all working fine in labview.
    Thanks

    I have used the PMD12208FS and I used this vi to use the analog outputs for it.  I obtained it from Measurment Computing ftp site.  The data value is in mV.  Hope this helps.
    Attachments:
    PMD1208FS_AOut_lv61.vi ‏17 KB

  • How to check the ALV output for the background job

    Hi Guru,
    We are having a cutomized report which will display the result like a ALV report.
    We configured it as an background job, after the completion of the background job, it will send the result to the SPOOL, and we can use SP02 to check the output,
    But it is not easy for user to directly check the result easily, is there an method we can save it as an spreadsheet and send the output to a specific location or mailbox and then user can check it easily
    thanks,

    In SM37 ,select the Job > Spool > Select Spool No > Display Contents > Here it will show you the Output of the Report.Now select Ctrl +Shift + F12 , it will ask you to save the Spread sheet in specified location.
    Best Regards,
    Ankur

  • Can I use my photos on the background?

    I've a iPod nano from the 6 generation. Can I use my own photos on the background from my iPod?

    As of right now you cannot.
    B-rock

  • While using a BDC in the background for some documents its hanging.

    Hi All,
    I had used BDC call transaction program and i am scheduling the program in the background. Normally it works fine but for some quotes it hangs and takes a long time. So its not going to other quote. Any solution how to kill the hanged quote and goto next one?

    Well, then you need to determine why (for which orders), the process is hanging. Compare with other orders, do a performance check, etc. There is no way for us to determine what the problem in this particular case is. We just don't have enough information to help you out here.

  • Is any extra isolation required when using Analog output to dirve higer power circuitry?

    I want to connect the analog output of a DAQcard-1200 to a current amplifier to give 5A and a tranformer to give approx 200V, is any extra isolation required to protect the card?

    Hello;
    As long as the maximum current that the board can source is taken in consideration and the input impedance of the external circuitry is high enough to prevent signal reflections back to the DAQ board, you should be good to go.
    However, since the protection circuitry can be built with such little budget, I wouldn't take my chances. I would go ahead and include the protection circuitry anyway.
    Regards
    Filipe A.
    Applications Engineer
    National Instruments

  • Is It Possible To Use A Video in the Background?

    Can I use a video from youtube in the background and then set it on repeat and mute it too?
    Is it possible to do it on full screen?

    Muse does not have a built-in feature for it, but museGrid has created a widget for it.
    Fullscreen Video Background | Adobe Muse Widget | museGrid.com

  • Output after the background job finished successfully

    Hi All,
    We executed a Dunning job  in the background (sm37) and the job finished succesfully.  How to check whether the job has created an output ? Where to look for the output ?
    Regards
    Shiva

    You can check the spool request of your job via SM37 or SMX. Go to SM37 select your job and check the spool request.
    Regards
    Subhash

Maybe you are looking for

  • What are the following Fields meant to contain...?

    What info are the following Fields in iTunes meant to contain? 'Comments', 'Description', 'Category', 'Grouping'? Thanks.

  • JCO Connection issue

    Dear All, I have created WebDynpro  application by importing track. When I deploy the application, it say, Deployment completed with warning. The warning is "Clusterwide exception: Failed to prepare application". Here I guess I need to find out which

  • What happens if I purge the central cache in Bridge?

    I am getting a window that says Bridge has encountered a problem, unable to read the central cache and that I should try to purge the central cache. So what happens? I do photography and have lots of photo files with associated previews. What are the

  • Airplay itunes denon avr-x3000

    I have a problem with Itunes on my Macbook Pro, after I changed the router from Netgear CG3100 to a Netgear CG3700, you will see it with "unknown error occurred (-6700)" when I try to connect to Airplay in Itunes ... On my old router it worked fine,

  • Date format error in Search help

    Hi, I am using standard search help in my ABAP webdynpro application.It is related to payscale group (field P0008-TRFGR). It works fine if I do not specify any date but gives a error message "Enter date in the format __.__.____ "   irrespective of th