Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Triggering at changes of waveform with NI-DAQ 1200?

I am trying to trigger my acquisition whenever a sine wave starts, and after an acquisition , whenever it finishes. My code up till now is as follows but I cannot getr it to work. Can anyone give me any suggestions or help? I would be eternally thankful.
void sVoltage( char *Voltage, double Buffer[1000], int ulCount)
{
FILE *fptr;
char *extension = ".dat";
int i=0;

while(kbhit()); // "eat" any char already in keyboard buffer

strcat(Voltage, extension);

if ( (fptr = fopen(Voltage,"wb")) == NULL)
{
printf("Cannot open %s \n\n", Voltage);
}

else
{
// write buffer to file
for (i=0; i {
fprintf(fptr, "%f\n", Buffer[i]);
}

fclose(fptr); // close file
}
}


///////// THE MAIN /////////

void main(void)
{


// Local Variable Declarations for Analog Input:


i16 iStatus = 0;
i16 iRetVal = 0;
i16 iDevice = 1;
f64 Trigg = 0.1;
u32 PtrTrigger = 1;
f64 dVoltage_A[BuffSize];
f64 dVoltage_B[BuffSize];
f64 dVoltage_C[BuffSize];
f64 dTempVoltage = 0.0;
f64 *ptr;
char szFileVoltage[256];

i16 iChanInput_A = 2;
i16 iChanInput_B = 2;
i16 iChanInput_C = 0;
i16 iGainInput = 1;

i16 iChan1 = 0;
i16 iChan2 = 0;
i16 iChan3 = 0;
i16 iGain = 1;
i16 iFinalScanOrder[3] = {0,1,2};
f64 dSampRate = 25600.0;
f64 dScanRate = 0.0;
u32 ulCount = 20;

f64 dGainAdjust = 1.0;
f64 dOffset = 0.0;
i16 iUnits = 0;
i16 iSampTB = 0;
u16 uSampInt = 0;
i16 iScanTB = 0;
u16 uScanInt = 0;
static i16 piBuffer[1000] = {0};
static f64 pdVoltBuffer[1000] = {0.0};

i16 iDAQstopped = 0;
u32 ulRetrieved = 0;

i16 iNumMUXBrds = 0;
i16 iNumChans = 3;
static i16 piChanVect[3] = {0, 1, 2};
static i16 piGainVect[3] = {1, 1, 1};
i16 iIgnoreWarning = 0;
u32 i =0;

char tmpbuf[128];




// Capture settings, initialise all user-specified variables

printf("Input name of file, with path, to which you want to save the current data: ");
scanf("%s\n", szFileVoltage);

printf("Enter the Voltage Threshold for the data acquisition trigger: ");
scanf("%d\n", Trigg);

// printf("Enter the time interval for which data acquisition is to take place: ");
// scanf("%d\n", Interval);


// Pointer is 1 when closing, -1 to open, or at least what I understand by them
// while( PtrTrigger > 0 )
// {
// iStatus = AI_VRead(iDevice, iChanInput_A, iGainInput, &dVoltage_A[i]);
//
// iRetVal = NIDAQErrorHandler(iStatus, "AI_VRead", iIgnoreWarning);
//
// printf("The Voltage at AI channel %d is %lf volts. \n", iChanInput_A, dVoltage_A[i]);
//
//
// ptr = &dVoltage_A[i];
//
// if (*ptr >= Trigg)
// {
// //TRIGGER HERE
// iStatus = Lab_ISCAN_Op(iDevice, iNumChans, iGain, piBuffer,
// ulCount, dSampRate, dScanRate, iFinalScanOrder);

// iRetVal = NIDAQErrorHandler(iStatus, "Lab_ISCAN_Op", iIgnoreWarning);
//
// iStatus = SCAN_Demux(piBuffer, ulCount, iNumChans, iNumMUXBrds);
//
// iRetVal = NIDAQErrorHandler(iStatus, "SCAN_Demux", iIgnoreWarning);
////
// iStatus = DAQ_VScale(iDevice, iChan1, iGain, dGainAdjust, dOffset,
// ulCount, piBuffer, pdVoltBuffer);
//
// iRetVal = NIDAQErrorHandler(iStatus, "DAQ_VScale", iIgnoreWarning);
//
//
//// //SAVE

// Set time zone from ZT environment variable. If TZ is not set
// the operating system is queried to obtain the default value
// for the variable
// _tzset();

//Acquire operating system-style time
// _strtime(tmpbuf);
//
// // Get rid of colon
// tmpbuf[2]=tmpbuf[3];
// tmpbuf[3]=tmpbuf[4];
// tmpbuf[5]=tmpbuf[7];
// tmpbuf[6]=tmpbuf[8];
// tmpbuf[9]='\0';
//
// Concatenate the strings
// strcat(tmpbuf, szFileVoltage);

// sVoltage(tmpbuf, pdVoltBuffer, ulCount);

// Check for buffer boundry value
// if (strlen(szFileVoltage) >= 256)
// break;

// PtrTrigger = -1;

// }


// else if (*ptr < Trigg)
// {
// if (i =! BuffSize)
// {
// i = i++;
// }
// else if (i > BuffSize)
// {
// i = 0;
// }
// }
// }
//
//
// while( PtrTrigger < 0 )
// {
// iStatus = AI_VRead(iDevice, iChanInput_A, iGainInput, &dVoltage_A[i]);
//
// ptr = &dVoltage_A[i];
////
// if ((*ptr == 0) && (dVoltage_A[(i-1)] == 0))
// {
// //TRIGGER HERE
// iStatus = Lab_ISCAN_Op(iDevice, iNumChans, iGain, piBuffer,
// ulCount, dSampRate, dScanRate, iFinalScanOrder);
//
// iRetVal = NIDAQErrorHandler(iStatus, "Lab_ISCAN_Op", iIgnoreWarning);
//
// iStatus = SCAN_Demux(piBuffer, ulCount, iNumChans, iNumMUXBrds);
//
// iRetVal = NIDAQErrorHandler(iStatus, "SCAN_Demux", iIgnoreWarning);
////
// iStatus = DAQ_VScale(iDevice, iChan1, iGain, dGainAdjust, dOffset,
// ulCount, piBuffer, pdVoltBuffer);
//
// iRetVal = NIDAQErrorHandler(iStatus, "DAQ_VScale", iIgnoreWarning);
//
//
// //SAVE
//
// // Set time zone from ZT environment variable. If TZ is not set
// // the operating system is queried to obtain the default value
// // for the variable
// _tzset();
//
// //Acquire operating system-style time
// _strtime(tmpbuf);
//
// // Get rid of colon
// tmpbuf[2]=tmpbuf[3];
// tmpbuf[3]=tmpbuf[4];
// tmpbuf[5]=tmpbuf[7];
// tmpbuf[6]=tmpbuf[8];
// tmpbuf[9]='\0';
////
// Concatenate the strings
// strcat(tmpbuf, szFileVoltage);
//
// sVoltage(tmpbuf, pdVoltBuffer, ulCount);
//
// // Check for buffer boundry value
// if (strlen(szFileVoltage) >= 256)
// break;
//
// PtrTrigger = 1;
//
// }
//
//
// else
// {
// if (i =! BuffSize)
// {
// i = i++;
// }
// else if (i > BuffSize)
// {
// i = 0;
// }
// }
// }


}
0 Kudos
Message 1 of 7
(4,517 Views)
Hy you use a lot. Maybe it's better to work with ActiveX components. Make your code much easier

Regards
0 Kudos
Message 2 of 7
(4,517 Views)
Probably, but at this moment I have to program this fast and Active X needs time to program the individua l components unless you buy a Labview or something similar. In addition I do not know how to program the individual compoenets and objects. Can you give me any help on how to do this with straight C?
0 Kudos
Message 3 of 7
(4,517 Views)
Normally when you use activex, you can do everything int the component and to start you have to do the following:
configure
start
and to stop:
stop

Regards

Stefan
0 Kudos
Message 4 of 7
(4,517 Views)
... and how do I setup the object. Do you have a very small example that could show me and lead me the way?
Thank you.

Regards,
0 Kudos
Message 5 of 7
(4,517 Views)
Here are a few examples

Regards

Stefan
0 Kudos
Message 6 of 7
(4,517 Views)
Thank you. But you still need componentworks to run the programs. I do not have any measurement studio, I just have visual C++.

Regards,
Iliana
0 Kudos
Message 7 of 7
(4,517 Views)