Click here to Skip to main content
16,011,538 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All,

In this simple program I am trying to pull a value from a method by calling the operator in the main(I apologize if my verbatum is incorrect, I am new to programming).

Essentially I want the instrument to read the frequency and then output next to the corresponding variable.
For instance if the Analyzer read 1400 MHz, in the console I would like to see:
"Frequency: 1400 MHz"

I am attempting to do this with multiple variables so any help would be appreciated!
Thanks!

Here is my code:
C++
// FileStateRecall.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "visa.h"
#include <iostream>
#include <fstream>
using namespace std;
int print_Freq()
{
	

	char FreQ[2048];
	int FreQSize = 2048;

	ViSession rm;
	viOpenDefaultRM(&rm);
	
	ViSession v5182_signal_generator;
	viOpen(rm, "TCPIP0::10.208.211.33::5025::SOCKET", VI_NULL, VI_NULL, &v5182_signal_generator);
	
	viQueryf(v5182_signal_generator, "STAT:QUES:FREQ?\n",  "%#T", FreQSize, FreQ);


	char z;
	z =printf("  %s\n",FreQ);
	return z;
}

int print_Amp()
{
	ViSession rm;
	viOpenDefaultRM(&rm);
	
	ViSession v5182_signal_generator;
	viOpen(rm, "TCPIP0::10.208.211.33::5025::SOCKET", VI_NULL, VI_NULL, &v5182_signal_generator);
	
	int z;
	z = viPrintf(v5182_signal_generator, ":POW 0dBm\n");
	return z;
}

