03-27-2007 10:40 PM
03-27-2007 11:02 PM
03-28-2007 12:10 AM
03-28-2007 03:53 AM
sorry. I have no problem of communication now, and th e beginning of my program works.
But I have know a problem of Format of data I receive. I put the data I receive into a buffer, that I send to a text file. But what is sent is very strange : Here is my program:
#include <vcl.h>
#include <visa.h>
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <windef.h>
#include <stdlib.h>
#include <iostream.h>
#include <fstream.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <sstream>
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
int main()
{
ViSession viRM;
ViSession instr;
ViStatus status;
ViChar buffer[255]; // buffer for string
ViChar buffer4[2550];
ViChar buffer6[255];
ViUInt32 retCount;
char tempDisplay[255];
int save_loop=0,g1;
std::string string3;
string3= "c:\\\\matlab2.txt";
ofstream os(string3.c_str(),ios::app);
status = viOpenDefaultRM(&viRM);
if (status < VI_SUCCESS )
{
printf("Can't initialize VISA \n");
return -1;
}
status = viOpen( viRM, "TCPIP::169.254.223.89::INSTR", VI_NULL, VI_NULL, &instr); //VXI11 INSTR
if (status < VI_SUCCESS )
{
printf("Can't initialize viOpen \n");
getchar();
return -1;
}
status = viSetAttribute( instr, VI_ATTR_TMO_VALUE, 5000);
if (status < VI_SUCCESS )
{
printf("Can't initialize viSetAttribute \n");
getchar();
return -1;
}
sprintf(buffer,"*IDN?\n");
status = viWrite(instr, (unsigned char *)&buffer[0],6,&retCount);
status = viRead(instr, (unsigned char *)buffer, 255, &retCount);
strncpy(tempDisplay, buffer, retCount);
tempDisplay[retCount]=0;
printf("IDN? returned %d bytes : %s \n ",retCount,tempDisplay); //here I receive the good name and version of the spectrum analyser. so the connection is ok
sprintf(buffer6,":FORMat:DATA INTeger,32\n");
status = viWrite(instr, (unsigned char *)&buffer6[0],100,&retCount);
sprintf(buffer4,"TRACe? 1\n");
status = viWrite(instr, (unsigned char *)&buffer4[0],100,&retCount);
status = viRead(instr, ( unsigned char *)buffer4, 2232, &retCount);
strncpy(tempDisplay, buffer4, retCount);
tempDisplay[retCount]=0;
printf(" returned %d bytes : %s \n ",retCount,tempDisplay); //here I receive 2210 byte as expected, but the format must be wrong in the viRead for buffer4. I don't know how to do
for (save_loop=0; save_loop<5000;save_loop++)
{
g1=buffer4[save_loop];
os << g1
}
os.close();
status = viClose(instr);
status = viClose(viRM);
getchar();
return 0;
}
DO you have an idea?
I thank you a lot
03-28-2007 04:00 AM
03-28-2007 04:36 AM
03-28-2007 06:49 AM
03-28-2007 06:59 AM
03-28-2007 07:06 AM
03-29-2007 09:33 PM