Quantcast
Channel: Measurement Studio for VC++ topics
Viewing all 660 articles
Browse latest View live

Playing a WAV file using the ANSI C functions for NIDAQMx

$
0
0

Hi,

 

I'm sorry if this is the wrong forum for this question, this is my first time here, and also my first time using the Measurement Studio functions.

I'm trying to play a WAV file over the analog channel of the NI PCIe - 6351 using C++ functions.

 

 

I know how to create a task and an Analog output voltage channel using the functions  DAQmxCreateTask and DAQmxCreateAOVoltageChan respectively. I can output a signal with a well defined math function like a sine wave by placing the samples in an array, but I need to play an audio signal which is saved in the WAV format. 

 

Can anybody help me with this please?

Any suggestions/code examples you have will be helpful.

 

Thanks.

 

 

 

 


Problem when installing Measurement Studio 2013 for C++

$
0
0

Hi,

 

I have a PC with windows 7 professional edition 64 bits and visual studio 2012.

I have first installed NI DAQmx driver (version 9.8).

 

I have installed an evaluation  edition of measurement studio 2013 (version 13.0.0.242) without selecting driver. They have been installed previously.

 

In order to install C++ Legacy Support Dependencies, i strictly follow  your document

"Measurement Studio Visual C++ MFC Legacy Support R1 for Visual Studio 2012 Readme" and particularly the section "

Install Visual C++ Dependencies from Measurement Studio 2010 Service Pack 1 or Later".

 

The installation seems to work properly. I have no error.

 

However when I want to add Include and Library Paths to my project, I can not find the directory VCNET under "Program Files (x86)\National Instruments\MeasurementStudioVS2012" path.

 

A screenshot of my directories under "MeasurementStudioVS2012" directory is in attachment.

 

Why this directory doesn't exist?

What is wrong in my installation?

 

Thanks in advanced

 

nivision.* library functions

$
0
0

Hi all,

 

I am working on a project that involves the use of the VI of IMAQ Object Tracking Options. I would like to know the details of this VI, so I double-click the VI to get the IMAQ Mean Shift Options Panel. When I look into this panel, it involves the use of a Call Library Function, which calls the function named LV_SetMeanShiftOptions whose library name or path is nivision.*.

 

I wonder if it is possible for me to know the details of the function LV_SetMeanShiftOptions and other functions in nivision.*, or are these functions in nivision.* completely confidential and unaccessable by users?

 

Thanks very much.

Cheng

PCI-6013 vs PCIe-6320

$
0
0

Hi All,

 

I am updating my software to the latest Ni Daqmx from the traditional (Legacy) and I'm having some problems.  I currently have my PCIe-6320 working with the C/C++ code that I have written and it works fine.  I use the same code to run on my PCI-6013 card and it does not work.  I am unable to get communication throught the pins on the board of the 6013 but communications work perfectly fine on my 6320.  I dont have any errors that are coming out of the code.  The code is written using the Ni Daqmx C API with calls: DAQmxCreateTask(), DAQmxCreateDIChan(), DAQmxStartTask(), DAQmxReadDigitalU8(), DAQmxStopTask(), DAQmxClearTask().

 

As I said before these calls work perfectly with the 6320 but not with the 6013.  Im not sure what the difference is between the two programmically or configuration wise but I am unable to get the older card working.  Any help is greatly appreciated as I need this urgently!

 

Patt

When I just compile example code, but It doesn't work

$
0
0

Hello,

 

I'm using the NI USB-6289

 

I want to collect the analog voltage input, so I compiled the example code which provided with DAQmx likes below : 

 

 

==========================================================================

#include <stdio.h>

#include <NIDAQmx.h>

#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else

