
Programming Examples
Introduction
6
6-3
Introduction
The following examples explain how to program the instrument and can serve as a basis
to solve more complex programming tasks. In these examples, the interface (RS-232 /
GPIB / ethernet) can be selected by setting constant ‘INTFC‘ to corresponding
‘INTFC_…‘ constant. Communication parameters (e.g. serial port, baud rate, IP address,
etc.) are set using ‘RSRC_NAME‘ and ‘RSRC_ATTR_…‘ constants.
The programing examples are written in ANSI C using VISA library implemented
according to version 2.2 of the VISA specification (
www.vxipnp.org
), for example
National instruments VISA 2.5 or higher. It is possible to communicate with the
instrument over RS-232 or Ethernet interface using basic operating system (e.g. Win32 or
UNIX) API only, that is, without using VISA library. There is one such example for
ethernet interface (using Win32 API) later in this chapter.
Initialize Interface
The interface must be initialized before any communication with the instrument takes
place.
The interface must be initialized before any communication with the instrument takes
place.
/*
* INITIALIZE INTERFACE
*
* This program will open VISA session to the instrument.
* The program uses RS-232, GPIB or ethernet interface depending
* on the setting of 'INTFC' constant and sets the I/O timeout
* to 10 seconds.
*/
#include <visa.h>
#include <stdio.h>
#define INTFC_RS232 1 /* RS-232 interface */
#define INTFC_GPIB 2 /* GPIB / IEEE 488.2 interface */
#define INTFC_LAN 3 /* ethernet / IEEE 802.3 interface */
#define INTFC_USB 4 /* USB interface (Virtual COM Port) */
#if 1
#define INTFC INTFC_RS232
#elif 1
#define INTFC INTFC_GPIB
#elif 1
#define INTFC INTFC_LAN
#else
#define INTFC INTFC_USB
#endif
#if INTFC == INTFC_RS232
# define RSRC_NAME "ASRL1" /* COM1 */
# define RSRC_ATTR_BAUD 115200 /* baud rate */
# define RSRC_ATTR_FLOW_CNTRL VI_ASRL_FLOW_RTS_CTS /* flow control */
#elif INTFC == INTFC_GPIB
# define RSRC_NAME "GPIB::5"
Summary of Contents for NORMA 4000 Operators
Page 6: ...Remote Control Users Guide iv ...
Page 8: ...Remote Control Users Guide vi ...
Page 10: ...Remote Control Users Guide viii ...
Page 26: ...Remote Control Users Guide 2 2 ...
Page 38: ...Remote Control Users Guide 3 2 ...
Page 50: ...Remote Control Users Guide 4 2 ...
Page 150: ...Remote Control Users Guide 4 102 ...
Page 152: ...Remote Control Users Guide 5 2 ...
Page 160: ...Remote Control Users Guide 6 2 ...
Page 184: ...Remote Control Users Guide 6 26 ...