Interfacing Your HP Controller to a Personal Computer
Overview
The test and measurement market has gone through many changes since the days of dedicated instrument controllers. Today, the personal computer (PC) has become the platform of choice for test and measurement system developers because of its price-to-performance ratio and wide range of application software. Many users, however, are reluctant to move to the PC because of the programming investment they have in dedicated instrument controllers. With the development of TransEra's HTBasic and National Instruments GPIB hardware, PCs can run almost any HP BASIC program without modification. The NI-488.2 software makes it easy to transfer HP BASIC programs or any other files from an HP Controller to the PC using the IEEE 488 bus.
The National Instruments NI-488.2 software, which has been the de facto industry standard for many years, is a high-speed driver with several utilities that help in developing and debugging an application program. Because the driver has high-level commands which automatically handle all bus management, you do not have to learn the programming details of the GPIB hardware or the IEEE 488 protocol. Low-level commands are also available for maximum flexibility and performance.
This application note shows how to transfer data between an HP Controller and a DOS-based PC and how to transfer HP BASIC programs into DOS-based text files, which then can be run in HTBasic.
Table of Contents
Background Information
Devices on the GPIB are categorized as Controllers, Talkers, or Listeners. All GPIB devices fall into one or more of these categories. In a typical GPIB system, there is a Controller (normally a computer) and a number of other devices such as oscilloscopes, multimeters, logic analyzers, printers, and plotters. What happens when you have two computers connected together? When more than one device has Controller capability, you must decide which is to be the System Controller. Each GPIB system can have only one System Controller. Other devices may have Controller capability, but they cannot take control of the GPIB unless the System Controller passes control to them.
Configuring the Computers
In a computer-to-computer data transfer, one computer must be the System Controller and the other must act as device (Non-Controller). In addition, each computer must be configured for a different primary GPIB address. Because many HP Controllers cannot relinquish control of the GPIB, the personal computer must be configured as Non-Controller and act as a device to the HP Controller. You can configure the PC as a device by running the GPIB configuration program, IBCONF, supplied with the NI-488.2 software. IBCONF is an easy-to-use configuration utility that configures the computer and a GPIB system.
Run IBCONF from the distribution subdirectory by typing in the following command at the prompt:
C:\AT-GPIB> ibconf
The figure below shows the proper IBCONF configuration parameters for the Non-Controller (your PC).