int Save_Image()
{
	ViSession rm;
	viOpenDefaultRM(&rm);

	ViSession n9010a_exa_signal_analyzer;
	viOpen(rm, "TCPIP0::10.208.211.153::5025::SOCKET", VI_NULL, VI_NULL, &n9010a_exa_signal_analyzer);

	viPrintf(n9010a_exa_signal_analyzer, "n9010a_exa_signal_analyzer\n");

	return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{	
	ViSession rm;
	viOpenDefaultRM(&rm);
	ViSession n9010a_exa_signal_analyzer;
	ViSession v5182_signal_generator;
	viOpen(rm, "TCPIP0::10.208.211.153::5025::SOCKET", VI_NULL, VI_NULL, &n9010a_exa_signal_analyzer);
	viOpen(rm, "TCPIP0::10.208.211.33::5025::SOCKET", VI_NULL, VI_NULL, &v5182_signal_generator);
	
	viPrintf(v5182_signal_generator, "*RCL 1\n");
	viPrintf(n9010a_exa_signal_analyzer, "*RCL 1\n");	

	printf("You are currently viewing State 01 via v5182 Signal Generator\n");
	printf("     \n");
	printf("Generator Frequency: \n", print_Freq);
	printf("     \n");
	printf("Generator Power: \n", print_Amp);
	printf("     \n");
	printf("Screenshot Saved in 'My Data Directory'  \n", Save_Image);
	printf("     \n");
	printf("Press any key to continue:\n");
	getchar();
	return 0;
		
	viClose(n9010a_exa_signal_analyzer);
	viClose(v5182_signal_generator);

	return 0;

}
Posted
Updated 11-Jul-12 9:18am
v2
Comments
[no name] 11-Jul-12 14:07pm    
And your question is what?
CMA21 11-Jul-12 14:26pm    
Sorry for not being specific. What I meant to ask more directly was, How do I change/fix my code to do the aforementioned objective?
[no name] 11-Jul-12 14:49pm    
Maybe you can help us all out. I left my signal generator in my other pants. What is it that your program is doing and what is it that you want it to do? Is your print_Freq function returning the right value? Why are you returning from your main function twice? Can you in fact connect to the equipment? It almost impossible for anyone but you to debug this.
[no name] 11-Jul-12 14:50pm    
try printf("Generator Frequency: %i\n", print_Freq);
CMA21 11-Jul-12 15:13pm    
Excuse my numerouse errors the code was thrown together in 20 mins and I haven't used C++ since my first college semester many years ago.....

Objective:
1. Open saved file/state on the generator
2. Output in a console the values of numerous variables decalred by the state (ie. Freq: 1400 MHz, Power: 13 dBm)
3. From here I want to save the screen image appearing on the analyzer resulting from the state file being opened

Hey Everyone,

I appreciate the feedback and help with my program and as you can see I infact was confused myself as to what exactly I was trying to do. But after sleeping on my thoughts and ideas for the project I was able to revise my project this morning.

Here is the code (Very Basic):

// FinalTestMode.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "visa.h"
#include "Windows.h"


void state_One()
{

ViSession rm;
viOpenDefaultRM(&rm);

ViSession v5182_signal_generator;
viOpen(rm, "TCPIP0::10.208.211.33::5025::SOCKET", VI_NULL, VI_NULL, &v5182_signal_generator);
ViSession n9010a_exa_signal_analyzer;
viOpen(rm, "TCPIP0::10.208.211.153::5025::SOCKET", VI_NULL, VI_NULL, &n9010a_exa_signal_analyzer);

printf("You are currently viewing State 01 via v5182 Signal Generator\n");
Sleep(10000);
viPrintf(v5182_signal_generator, "*RCL 1\n");
viPrintf(n9010a_exa_signal_analyzer, ":FREQuency:TUNE:IMMediate\n");
printf(" \n");
printf("You are now viewing W-CDMA Waveform Mode\n");
Sleep(10000);
printf(" \n");
printf("The System Will Now Prepare to Perfrom Measurements\n");
printf(" \n");
Sleep(10000);
printf(" \n");
printf("You are now viewing Channel Power\n");
viPrintf(n9010a_exa_signal_analyzer, ":CONFigure:CHPower\n");
viPrintf(n9010a_exa_signal_analyzer, ":MMEMory:STOR:SCR 'S1ChanPow.png'\n");
Sleep(10000);
printf(" \n");
printf("You are now viewing Occupied Bandwith\n");
viPrintf(n9010a_exa_signal_analyzer, ":CONFigure:OBWidth\n");
viPrintf(n9010a_exa_signal_analyzer, ":MMEMory:STOR:SCR 'S1OBWidth.png'\n");
Sleep(10000);
printf(" \n");
printf("You are now viewing ACP\n");
viPrintf(n9010a_exa_signal_analyzer, ":CONFigure:ACP\n");
viPrintf(n9010a_exa_signal_analyzer, ":MMEMory:STOR:SCR 'S1ACP.png'\n");
Sleep(10000);
printf(" \n");
printf("You are now viewing Power Stat CCDF\n");
viPrintf(n9010a_exa_signal_analyzer, ":CONFigure:PSTatistic\n");
viPrintf(n9010a_exa_signal_analyzer, ":MMEMory:STOR:SCR 'S1PowStat.png'\n");
Sleep(10000);
printf(" \n");
printf("You are now viewing Burst Power\n");
viPrintf(n9010a_exa_signal_analyzer, ":CONFigure:TXPower\n");
viPrintf(n9010a_exa_signal_analyzer, ":MMEMory:STOR:SCR 'S1BurstPow.png'\n");
Sleep(10000);
printf(" \n");
printf("You are now viewing Spurious Emissions\n");
viPrintf(n9010a_exa_signal_analyzer, ":CONFigure:SPURious\n");
viPrintf(n9010a_exa_signal_analyzer, ":MMEMory:STOR:SCR 'S1SPuriousEmis.png'\n");
Sleep(10000);
printf(" \n");
printf("You are now viewing Spectrum Emission Mask\n");
viPrintf(n9010a_exa_signal_analyzer, ":CONFigure:SEMask\n");
viPrintf(n9010a_exa_signal_analyzer, ":MMEMory:STOR:SCR 'S1SpectrumEmissMask.png'\n");
Sleep(10000);
printf(" \n");
printf("The Measurement Tests For State 01 Are Now Complete\n");
Sleep(1000);
printf(" \n");
printf("An Image Of Each Test Has Been Saved to the Desktop\n");
Sleep(1000);
printf(" \n");
printf("Press any key to continue:\n");
getchar();
return;



viClose(n9010a_exa_signal_analyzer);
viClose(v5182_signal_generator);


}


int _tmain(int argc, _TCHAR* argv[])
{

state_One();


return 0;
}
 
Share this answer
 
I'm just guessing what the problem is. Here is a big mistake:

Instead of this:
C++
printf("Generator Frequency: \n", print_Freq);
printf(" \n");
printf("Generator Power: \n", print_Amp);
printf(" \n");
printf("Screenshot Saved in 'My Data Directory' \n", Save_Image);
printf(" \n");


Use this:
C++
printf("Generator Frequency: ");
print_Freq();
printf(" \n");
printf("Generator Power: ");
print_Amp();
printf(" \n");
printf("Saving Screenshot to 'My Data Directory'....\n");
Save_Image();
printf(" \n");
printf("Screenshot Saved.\n");


If you still have problems we need to take a look at the documentation of the viQueryf() that you use in the print_Freq() function!
 
Share this answer
 
v3
Comments
CMA21 11-Jul-12 15:19pm    
Hi pasztorpisti!

Thanks for the help unfortunately I am still having errors and after changing to the new code. Now I am not able to generate any text on the console when debug is activated
pasztorpisti 11-Jul-12 16:23pm    
Well, unfortunately without providing any more info its unlikely that someone can help you. You should at least provide some more info about the first location where the text doesn't appear correctly. What do you see on the screen? Its almost sure that you pass incorrect arguments to one of your viXXX function calls and one of them crashes or doesn't do what you want.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900