int main(void)
{
int32 error = 0;
TaskHandle taskHandle = 0;
int32 read;
float64 data[1000];
char errBuff[2048] = { '\0' };

/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk(DAQmxCreateTask("", &taskHandle));
DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai8", "", DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle, "", 10000.0, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 1000));

/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxErrChk(DAQmxStartTask(taskHandle));

/*********************************************/
// DAQmx Read Code
/*********************************************/
DAQmxErrChk(DAQmxReadAnalogF64(taskHandle, 1000, 10.0, DAQmx_Val_GroupByChannel, data, 1000, &read, NULL));

printf("Acquired %d points\n", read);

Error:
if (DAQmxFailed(error))
DAQmxGetExtendedErrorInfo(errBuff, 2048);
if (taskHandle != 0) {
/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
}
if (DAQmxFailed(error))
printf("DAQmx Error: %s\n", errBuff);
printf("End of program, press Enter key to quit\n");
getchar();
return 0;
}

 

===================================================

 

But, when I execute above code right after the device is turned on, then, the program works well first time, 

 

But, when I execute again, then error message is generated likes below : 

====================================================

DAQmx Error: Some or all of the samples requested have not yet been acquired.

To wait for the samples to become available use a longer read timeout or read la
ter in your program. To make the samples available sooner, increase the sample r
ate. If your task uses a start trigger, make sure that your start trigger is co
nfigured correctly. It is also possible that you configured the task for externa
l timing, and no clock was supplied. If this is the case, supply an external clo
ck.
Property: DAQmx_Read_RelativeTo
Corresponding Value: DAQmx_Val_CurrReadPos
Property: DAQmx_Read_Offset
Corresponding Value: 0

Task Name: _unnamedTask<0>

Status Code: -200284
End of program, press Enter key to quit

 

============================

 

And, when I compile the below code (Continuous voltage collection), it also works well first time when the device is turned on, but when I execute again, it doesn't work!

 

(The error message is not same with the above case)

 

===========================

#include <stdio.h>

#include <NIDAQmx.h>

#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else

int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData);
int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData);

int main(void)
{
int32 error = 0;
TaskHandle taskHandle = 0;
char errBuff[2048] = { '\0' };

/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk(DAQmxCreateTask("", &taskHandle));
DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai0", "", DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle, "", 10000.0, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1000));

DAQmxErrChk(DAQmxRegisterEveryNSamplesEvent(taskHandle, DAQmx_Val_Acquired_Into_Buffer, 1000, 0, EveryNCallback, NULL));
DAQmxErrChk(DAQmxRegisterDoneEvent(taskHandle, 0, DoneCallback, NULL));

/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxErrChk(DAQmxStartTask(taskHandle));

printf("Acquiring samples continuously. Press Enter to interrupt\n");
getchar();

Error:
if (DAQmxFailed(error))
DAQmxGetExtendedErrorInfo(errBuff, 2048);
if (taskHandle != 0) {
/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
}
if (DAQmxFailed(error))
printf("DAQmx Error: %s\n", errBuff);
printf("End of program, press Enter key to quit\n");
getchar();
return 0;
}

int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData)
{
int32 error = 0;
char errBuff[2048] = { '\0' };
static int totalRead = 0;
int32 read = 0;
float64 data[1000];

/*********************************************/
// DAQmx Read Code
/*********************************************/
DAQmxErrChk(DAQmxReadAnalogF64(taskHandle, 1000, 10.0, DAQmx_Val_GroupByScanNumber, data, 1000, &read, NULL));
if (read>0) {
printf("Acquired %d samples. Total %d\r", read, totalRead += read);
fflush(stdout);
}

Error:
if (DAQmxFailed(error)) {
DAQmxGetExtendedErrorInfo(errBuff, 2048);
/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
printf("DAQmx Error: %s\n", errBuff);
}
return 0;
}

int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData)
{
int32 error = 0;
char errBuff[2048] = { '\0' };

// Check to see if an error stopped the task.
DAQmxErrChk(status);

Error:
if (DAQmxFailed(error)) {
DAQmxGetExtendedErrorInfo(errBuff, 2048);
DAQmxClearTask(taskHandle);
printf("DAQmx Error: %s\n", errBuff);
}
return 0;
}

 

============================

Acquiring samples continuously. Press Enter to interrupt
DAQmx Error: Attempted to read samples that are no longer available. The request
ed sample was previously available, but has since been overwritten.

