"VC + + Technology 005" How to communicate with program control instrument via GPIB interface

Source: Internet
Author: User
Tags idn

In the industrial control test system, often need to use all kinds of programmed instruments, these programmed instruments usually have GPIB, LAN, USB and other hardware interface, the computer through these interfaces can communicate with, so as to achieve automatic measurement, data acquisition, analysis and processing operations. This paper mainly introduces how to communicate with programmed instrument through GPIB interface.

1.GPIB Introduction

GPIB is the abbreviation of the Universal Bus (General Purpose Interface Bus).

GPIB is composed of 24 lines, of which 8 data lines db0-db7,3 the root handshake (NRFD, DAV, NDAC), 5 bus control lines (ATN, SRQ, IFC, REN, EOI), 8 ground.

GPIB is a two-way bus for asynchronous data transmission, and the information on the bus is transmitted in bits (bit) parallel and byte (byte) in a sequential way.

Detailed GPIB Hardware interface introduction Please consult the relevant information, here is not detailed.

2.SCPI Introduction

SCPI is the abbreviation for the Programmable Instrument standard command (Commands for Programmable Instruments).

SCPI specifies the structure and content of the information exchange layer messages between the Controller and the instrument and the instrument to the controller, so that the same type of instrument command set is similar at the vertical level, and the SCPI command of the same function is consistent between different types of instruments at the horizontal level.

The SCPI command is divided into two parts: Instrument common Command and Instrument specific control command. Public commands are used to control certain basic functions of the instrument, whose syntax and semantics follow the IEEE488.2 rules. Instrument-specific control commands are specific commands that each programmed instrument completes its own command operation.

Detailed SCPI command syntax please consult the relevant information, here is not detailed.

3.VISA Introduction

Visa is the abbreviation for Virtual Instrument Software Architecture (Vsan instrument software).

Visa provides a library of standard I/O functions for instrument programming, called the Visa library. The Visa library provides a unified device resource management, operation, and usage mechanism that is independent of hardware devices, interfaces, operating systems, and programming languages, and has characteristics that are not related to the hardware architecture. It abstracts the lower-level driver for each instrument's hardware bus type and provides a single API for communicating with the instrument, without having to consider the specific bus interface.

Common visa APIs include the following:

(1) vistatus VIOPENDEFAULTRM (vipsession VI); Open the Default Resource Manager resource dialog Channel

(2) Vistatus Viopen (visession sesn, virsrc name, Viaccessmode mode, ViUInt32 timeout, vipsession VI); Open a conversation channel for a specific resource

(3) Vistatus viclose (Viobject VI); Close a conversation channel for a specific resource

(4) Vistatus viprintf (visession VI, vistring writefmt, ...); Write data to the instrument in a set format

(5) Vistatus viscanf (visession VI, vistring readfmt, ...); Read data from instrument in set format

(6) Vistatus Viread (visession VI, Vipbuf buf, ViUInt32 cnt, ViPUInt32 retcnt); Read data synchronously from instrument

(7) Vistatus Viwrite (visession VI, Vibuf buf, ViUInt32 cnt, ViPUInt32 retcnt); Write data synchronously to the instrument

(8) Vistatus viclear (visession VI); Clear Data

4. Programming examples

The following code example demonstrates how to control the dual-channel DC power supply of the 2220G-30-1 model via the GPIB interface. The program runs as shown in effect 1.

Figure 1 GPIB example Run effect

4.1 Loading the header and library files of the visa library

In order to control the programmed instrument using the Visa API function in the project, the header file Visa.h and the library file visa32.lib of the visa library need to be loaded. These two files can be found in the Include and Lib directories under the "C:\Program files\ivi foundation\visa\winnt" directory after installing GPIB drivers.

Here are some ways to load these two files:

1 " include//visa.h "                                // include visa header and library files 2 #pragma comment (lib, "Lib/msc//visa32.lib")

4.2 Connecting the device

Click the Connect device button in Figure 1 to call the Viopen () function to open a conversation channel for a specific resource. If the conversation channel is open successfully, send "*idn" to the instrument. command to read the device information. The specific implementation code is as follows:

1 /*2 * Function function: When the "Connect Device" button is clicked, the function is called3 * Remark:4 * Author: Blog Park is still indifferent5  */6 voidCgpibdemodlg::onbuttonopendevice ()7 {8VIOPENDEFAULTRM (&m_visessionrm);9     if(vi_success = = Viopen (M_VISESSIONRM,"Gpib0::1::instr", Vi_null, Vi_null, &m_visession))Ten     { One         Charreceivebufferarrary[ the] = {0}; Aviprintf (M_visession,"*rst\n");//Send Reset Command -viprintf (M_visession,"*idn?\n");//Send read device information command -VISCANF (M_visession,"%t", &receivebufferarrary); them_isconnected =true; -M_staticdevicestate.format ("Device status: Connected! "); -M_staticdeviceinfo.format ("device information:%s \ n", receivebufferarrary); - UpdateData (FALSE); +     } -     Else +     { Am_isconnected =false; atMessageBox ("failed to connect the device! ","Tips", mb_ok|mb_iconwarning); -     } -}

As can be seen from Figure 1, after the connection device is successful, the device information obtained is "Keithley instruments, 2220g-30-1, 9010179, 1.16-1.04". These four fields represent the manufacturer, the product designator, the product serial number, and the software version number, respectively.

4.3 Setting the voltage current

The 2220G-30-1 model's dual DC power supply can set the DC voltage of the output 0-30v and the current of the 0-1.5a. The following code gives the method for setting the voltage and current of Channel 1:

1 /*2 * Function function: When the "Channel 1 Settings" button is clicked, the function is called3 * Remark:4 * Author: Blog Park is still indifferent5  */6 voidcgpibdemodlg::onbuttonchannel1setting ()7 {8 UpdateData (TRUE);9 Ten     if(!m_isconnected) One     { AMessageBox ("please connect the device first! ","Tips", mb_ok|mb_iconwarning); -         return; -     } the  -     if(M_editchannel1voltage.isempty ()) -     { -MessageBox ("the input voltage cannot be empty! ","Tips", mb_ok|mb_iconwarning); +         return; -     } +  A     if(M_editchannel1current.isempty ()) at     { -MessageBox ("input current cannot be empty","Tips", mb_ok|mb_iconwarning); -         return; -     } -  -viprintf (M_visession,"Inst:sel ch1\n");//Select Channel 1 inviprintf (M_visession,"SOURCE:OUTP:ENAB on\n");//Enable output -viprintf (M_visession,"Source:volt%sv\n", m_editchannel1voltage);//Setting the output voltage toviprintf (M_visession,"Source:curr%sa\n", m_editchannel1current);//Setting the output current +viprintf (M_visession,"SOURCE:OUTP on\n");//Output -}

"VC + + Technology 005" How to communicate with program control instrument via GPIB interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.