Home > Back-end >  Read the Tek oscilloscope waveform timeout problems
Read the Tek oscilloscope waveform timeout problems

Time:09-21

younger brother recently in an oscilloscope, the requirement is to use c + + read is captured by the oscilloscope waveform data, according to provide routine FORMATIO, CPP, address after running, I have modified the resources into ReadWaveform (ViSession vi, long * elements) function, read
//Get the width of element field.
Status=viScanf (vi, "% c", & amp; C);
If (the status & lt; VI_SUCCESS) goto the error;
Assert (c & gt;='0' & amp; & C & lt;='9');
Times wrong for TIMEDOUT or trigger an assertion,
Paste the code below, request your guidance!

Younger brother can read ID of the oscilloscope, set the various properties, but is unable to read waveform data,
For three weeks, sorry ~ ~ helpless turned to SIRS great god!

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include
#include
#include
#include
#include

//This function reads the currently selected waveform and returns
//it as an array of doubles.
Double * ReadWaveform (ViSession vi, long * elements) {
ViStatus status;
Float yoffset ymult;
ViChar buffer [256].
ViChar c;
Long count, I;
Double * PTR=NULL;
Unsigned char szBuff [256]={0};

Assert (elements!=NULL);

Status=viSetAttribute (vi, VI_ATTR_WR_BUF_OPER_MODE VI_FLUSH_ON_ACCESS);
Status=viSetAttribute (vi, VI_ATTR_RD_BUF_OPER_MODE VI_FLUSH_ON_ACCESS);

//Turn headers off, this top service parsing easier
Status=viPrintf (vi, "header off \ n");
If (the status & lt; VI_SUCCESS) goto the error;

//Get the record length value
Status=viQueryf (vi, "hor: reco? Ld \ n ", "%", elements);
If (the status & lt; VI_SUCCESS) goto the error;

//Make sure the start and stop values for the curve query match the full record length
Status=viPrintf (vi, "data: start 1; Data: stop % d \ n ", * elements);
If (the status & lt; VI_SUCCESS) goto the error;

//Get the yoffset to help calculate the vertical values.

Status=viQueryf (vi, "WFMOutpre: YOFF? \ n ", "% f", & amp; Yoffset);
If (the status & lt; VI_SUCCESS) goto the error;

//Get the ymult to help calculate the vertical values.
Status=viQueryf (vi, "WFMOutpre: YMULT? \ n ", "% f", & amp; Ymult);
If (the status & lt; VI_SUCCESS) goto the error;

//Request 8 bit binary data on the curve of the query
Status=viPrintf (vi, "DATA: ENCDG RIBINARY; WIDTH 1 \ n ");
If (the status & lt; VI_SUCCESS) goto the error;

//Request the curve
Status=viPrintf (vi, "CURVE? \n");
If (the status & lt; VI_SUCCESS) goto the error;

//Always flush the if a viScanf follows a viPrintf or viBufWrite.
Status=viFlush (vi, VI_WRITE_BUF | VI_READ_BUF_DISCARD);
If (the status & lt; VI_SUCCESS) goto the error;

//Get the first char and validate
Status=viSetAttribute (vi, VI_ATTR_RD_BUF_OPER_MODE VI_FLUSH_DISABLE);
Status=viScanf (vi, "% c", & amp; C);
If (the status & lt; VI_SUCCESS) goto the error;
Assert (c=='#');
//run here error
//Get the width of element field.
Status=viScanf (vi, "% c", & amp; C);
If (the status & lt; VI_SUCCESS) goto the error;
Assert (c & gt;='0' & amp; & C & lt;='9');

//Read element characters
Count=c - '0';
For (I=0; I & lt; The count. I++) {
Status=viScanf (vi, "% c", & amp; C);
If (the status & lt; VI_SUCCESS) goto the error;
Assert (c & gt;='0' & amp; & C & lt;='9');
}

//Read waveform into allocated storage
* PTR=(double) malloc elements (* * sizeof (double));

For (I=0; I & lt; * elements; I++) {
Status=viScanf (vi, "% c", & amp; C);
If (the status & lt; VI_SUCCESS) goto the error;
PTR [I]=(((double) c) - yoffset) * ymult;
}

Status=viFlush (vi, VI_WRITE_BUF | VI_READ_BUF_DISCARD);
If (the status & lt; VI_SUCCESS) goto the error;

Return PTR.

Error:
//Report the error and the clean up
ViStatusDesc (vi, status, buffer);
Fprintf (stderr, "failure: % s \ n", buffer);
If (PTR!=NULL) free (PTR);
return NULL;
}


//This program reads a waveform from a Tektronix
//TDS scope and writes the floating point values to
//stdout.
Int main (int arg c, char * argv [])
{
ViSession rm=VI_NULL, vi=VI_NULL;
ViStatus status;
ViChar buffer [256].
Double * WFM=NULL;
Long elements, I;

//Open a default Session
Status=viOpenDefaultRM (& amp; The rm);
If (the status & lt; VI_SUCCESS) goto the error;

//Open the gpib device at primary address 1, gpib board 8

//because I am using usb and modifications for usb: : x0699:0:0 x03a3: : C011293: : INSTR
Status=viOpen (rm, "GPIB8: : 1: : INSTR VI_NULL, VI_NULL, & amp; Vi);

If (the status & lt; VI_SUCCESS) goto the error;

//Read waveform and write it to stdout
WFM=ReadWaveform (vi, & amp; Elements);
If (WFM!=NULL) {
For (I=0; I & lt; Elements; I++) {
Printf (" % f \ n ", WFM [I]);
}
}

//Clean up
If (WFM!=NULL) free (WFM);
ViClose (vi);//Not men, but top service things a bit more understandable
ViClose (rm);

return 0;

Error:
//Report the error and the clean up
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related