Increasing the buffer size, reading the data more frequently, or specifying a fi
xed number of samples to read instead of reading all available samples might cor
rect the problem.
Property: DAQmx_Read_RelativeTo
Corresponding Value: DAQmx_Val_CurrReadPos
Property: DAQmx_Read_Offset
Corresponding Value: 0

Task Name: _unnamedTask<0>

Status Code: -200279

 

============================

 

I think the C code can't initailize perfectly, so I can't collect the voltage! (I'm already try adjusting the sampling rate, and the number of point and so on...)

 

What Can I do???? T.T

 

 

 

Stop pulse generation after last item of buffer

$
0
0

Hi,
I am working with NI USB 6363 and DAQmx C API. My CO task periodically generates sine half periods specified by 16 items 0.0980171, 0.290285, 0.471397, 0.634393, 0.77301, 0.881921, 0.95694, 0.995185, 0.995185, 0.95694, 0.881921, 0.77301, 0.634393, 0.471397, 0.290285, 0.0980171. This task is possible to stop by clicking on a button in GUI.

 

When the stop button is pressed, the stop function of the task is called immediatelly. But in my case is very important to wait for sending all 16 items before the task can be stopped. Is there some signal or other way in the DAQmx C API which I could use to reach described functionality?

Best regards,
Vladimir

NI-4844 OSI C++ programming

$
0
0

Hello!

I have an optical interrogator NI PXIe-4844 and I need to write my own data acquisition software using C or C++. Can anyone tell me how I can connect this module with my C++ application? I'm confused about dozens of new products like a DAQmx, an OSI, a Measurement Studio, a LabView, etc... What do I need for my task?

 

I'm sorry if I chose incorrect board for my question.

How can I synchronize line camera with galvanometers?

$
0
0

Hello, everyone,

I am Hoon-sup, Kim. I'd like to synchronize galvanometers with line san camera to implement optical coherence tomography system. As you can see the attached snippet of my c language code('each line trigger with galvo.pdf'), I imitated llgrab.c example code and imgSessionLineTrigSource2() function to trigger each line and to grab one image continually.

One image consists of 2048(Width) x 500(Height). I used GL2048L line camera and PCIe-1429 and PCI-6229. The counter0 channel is generating five hundred pulses with 30kHz frequency and then the counter0 output pulses is driving GL2048L as each line trigger mode. Measurement & Automation Explorer(MAX) was set as follows.
Trig mode: 2 variable exposure
CC1: external, Number: 0

For your information, refering to this manual(http://www.ni.com/white-paper/13786/en/), I already checked that HL Trigger each line from Encoder (Express).vi example code is working well.

Even though the acquisition time is correct as 17msec which is calculated from 500 points divided by 30kHz, I have two problems under the text based customized code as you can see the attached 'two issues.pdf' file.


First, Image is continually being shifted to the right with some ratio.
Second, backward part of the galvanometer analog output signal is sometimes being stopped abruptly with no completion.

In order to synchronizing analog output Channel with Counter Channel, I used "ao/StartTrigger" as a Counter output trigger source and I kept the order of DAQmxStartTask functions, which means that COtaskHandle first and AO0taskHandle last.

DAQmxCfgDigEdgeStartTrig(COtaskHandle,"ao/StartTrigger", DAQmx_Val_Rising);
...

DAQmxErrChk (DAQmxStartTask(COtaskHandle));
DAQmxErrChk (DAQmxStartTask(AO0taskHandle));
...

Are there any faults when I used a few of DAQmx API and IMAQ API functions in my code? Do I really need to use RTSI bus to connect framegrabber to DAQ board as 'LL Triggered Ring using RTSI from DAQ.vi' from http://www.ni.com/example/29476/en/ ? Actually I would like to resolve this synchronization issue without introducing RTSI bus. I want to know if it is possible or not.

Sincerely,
Hoon-sup, Kim


Why can VS2008 not create NI MFC Application project?

$
0
0

I have setup measurement studio 2013 evaluation for VS2008.But I cann't create NI MFC Application project in VS2008, why? It prompts that the NI MFC Application project creating fail.

xnet c code example frame Input & Output Queued Mode

$
0
0

Looking for example code for XNET CAN Frame Input & Output Queued Mode Sessions

nidcpwr

$
0
0

Hi,

 

I have installed NI DCPower v1.7. But, i could not find the examples in C language.

 

It would be great if some one guides me in finding the examples.

 

Thanks

Chakravarthy Sulva

retrieve software versions from NI licence manager

$
0
0

Hello

 

We want to retrieve the serial numbers of active licenses of our testsystems automaticaly and store the info in our database.

So it possible to retrieve data from the  NI license manager in C# 2012  (ore maybe in Labview)?.

Is there an API ?

 

thanks in advance

 

Tonnie

 

 

 

setting CAN FD baud rate in c using c driver

$
0
0

I need to set the baud rate to 2Megbit for CAN FD.  The manual and the example are not working using the set properties for Session

執行檔

$
0
0

您好!!請問一下如果使用Measurement studio原件所建立的執行檔(未使用到任何儀器)需要在其他電腦上執行,需要安裝什麼東西嗎?因為建成release後,放到其他電腦點擊後沒有反應,謝謝!!!

ps. measurement studio 8.6 VS 2005 作業系統為Wn7 32bits

 

use case and document of CNiMath::RMS() function

$
0
0

I have Measurement Studio 2013 Enterprise version for C++ program development and am looking for explanation on CNiMath::RMS() input parameter and use case. The first input parameter is "data to process" according to inline comment. Most API's specify whether time domain signals or power spectrum are expected. This one API does not explain. Would appreciate anyone who has ever used this API to share your first-hand experience. Basically, I need a function to calculate the average power of a sinewave. Thanks in advance.


Using analog output in the background

$
0
0

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

 

 

 

 

 

 

The type initializer for NationalInstruments.NI4882.Internal.GPIBdll threw an error

$
0
0

My deployed MS Visual Studio 2012 program throws an error on a target machine. The error is "The type initializer for NationalInstruments.NI4882.Internal.GPIBdll threw an error". The program was created under Windows 7. I included two NI merge modules during setup program build - mstudiogpib2010.msm and mstudiocommon2010.msm. My target machine has full admin privilege. What could be the problem here, please?

 

On a related note, where does the installer put the two required NI4882.dll and Common.dll?. Thanks.

CNiMath::CrossSpectrum() programming experience?

$
0
0

According to NiMath.h in-line comment, this function "calculates the double-sided cross power spectrum of two time-domain signals." Parameter 1 and 2 are time-domain signals as inputs. Upon return, the third parameter should contain the double-sided cross power spectrum between the two time-domain signals, in a complex form.

 

Looking at the real part, I am surprised that it contains some negative values. Can "power spectrum" be negative? Would appreciate anyone sharing your experience. Further questions:

1.  Do I need to scale the two time-domain signals?

2.  Why this function does take sampling rate into concern?

3.  There is another similar API, CNiMath::CrossPowerSpectrum(), which takes sampling frequency into account. What are the guideline while comes to decide which API to use?

 

Thanks again for your generous sharing of programming experience.

Data acquisition using cRIO-9066 and C++

$
0
0

Hi there!

I want to write a C++ application which would acquire data from some modules installed in cRIO-9066 chassis and this application have to work without LabView. How can I do it? Can I connect this chassis to my PC using NI DAQmx? Is it possible?

What is the difference between nivisa4.lib and visa64.lib

$
0
0

In 

 

C:\Program Files\IVI Foundation\VISA\Win64\Lib_x64\msc

 

There are 3 lib files: nivisa64.lib,  visa64.lib, visa32.lib

 

And in C:\Windows\System32 are the 3 corresponding .dll files located.

 

I understand that I have to link against visa64/visa32 depending on if it is a 64bit or a 32bit machine.

 

But what is nivisa64.dll and nivisa64.lib good for? Do I need it for communication with my device? What is the difference between visa and nivisa?

Viewing all 660 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>