Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

use of the libairy visa

Two questions:
 
(1) Did you make NI-MAX to scan your instrument? If successfully scanned, can you communicate with the instrument through the NI-MAX VISA Interactive tool?
 
(2) Can NI-SPY program capture any IO trafic when you run the vendor-provided application (that will successfully work)?
Message 21 of 33
(5,283 Views)
 
(1) Did you make NI-MAX to scan your instrument? If successfully scanned, can you communicate with the instrument through the NI-MAX VISA Interactive tool?
(2) Can NI-SPY program capture any IO trafic when you run the vendor-provided application (that will successfully work)?
 
 
How can I can get these two program, NI MAX and NI SPY. I don't think it is provided with the spectrum analyser i bought 😞
 
I m sorry for disturbing you
0 Kudos
Message 22 of 33
(5,279 Views)
sorry, I get NI spy now, but I have nothing. Even with the software from the constructor, it doesn t work. It is ;y connection which is not good. I have tried with two diffenrent PC, but it doesn t work
0 Kudos
Message 23 of 33
(5,273 Views)

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

0 Kudos
Message 24 of 33
(5,271 Views)
i have tried with what you adviced me :
int buffer[550];
viRead(vi, buffer , sizeof(buffer), &retCount);
 
but there is a probleme of compilation. Maybe, the viRead function doesn't want a table of int for the second parameter ??
0 Kudos
Message 25 of 33
(5,271 Views)
>int buffer[550];
>viRead(vi, buffer , sizeof(buffer), &retCount);
 
Simply typecast the 2nd param as (unsigned char*).
 
By the way I want to know the followings:
 
(1)
ViChar buffer4[2550];
....
status = viRead(instr, ( unsigned char *)buffer4, 2232, &retCount);
After this viRead has returned, what value does the retCount contain?  This value indicates how many BYTEs you have actually read.
 
(2)
After this viRead what are the first 10 BYTEs of the ViChar buffer4[] ?  If the response format is a BINARY block, this area must contain the IEEE488.2 binary header that begins with #xyyyyyyyy... format. 
 
0 Kudos
Message 26 of 33
(5,262 Views)
(1)
ViChar buffer4[2550];
....
status = viRead(instr, ( unsigned char *)buffer4, 2232, &retCount);
After this viRead has returned, what value does the retCount contain?  This value indicates how many BYTEs you have actually read.
 
retCount return me 2210 ( one measurement point has 4 bytes, and there are 550 points, so it is ok -->550*4+10 )
is it important to put some int in a table of char ? I have tried this way : ViChar buffer4[2550];
                                                                                                                    ....
                                                                                                                status = viRead(instr, ( unsigned char *)buffer4, 2232, &retCount);

but when I want to send it into a text file, the caracters are strange.


(2)
After this viRead what are the first 10 BYTEs of the ViChar buffer4[] ?  If the response format is a BINARY block, this area must contain the IEEE488.2 binary header that begins with #xyyyyyyyy... format. 

The first bytes are : #42204 . I don't understand what it means.

I thank you a lot.
0 Kudos
Message 27 of 33
(5,261 Views)
> retCount return me 2210 ( one measurement point has 4 bytes, and there are 550 points, so it is ok -->550*4+10 )
...
> The first bytes are : #42204 . I don't understand what it means.
...
 
The first #4 means that a 4-digit length info will follow.  The 4-digit length info is the next 4 byte characters -- "2204", means that the actual data block 2204 bytes will follow. 
Therefore in your case, entire length is [6 + (551 x 4)] = 2210 bytes.  Now you have 551 pt data of 32bit-integer, not 550 pt.
 


 
0 Kudos
Message 28 of 33
(5,257 Views)
arigato gozaimasu. I have understand. I will try tomorrow to think about how to send correctly these 551 measurement points into a texte file.

I thank you a lot, i may have some questions tomorrow if I don't succeed. Thank you so much
0 Kudos
Message 29 of 33
(5,255 Views)
good morning.
 
Yesterday I wrote a small programm that succeeded in receiving data from my spectrum analyser. I ordered it to send me data in ASCII format, and I was able to send these data into a text file.
But today, when I run the same programm, it doesn t work anymore and I really don't understand why. When I order it to send me data in ASCII, it says me that I have a problem with the function viRead. But when I put the format into INT, it works. I really don t understand, yesterday it worked, and I have changed nothing. This is my programm:
 
#include <vcl.h>
#include <visa.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 #include <bitset>
#include <string>
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
int main()
{
ViSession viRM;
ViSession instr;
ViStatus status;
ViChar buffer[255]; // buffer for string
ViChar buffer4[7001];
ViChar buffer6[255];
ViUInt32 retCount;
char tempDisplay[255];

status = viOpenDefaultRM(&viRM);
if (status < VI_SUCCESS )
 {
  printf("Can't initialize VISA \n");
  return -1;
 }
 
status = viOpen( viRM, "TCPIP::169.254.55.115::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);
 

 
sprintf(buffer6,":FORMat:DATA ASCii\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, 7000, &retCount);
 
if (status < VI_SUCCESS )
 {
  printf("Can't read \n");                              //today, I receive "can t read" with ASCii format, but it works with INTeger,32 format
         getchar();
  return -1;
 }
 
strncpy(tempDisplay, buffer4, retCount);
tempDisplay2[retCount]=0;
printf("IDN? returned %d bytes : %x \n ",retCount,tempDisplay);

 
status = viClose(instr);
status = viClose(viRM);
     getchar();
        return 0;
}
 
0 Kudos
Message 30 of 33
(5,249 Views)