I am writing a VC++ program to change the frequency of Signal Generator from 0.5 GHz to 18 GHz in the step of 500 MHz. I want to use the for loop in the program. The code is as below:
#include
#include
void CTryDlg::OnOK()
{
ViSession defaultRM, vi;
viOpenDefaultRM(&defaultRM);
viOpen(defaultRM, "GPIB0::09::INSTR",VI_NULL,VI_NULL, &vi);
viPrintf(vi, "*RST\n");
float i= 0.5;
for (; i = < 36; i=i+0.5)
{
viPrintf(vi, "FREQ ", i ,"GHZ\n");
Sleep(500);
}
viClose(vi);
viClose(defaultRM);
}
The above code gives error because I am trying to concatenate the char and number, but I do not know how to do this.
Please help in this regard.
I will be thankful for your reply.
#include
#include
void CTryDlg::OnOK()
{
ViSession defaultRM, vi;
viOpenDefaultRM(&defaultRM);
viOpen(defaultRM, "GPIB0::09::INSTR",VI_NULL,VI_NULL, &vi);
viPrintf(vi, "*RST\n");
float i= 0.5;
for (; i = < 36; i=i+0.5)
{
viPrintf(vi, "FREQ ", i ,"GHZ\n");
Sleep(500);
}
viClose(vi);
viClose(defaultRM);
}
The above code gives error because I am trying to concatenate the char and number, but I do not know how to do this.
Please help in this regard.
I will be thankful for your reply.
We think you need to convert the ‘i’ variable (which is a numeric float) to a string variable.
‘i’ goes from numbers .5 to 18 so for example they need to convert the number .5 to the string “.5”.
Then concatenate the strings “FREQ” + “converted number”+”GHZ” to give a single string: “FREQ .5GHZ”.
Now use :
viPrintf(vi, “FREQ .5GHZ\n”
I hope this helped -