Tektronix Technical Forums are maintained by community involvement. Feel free to post questions or respond to questions by other members. Should you require a time-sensitive answer, please contact your local Tektronix support center here.

MDO 3014 Visual C++ program cannot save waveform data

Post Reply
ucmcob
Posts: 1
Joined: December 24th, 2016, 5:15 pm
Country: United States

MDO 3014 Visual C++ program cannot save waveform data

Post by ucmcob » December 24th, 2016, 6:14 pm

Hello,

I'm programming a VC++ program to remotely control our MDO 3014 (via USB port) to acquire a single waveform, then transfer the waveform data to PC disk and save it as .csv format.

I can see the waveform acquired successfully from oscilloscope screen. But the data cannot be saved to PC. I've tried different ways to save the data, unfortunately, no one works.
Any suggestions are appreciated!
Thanks.

Code: Select all

int main(void)
{
	ViSession rm = VI_NULL;
	ViSession vi = VI_NULL;
	ViStatus status = 0;
	ViChar	buffer[256] = {};
	ViUInt32 retCnt;

	// Open a default Session
	status = viOpenDefaultRM(&rm);
	if (status < VI_SUCCESS) goto error;	
	// Open the usb device
	status = viOpen(rm, "USB::0x0699::0x0408::B010275::INSTR", VI_NULL, VI_NULL, &vi);
	if (status < VI_SUCCESS) goto error;	
	// Set timeout to 5 seconds
	status = viSetAttribute(vi, VI_ATTR_TMO_VALUE, 50000);
	if (status < VI_SUCCESS) goto error;		
	//Turn on channels 1
	status = viWrite(vi, (ViBuf) ":SELECT:CH1 1", 50, &retCnt);
	if (status < VI_SUCCESS) goto error;	
	//Set aquire mode to SAMPLE
	status = viWrite(vi, (ViBuf) ":ACQUIRE:MODE SAMPLE", 20, &retCnt);
	if (status < VI_SUCCESS) goto error;
	
	status = viWrite(vi, (ViBuf) ":ACQUIRE:STOPAFTER SEQUENCE", 27, &retCnt);
	if (status < VI_SUCCESS) goto error;
	
	//Set CH1 as the source
	status = viWrite(vi, (ViBuf) ":DATA:SOURCE CH1\n", 17 , &retCnt);
	if (status < VI_SUCCESS) goto error;
	//Set encoding to ribinary
	status = viWrite(vi, (ViBuf) ":DATA:ENCDG SRIBINARY\n", 22 , &retCnt);
	if (status < VI_SUCCESS) goto error;
	//Set the data to collect
	//TODO:: set the data to start at 1 and stop and record length
	status = viWrite(vi, (ViBuf) ":DATA:START 1\n", 14 , &retCnt);
	if (status < VI_SUCCESS) goto error;
	status = viWrite(vi, (ViBuf) ":DATA:STOP 10000\n", 17 , &retCnt);
	if (status < VI_SUCCESS) goto error;
	//Set the destination to REF1
	status = viWrite(vi, (ViBuf) "DATA:DESTINATION REF1", 22 , &retCnt);
	if (status < VI_SUCCESS) goto error;
	//Set the number of bytes
	status = viWrite(vi, (ViBuf) "WFMOUTPRE:BYT_NR 1", 20 , &retCnt);
	if (status < VI_SUCCESS) goto error;
    	//Set waveform save format to SPREADSHEET
	status = viWrite(vi, (ViBuf) "SAVE:WAVEFORM:FILEFORMAT SPREADSHEET", 40, &retCnt);
    	if (status < VI_SUCCESS) goto error;

	//Get the curve
	status = viWrite(vi, (ViBuf) "CURVE?\n", 8, &retCnt);
	if (status < VI_SUCCESS) goto error;
	
	status = viWrite(vi, (ViBuf) ":SAVE:WAVEFORM REF1, \"ref1.csv\"", 100, &retCnt);
	if (status < VI_SUCCESS) goto error;
	status = viWrite(vi, (ViBuf) ":SAVE:WAVEFORM CH1, \"ch1.csv\"", 100, &retCnt);
	if (status < VI_SUCCESS) goto error;
	status = viWrite(vi, (ViBuf) "SAVE:WAVEform ALL, \"all.csv\"", 100, &retCnt);
	if (status < VI_SUCCESS) goto error;
	
	viClose(rm);
	return 0;
error:
	// Report error and clean up
	viStatusDesc(vi, status, buffer);
	fprintf(stderr, "failure: %s\n", buffer);
	if (rm != VI_NULL) {
		viClose(rm);
	}
	system("pause");
	return 1;
}

David N
Tektronix Applications
Tektronix Applications
Posts: 550
Joined: July 31st, 2008, 8:26 am

Re: MDO 3014 Visual C++ program cannot save waveform data

Post by David N » January 3rd, 2017, 10:15 am

There are several remote programming examples in the "Remote Instrument Communication Examples" forum group at: viewforum.php?f=580. You may find one of them helpful to your programming situation.

tekzilla

Re: MDO 3014 Visual C++ program cannot save waveform data

Post by tekzilla » January 4th, 2017, 5:03 am

The SAVE:WAVEFORM command saves the selected waveform(s) to the scope's internal memory, not to the controlling computer.

The best way to get waveform data to the controlling computer programmatically is to use the CURVE? query, which I see you've written in your script. Sending the CURVE? query to the scope causes it to put the current waveform data into a buffer and send that data to the controlling computer. You'll use a viRead() command to transfer the data from the buffer to a variable in your program. The CURVE? query returns data in the IEEE 488 binary block format, which prepends a short header onto the data (See http://na.support.keysight.com/pna/help ... alyzer.htm and scroll down to the "Block Data" section for more details).

Once you've got the waveform data stored as a variable in your program, you can manipulate and save it however you like on your computer.

Post Reply

Return to “Programming Support”

Who is online

Users browsing this forum: No registered users and 8 guests