Simple Data Transfer
A simple data transfer is a transfer that reads and/or writes data. The following BASICA code in Example 1 programs the National Instruments GPIB interface in the PC to accept data from the HP Controller.
Example 1 -- BASICA Program to Read Data from an HP Controller
This program first opens and initializes the GPIB interface board. It then attempts to read data from the HP Controller. Because the PC is not the System Controller, the program must wait for its listen address before it can read data. When the state of the PC changes to Listener, signifying that the HP Controller is sending data, the IBRD function reads the data. If the PC is not addressed within the timeout limit, which was set in IBCONF to 10 seconds, the IBRD function terminates without completing the read operation.
100 REM Use the MERGE command to include DECL.BAS.
120 READING$ = SPACE$(20) ' Declare var. for 20 data bytes.
130 Device$ = "GPIB0"
140 CALL IBFIND (Device$, Brd%) ' Open & init. GPIB interface.
150 CALL IBRD (Brd%, READING$) ' Input data from HP Cont.
160 PRINT READING$ ' Print data to the screen.
170 END
In the HP Controller program, the program opens the GPIB port and communicates to a device at primary GPIB address 1. After the program opens the GPIB port, it outputs data.
Data File Transfers
Transferring data files over the GPIB is similar to transferring data except that data files have already been created and stored. It is important for the Controller and PC to establish first the name of the file that is to be transferred and to specify where the file will be stored. The NI-488.2 software makes file transfers easy by providing functions that transparently open, read, write, and close files.
HP Controllers and PCs store files in different formats. On a PC, data files are often stored in TEXT format, whereas on HP Controllers, data files are often stored in BDAT format. BDAT files hold binary data using variable length records. Each record may contain real, integer, or ASCII data types, or a combination of these. Each data type is saved in variable lengths depending on its type. Integers require two bytes, real numbers require eight bytes, and strings require the length of the dimensioned string.
BDAT files must be read in the same order they were stored for the data to be interpreted properly. For example, if a real number and an integer were consecutively stored, the record is 10 bytes long -- the first eight bytes are the real number and the last two bytes are the integer. Example 2 contains the two programs necessary for transferring an HP BASIC BDAT file to a PC. This example shows the programs for the HP Controller and for the PC. You must execute both of these programs simultaneously to transfer the BDAT file.
Example 2 -- Transferring a BDAT File from the HP Controller to the PC
The program for the HP Controller first initializes variables and opens a BDAT file named "DATA." It sends the filename "DATA" to the PC using the OUTPUT command. The HP Controller then sends an integer containing the number of records, in this case 100, and then sends the BDAT file containing 100 records of real numbers. With both sides ready, the HP Controller reads in the record from the stored data file and sends the record to the PC. This continues until all of the records have been transferred.
HP BASIC Program Sending a BDAT File to a PC
100 Filename$ = "DATA" ' Define the name of the data file.
110 INTEGER I, RecordNum ' Declare variables to store data.
120 REAL Reading
130 RecordNum = 100 ' Define number of records to send.
140 ASSIGN @Path TO Filename$ ' Open the data file to send.
150 ASSIGN @PC TO 701 ' Define the PCs GPIB address.
160 OUTPUT @PC; Filename$ ' Send name of te file to the PC.
170 OUTPUT @PC; RecordNum ' Send number of records to PC.
180 FOR I=1 TO RecordNum ' Send the data to the PC.
190 ENTER @Path; Reading
200 OUTPUT @PC; Reading
210 NEXT I
220 ASSIGN @Path TO * ' Close the data file.
230 END
Using the same commands as in Example 1, the BASICA program first initializes the NI-488.2 driver. After it is addressed to listen, it reads the name of the data file from the HP Controller. A file is opened using the name that was read from the Controller. Then the record count followed by each record is stored into the file. Each record in the TEXT file will be delimited by a carriage return-linefeed (CR LF) pair.
The BASICA Program Reading a Data File from an HP Controller
100 REM Use the MERGE command to include DECL.BAS.
110 Filename$ = SPACE$(20) ' Declare variables to store data.
120 NumberRec$ = SPACE$(6)
130 Reading$ = SPACE$(255)
140 Device$ = "GPIB0"
150 CALL IBFIND (Device$, Brd%) ' Open & init. GPIB interface.
160 CALL IBRD (Brd%, Filename$) ' Input data from HP Cont.
170 OPEN Filename$ FOR OUTPUT AS #1 ' Open file to store data.
180 CALL IBRD (Brd%, NumberRec$) ' Input # records to be sent.
190 RecordCnt = VAL(NumberRec$) ' Convert string to a number.
200 FOR I = 1 TO RecordCnt
210 CALL IBRD(Brd%, Reading$) ' Read data from HP Cont.
220 PRINT #1, Reading$ ' Write the data to the file.
230 NEXT I
240 END
Running HP BASIC Programs on a PC
As discussed earlier, using HTBasic and your PC, programs written on HP Controllers can be executed with little or no modification. Example 3 shows a BASICA program reading an HP BASIC program listing into a PC. Once transferred, each program can then be run in HTBasic.
Example 3 -- BASICA Program to Read an HP BASIC Program Listing
You do not have to write an HP BASIC program for this example. The HP Controller sends each program listing to the PC using the HP BASIC command LIST 701, which is usually used to print program listings to a GPIB printer. Because the PC is emulating a GPIB printer, it does not know when the program listing is complete. Therefore, in this application, the PC reads its program from the HP Controller line-by-line until a timeout occurs (the TIMO bit is set in the NI-488.2 status variable IBSTA). At this point, the PC program terminates, assuming it has read the whole program listing.
100 REM Use the MERGE command to include DECL.BAS.
110 OPEN "Program" FOR OUTPUT AS #1 ' Open File to store prog.
120 Reading$ = SPACE$(100) ' Declare a var. to store the data.
130 Device$ = "GPIB0"
140 CALL IBFIND (Device$, Brd%) ' Open & init. GPIB interface.
150 CALL IBRD (Brd%, Reading$) ' Input data sent from HP Cont.
160 IF (IBSTA% AND TIMO) THEN GOTO 200 ' IBRD times out when the HP stops sending data.
170 PRINT Reading$ ' Print the data to the screen.
180 OUTPUT #1, Reading$ ' Write the data to the file.
190 GOTO 150 ' Loop until a timeout occurs.
200 END
Summary
The PC has become the platform of choice for test and measurement system developers because of its price-to-performance ratio and wide range of application software. By using the NI-488.2 software, it is easy to develop file transfer programs. You can even transfer HP BASIC application programs to the PC and run them using HTBasic without modification.
Reader Comments | Submit a comment »
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).
