Recently the project has used the program control of the device, but rookie one, what SCPI instructions Ah, visa or something, do not understand, fortunately there is a universal Internet, here to summarize the following ...
Environment configuration
系统:win8.1withupdate开发环境:VS2010编程语言:C++
Related knowledge
SCPI directive
Standard Commands is an abbreviation for Programmable instruments, which is a standardized command set for programmed instruments (programmable instruments). SCPI is an established standard IEEE488.1 and IEEE 488. 2, and follows the standard instrument programming language of many standards, such as floating-point arithmetic rules, ISO646 information Exchange 7-bit coded symbols (equivalent to ASCLL programming), and IEEE754 standard. It adopts a set of command set of tree hierarchy, presents a universal instrument model with signal-oriented measurement, and its mnemonic generation rules are simple, definite and easy to remember.
Visa Programming Interface
Ni-visa (Virtual instrument software Architec-ture, hereinafter referred to as "VISA") is the National Instrument ni (nationalinstrument) A high-level application programming interface developed by the company to communicate with various instrument busses. Visa bus I/O software is a comprehensive package that can be configured, programmed, and debugged for USB, GPIB, serial, VXI, PXI, and Ethernet systems, not limited by platform, bus, and environment. Visa is a virtual instrument system I/O interface software. Based on the bottom-up structure model, Visa has created a unified form of I/O control function set. On the one hand, for beginners or simple task designers, Visa provides a simple and easy-to-use control function set, in the form of simple application, on the other hand, for the complex system of developers, Visa provides a very powerful instrument control functions and resource management.
How to use the Visa library in VS2010
First, install the NI-provided driver library on the computer, and then locate the corresponding library file and header file on the computer.
Files directory: C:\Program files (x86) \ivi Foundation\visa\winnt
Where Lib files are in: Lib\msc\visa32.lib and Ivi.lib
Header file in: Include
Second, add library to the project
The blogger directly copies the library file and the corresponding header file to the project directory, and then adds a reference to the Lib library in the project, which is referred to in the VS2010 Visa library as follows:
1 Menu Item--Properties--Configuration Properties –> Linker--Input-additional dependencies, add library names, such as: Visa32.lib;
Or in the CPP source file with code #pragma comment (lib, "Visa32.lib") instead. At this point, the compiler will prompt the error: fatal error LNK1104: Unable to open the file "My_api.lib", because the compiler does not know where to find our library, the following to solve
2 Then add the library file path to the project and add the additional library path:
Configure Properties---Properties------------------------------------ F:\my_program\meiyong\PPPP_Decode_ETIM, or. /.. /pppp_decode_etim, and the experimental test is based on the project file. Vcxproj is in the current directory, the current directory is now the way to set up better. That's good.
Third, the use of the visa library in the project
In the following code, the *IDN?
ID of the instrument is queried in VS2010 by calling the Visa library.
#include "visa/include/visa.h"#include "visa/include/ivi.h"#pragma comment (lib, "Visa32.lib")#pragma comment (lib, "Ivi.lib")/*----------------------------------------------------------------------------*// * Macro Definition declaration * //*----------------------------------------------------------------------------*/#define MAX_SCPI_LENGTH 255//maximum SCPI command#define DEFAULT_TIMEOUT 5000//timeout: 5000msintMainvoid) {Vistatus Nreturnstatus =0;//Save return valueVisession rmsession =0, Pninstrhandle; ViUInt32 retcnt =0; Vibyte Wrtbuf[max_scpi_length];//write bufferVibyte Rdbuf[max_scpi_length];//Read buffer intReturn_count; Nreturnstatus = VIOPENDEFAULTRM (&rmsession); Nreturnstatus = Viopen (Rmsession,"Tcpip0::172.141.114.6::5001::socket", Vi_null, Vi_null, &pninstrhandle);/*-Configure VISA formatted I/o----------------------------------------*/Nreturnstatus = Visetattribute (Pninstrhandle, Vi_attr_tmo_value, default_timeout);//Set timeoutNreturnstatus = Visetattribute (Pninstrhandle, Vi_attr_suppress_end_en, Vi_false);//Do not send TerminatorNreturnstatus = Visetattribute (Pninstrhandle, Vi_attr_send_end_en, Vi_false);//Do not receive TerminatorNreturnstatus = Viqueryf (Pninstrhandle,"*idn?\n",'%s ', RDBUF); Viclose (Pninstrhandle); Viclose (rmsession);return 0;}
Blogger GitHub hosted static blog: newbie-bt.com
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
How to use VS2010 to call visa for program control