Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

use of the libairy visa

thank you very much
do you think I can use the " viRead " like that :    
 
int buffer[2200];
viRead(vi, buffer , 255, &retCount);
 
I order the spectrum analyser to send me data in int format with the command :  vs = viPrintf( vi, "FORMat: DATA INTeger 32 ");
I don't know if I can put a table of int for the second parameter of the function viRead ();
Thank you.
0 Kudos
Message 11 of 33
(5,340 Views)
>do you think I can use the " viRead " like that :    
>int buffer[2200];
>viRead(vi, buffer , 255, &retCount);
 
No! The code shall be:
int buffer[550];
viRead(vi, buffer , sizeof(buffer), &retCount);
 
The "sizeof(buffer)" will be compiled as 2200 by the C/C++ compiler.  However, your reading data will have a SCPI birnary prefix (#xyyyyyyyy...), therefore your reading buffer must have more space.  For example, if the prefix is #800002200, the entire length will be  2210 bytes.  In this case your reading code can be:
 
#pragma pack(1)   
  // The struct members must be aligned as 1-byte alignment
  // but the #pragma directive is different depending on compiler vendors
typedef struct tagBUFFER
{
    char cSharp;   // will be #
    char cLengthWidth;  // x part
    char acLengthInfo[8]; // y part, assuming "x" part says "8"
    int buffer[550];  //your trace data
} BUFFER;
 
BUFFER buffer;
viRead(vi, (unsigned char*)buffer , sizeof(buffer), &retCount);
 
Anyway, you must be sure:
(1) if the response data is BINARY formatted with SCPI / IEEE488.2 header prefix, and
(2) what the header prefix contents are.
 
As for (2), you can check  #xyyyyyyyy part by the following call:
 
char header[16];
memset( header, 0, sizeof(header));
viRead(vi, (unsigned char*)header, 10, &retCount);
 
What did you see in the header?
 
0 Kudos
Message 12 of 33
(5,334 Views)

thank you and sorry. I will try it as soon as possible>

Thank you very much

0 Kudos
Message 13 of 33
(5,332 Views)
Now I'm trying to communicate with a spectrum analyser via ethernet RJ45. So I have connected it and try to see if the spectrum analyser has an IP address but nothing. When I use the software provided by the manufacturer, I chose ethernet communication, but it replies that communication failed. I really don't know how to communicate with it . Have to create a local area network ??
 
Thank you very much
0 Kudos
Message 14 of 33
(5,330 Views)
Sorry, I have succeed in communicating with the spectrum analyser and with the software provided.
But now I m trying to use C++ . I have writen a program, but it doesn't work. I cant initialize the communication with the function viOpen :
Here is my program :
 
#include <vcl.h>
#include <visa.h>
#include <stdio.h>
#include <string.h>
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
int main()
{
ViSession viRM;
ViSession instr;
ViStatus status;

status = viOpenDefaultRM(&viRM);
if (status < VI_SUCCESS )
 {
  printf("Can't initialize VISA \n");
  return -1;
 }
 
status = viOpen( viRM, "TCPIP0::172.16.130.109::INSTR", VI_NULL, VI_NULL, &instr); //VXI11 INSTR
if (status < VI_SUCCESS )
 {
  printf("Can't initialize viOpen \n");
         getchar();
  return -1;
 }

status = viClose(instr);
status = viClose(viRM);

     getchar();
        return 0;
}
 
 
The program return me " Can't initialize viOpen" . But I m pretty sure of the IP address since it has work with the software from the constructor.
Do you have an idea ?
Thank you very much
0 Kudos
Message 15 of 33
(5,326 Views)
> viOpen( viRM, "TCPIP0::172.16.130.109::INSTR", VI_NULL, VI_NULL, &instr); //VXI11 INSTR
 
Is your instrument really VXI-11 compliant?  If yes, the above viOpen() call must succeed.
 
If not VXI-11, the above viOpen() call must fail even if the IP address is correct. The VISA address you used requires that the instrument is TCPIP VXI-11 compliant, but not all the instruments are VXI-11.  For non-VXI-11 instruments, you have to access through the TCPIP SOCKET protocol as shown blow.  Then, you must explicitly specify a "port number" that is defined or configured by the instrument side.  The following code assumes that the port# is 12345, but you shall read the operation manual to know the correct port number.
 
viOpen( viRM, "TCPIP0::172.16.130.109::12345::SOCKET", VI_NULL, VI_NULL, &instr);
 
 
0 Kudos
Message 16 of 33
(5,318 Views)

yes I'm sure that the spectrum analyser has a VXI-11 protocol. In the documentation, it is written : the physical interface is RJ45 connection on the instrument for 10 BASE-T. Data transfer takes place over ethernet using TCP IP and the VXI-11 protocol.

But after it is written that : But to communicate with the instrument, the PC must have a VXI-11  client implementation either as part of the controller program.

So maybe something s missing on my computer ??

 

Thank you

0 Kudos
Message 17 of 33
(5,318 Views)

> yes I'm sure that the spectrum analyser has a VXI-11 protocol.

The VISA address syntax is correct.  By the way the "0" (zero) suffix for VISA address "TCPIP0" is normally unnecessary, therefore you can simply write TCPIP instead of TCPIP0.  Try it too.  Then, when you could not open viOpen(), what error code (ViStatus) did you get?

> the PC must have a VXI-11  client implementation either as part of the controller program.
> So maybe something s missing on my computer ??

The client program that controls a VXI11 instrument internally requires SUN ONC RPC library, however NI-VISA already have it inside.  Therefore you dont have to prepare any other software.  The only exception is, WinXP SP2 contains firewall feature as default, therefore you must answer as "Unblock" when the os prompts you for it. 

If the vendor-provided software is also using VISA library and successfully accesses the instrument, you can capture the IO trafic log by NI-SPY then compare with your app.

0 Kudos
Message 18 of 33
(5,312 Views)
> viOpen( viRM, "TCPIP0::172.16.130.109::INSTR", VI_NULL, VI_NULL, &instr); //VXI11 INSTR
 
Sorry the syntax is strictly is not correct.  The correct syntax is like below, but it has no impact in this case though...
vs = viOpen( viRM, "TCPIP0::172.16.130.109::INSTR", VI_NO_LOCK, 0, &instr);
 
The 3rd param must be VI_NO_LOCK if no lock needed.  But This symbol has the value zero having no difference.
The 4th param must be an integer for lock timeout.  But 0 is okay if VI_LOC_LOCK is specified.
 
By the way, is your instrument IP address already recognized in the Instrument Search feature of NI-MAX? If not, viOpen() may fail even if the instrument IP address passed to viOpen() is correct.
 

 
0 Kudos
Message 19 of 33
(5,307 Views)

in fact, i have difficulties to connect the spectrum analyser. I have followed what they said in the documentation, but i have problems.

I put the ethernet cable ( i have tried with a normal and with a cross over). In the spectrum analyser, I set " set the IP adress dynamycally using DHCP ". I have checked on my computer ( which is very recent) that the DHCP is well activated, and it is ok . But the computer tells my that the connexion is limited or inexistant. When I try to use the software provided by the constructor, i can t connect.

Then I have try to put manually the IP adress, but in this case too, it doesn't work. It is very strange

0 Kudos
Message 20 of 33
(5,307 Views)