VC下调试GPIB驱动自带演示程序打开与之相连的仪器的电源,出现连接错误!!!

jscn123789abc 2008-04-29 09:52:46
//////////////////////////////////////////////////////////////////////////////////
VC下调试GPIB驱动自带演示程序打开与之相连的仪器的电源,出现连接错误!!!
//////////////////////////////////////////////////////////////////////////////////
VC6.0下调试GPIB驱动程序NI488.2里自带的演示程序,通过GPIB打开与之相连的仪器的电源,出现下面的连接错误:
我把用到的三个文件:CPP文件、头文件以及一个Txt说明文件贴上来,
请朋友帮忙提一些建议,谢谢啦。。。
//////////////////////////////////////////////////////////////////////////////////
--------------------Configuration: Simple - Win32 Debug--------------------
Linking...
Simple.obj : error LNK2001: unresolved external symbol _ibonl@8
Simple.obj : error LNK2001: unresolved external symbol _ibcntl
Simple.obj : error LNK2001: unresolved external symbol _ibrd@12
Simple.obj : error LNK2001: unresolved external symbol _ibwrt@12
Simple.obj : error LNK2001: unresolved external symbol _ibclr@4
Simple.obj : error LNK2001: unresolved external symbol _iberr
Simple.obj : error LNK2001: unresolved external symbol _ibsta
Simple.obj : error LNK2001: unresolved external symbol _ibdev@24
Debug/Simple.exe : fatal error LNK1120: 8 unresolved externals
Error executing link.exe.
Simple.exe - 9 error(s), 0 warning(s)
//////////////////////////////////////////////////////////////////////////////////
//文件说明
//////////////////////////////////////////////////////////////////////////////////
C/C++ SIMPLE Sample Application
This directory contains the following:
README.TXT - This readme file
SIMPLE.C - Win32 C sample application
Description
-----------
The Simple sample application was written to do a write and a read to
a Tektronix PS2520G Programmable Power Supply. The application is a
Win32 console application. It illustrates how to use the NI-488.2 API.
A Win32 console application is a Win32 application which uses text-
based input and output, not a graphical interface. This allows you to
quickly create a Win32 application by using simple input and output
functions like printf and scanf.
Checking Status with Global Variables
-------------------------------------
Each NI-488.2 call updates four global variables to reflect the status
of the device or board that you are using. The four global variables
are the status word (ibsta), the error variable (iberr), and the
count variables (ibcnt and ibcntl). Your application should check for
errors after each NI-488.2 call by looking at ibsta. The ERR bit in
ibsta indicates if the call succeeded or not. If the ERR bit is set,
iberr contains an error code. For a complete description of ibsta
bits and iberr error codes, see the online help. If you are writing a
multithreaded application, please refer to the online help on writing
multithreaded applications.
Compiling, Linking, and Running the Sample Application from the
Command Line
--------------------------------------------------------------
From the standard DOS shell command line, you can compile and link
the sample application, Simple.c, with the Microsoft Visual C++
language interface, Gpib-32.obj, using Microsoft Visual C++ (version
2.0 or higher), by typing in:
cl Simple.c ..\Gpib-32.obj
To run the application from the DOS shell, just type in the executable
name at the prompt. To run it from within Windows choose the RUN...
option from the START menu. Enter the name of the compiled application
in the dialog box that pops up.
More Information
----------------
Refer to the NI-488.2 online help for more information on application
development.
Copyright National Instruments Corporation.
All Rights Reserved.
...全文
1565 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
jscn123789abc 2009-05-02
  • 打赏
  • 举报
回复
谢谢楼上朋友的回复。。。。
aled6825 2009-05-01
  • 打赏
  • 举报
回复
inlude gpib-32.obj
jscn123789abc 2008-04-29
  • 打赏
  • 举报
回复


*/
#define IbcPAD 0x0001 /* Primary Address */
#define IbcSAD 0x0002 /* Secondary Address */
#define IbcTMO 0x0003 /* Timeout Value */
#define IbcEOT 0x0004 /* Send EOI with last data byte? */
#define IbcPPC 0x0005 /* Parallel Poll Configure */
#define IbcREADDR 0x0006 /* Repeat Addressing */
#define IbcAUTOPOLL 0x0007 /* Disable Auto Serial Polling */
#define IbcCICPROT 0x0008 /* Use the CIC Protocol? */
#define IbcIRQ 0x0009 /* Use PIO for I/O */
#define IbcSC 0x000A /* Board is System Controller? */
#define IbcSRE 0x000B /* Assert SRE on device calls? */
#define IbcEOSrd 0x000C /* Terminate reads on EOS */
#define IbcEOSwrt 0x000D /* Send EOI with EOS character */
#define IbcEOScmp 0x000E /* Use 7 or 8-bit EOS compare */
#define IbcEOSchar 0x000F /* The EOS character. */
#define IbcPP2 0x0010 /* Use Parallel Poll Mode 2. */
#define IbcTIMING 0x0011 /* NORMAL, HIGH, or VERY_HIGH timing. */
#define IbcDMA 0x0012 /* Use DMA for I/O */
#define IbcReadAdjust 0x0013 /* Swap bytes during an ibrd. */
#define IbcWriteAdjust 0x014 /* Swap bytes during an ibwrt. */
#define IbcSendLLO 0x0017 /* Enable/disable the sending of LLO. */
#define IbcSPollTime 0x0018 /* Set the timeout value for serial polls. */
#define IbcPPollTime 0x0019 /* Set the parallel poll length period. */
#define IbcEndBitIsNormal 0x001A /* Remove EOS from END bit of IBSTA. */
#define IbcUnAddr 0x001B /* Enable/disable device unaddressing. */
#define IbcSignalNumber 0x001C /* Set UNIX signal number - unsupported */
#define IbcBlockIfLocked 0x001D /* Enable/disable blocking for locked boards/devices */
#define IbcHSCableLength 0x001F /* Length of cable specified for high speed timing.*/
#define IbcIst 0x0020 /* Set the IST bit. */
#define IbcRsv 0x0021 /* Set the RSV byte. */
#define IbcLON 0x0022 /* Enter listen only mode */
/*
* Constants that can be used (in addition to the ibconfig constants)
* when calling the ibask() function.
*/
#define IbaPAD IbcPAD
#define IbaSAD IbcSAD
#define IbaTMO IbcTMO
#define IbaEOT IbcEOT
#define IbaPPC IbcPPC
#define IbaREADDR IbcREADDR
#define IbaAUTOPOLL IbcAUTOPOLL
#define IbaCICPROT IbcCICPROT
#define IbaIRQ IbcIRQ
#define IbaSC IbcSC
#define IbaSRE IbcSRE
#define IbaEOSrd IbcEOSrd
#define IbaEOSwrt IbcEOSwrt
#define IbaEOScmp IbcEOScmp
#define IbaEOSchar IbcEOSchar
#define IbaPP2 IbcPP2
#define IbaTIMING IbcTIMING
#define IbaDMA IbcDMA
#define IbaReadAdjust IbcReadAdjust
#define IbaWriteAdjust IbcWriteAdjust
#define IbaSendLLO IbcSendLLO
#define IbaSPollTime IbcSPollTime
#define IbaPPollTime IbcPPollTime
#define IbaEndBitIsNormal IbcEndBitIsNormal
#define IbaUnAddr IbcUnAddr
#define IbaSignalNumber IbcSignalNumber
#define IbaBlockIfLocked IbcBlockIfLocked
#define IbaHSCableLength IbcHSCableLength
#define IbaIst IbcIst
#define IbaRsv IbcRsv
#define IbaLON IbcLON
#define IbaSerialNumber 0x0023
#define IbaBNA 0x0200 /* A device's access board. */
/* Values used by the Send 488.2 command. */
#define NULLend 0x00 /* Do nothing at the end of a transfer.*/
#define NLend 0x01 /* Send NL with EOI after a transfer. */
#define DABend 0x02 /* Send EOI with the last DAB. */
/* Value used by the 488.2 Receive command.
*/
#define STOPend 0x0100
/* Address type (for 488.2 calls) */
typedef short Addr4882_t; /* System dependent: must be 16 bits */
/*
* This macro can be used to easily create an entry in address list
* that is required by many of the 488.2 functions. The primary address goes in the
* lower 8-bits and the secondary address goes in the upper 8-bits.
*/
#define MakeAddr(pad, sad) ((Addr4882_t)(((pad)&0xFF) | ((sad)<<8)))
/*
* This value is used to terminate an address list. It should be
* assigned to the last entry.
*/
#ifndef NOADDR
#define NOADDR (Addr4882_t)((unsigned short)0xFFFF)
#endif
jscn123789abc 2008-04-29
  • 打赏
  • 举报
回复
/////////////////////////////////////////////////////////////////////////////////
//头文件ni488
//////////////////////////////////////////////////////////////////////////////////
/*
*
*
* Include file for accessing the NI-488.2 API
*
*
* Contains user variables (ibsta, iberr, ibcnt, ibcntl),
* function prototypes and useful defined constants for
* calling NI-488 and NI-488.2 routines from a C/C++
* application.
*
*
* Copyright 2001 National Instruments Corporation
*
*/
#ifndef NI488_H // ensure we are only included once
#define NI488_H
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************/
/* HANDY CONSTANTS FOR USE BY APPLICATION PROGRAMS ... */
/***************************************************************************/
#define UNL 0x3f /* GPIB unlisten command */
#define UNT 0x5f /* GPIB untalk command */
#define GTL 0x01 /* GPIB go to local */
#define SDC 0x04 /* GPIB selected device clear */
#define PPC 0x05 /* GPIB parallel poll configure */
#define GET 0x08 /* GPIB group execute trigger */
#define TCT 0x09 /* GPIB take control */
#define LLO 0x11 /* GPIB local lock out */
#define DCL 0x14 /* GPIB device clear */
#define PPU 0x15 /* GPIB parallel poll unconfigure */
#define SPE 0x18 /* GPIB serial poll enable */
#define SPD 0x19 /* GPIB serial poll disable */
#define PPE 0x60 /* GPIB parallel poll enable */
#define PPD 0x70 /* GPIB parallel poll disable */
/* GPIB status bit vector : */
/* global variable ibsta and wait mask */
#define ERR (1<<15) /* Error detected */
#define TIMO (1<<14) /* Timeout */
#define END (1<<13) /* EOI or EOS detected */
#define SRQI (1<<12) /* SRQ detected by CIC */
#define RQS (1<<11) /* Device needs service */
#define CMPL (1<<8) /* I/O completed */
#define LOK (1<<7) /* Local lockout state */
#define REM (1<<6) /* Remote state */
#define CIC (1<<5) /* Controller-in-Charge */
#define ATN (1<<4) /* Attention asserted */
#define TACS (1<<3) /* Talker active */
#define LACS (1<<2) /* Listener active */
#define DTAS (1<<1) /* Device trigger state */
#define DCAS (1<<0) /* Device clear state */
/* Error messages returned in global variable iberr */
#define EDVR 0 /* System error */
#define ECIC 1 /* Function requires GPIB board to be CIC */
#define ENOL 2 /* Write function detected no Listeners */
#define EADR 3 /* Interface board not addressed correctly */
#define EARG 4 /* Invalid argument to function call */
#define ESAC 5 /* Function requires GPIB board to be SAC */
#define EABO 6 /* I/O operation aborted */
#define ENEB 7 /* Non-existent interface board */
#define EDMA 8 /* Error performing DMA */
#define EOIP 10 /* I/O operation started before previous */
/* operation completed */
#define ECAP 11 /* No capability for intended operation */
#define EFSO 12 /* File system operation error */
#define EBUS 14 /* Command error during device call */
#define ESTB 15 /* Serial poll status byte lost */
#define ESRQ 16 /* SRQ remains asserted */
#define ETAB 20 /* The return buffer is full. */
#define ELCK 21 /* Address or board is locked. */
#define EARM 22 /* The ibnotify Callback failed to rearm */
#define EHDL 23 /* The input handle is invalid */
#define EWIP 26 /* Wait already in progress on input ud */
#define ERST 27 /* The event notification was cancelled */
/* due to a reset of the interface */
#define EPWR 28 /* The system or board has lost power or */
/* gone to standby */
/* Warning messages returned in global variable iberr */
#define WCFG 24 /* Configuration warning */
#define ECFG WCFG
/* EOS mode bits */
#define BIN (1<<12) /* Eight bit compare */
#define XEOS (1<<11) /* Send END with EOS byte */
#define REOS (1<<10) /* Terminate read on EOS */

/* Timeout values and meanings */
#define TNONE 0 /* Infinite timeout (disabled) */
#define T10us 1 /* Timeout of 10 us (ideal) */
#define T30us 2 /* Timeout of 30 us (ideal) */
#define T100us 3 /* Timeout of 100 us (ideal) */
#define T300us 4 /* Timeout of 300 us (ideal) */
#define T1ms 5 /* Timeout of 1 ms (ideal) */
#define T3ms 6 /* Timeout of 3 ms (ideal) */
#define T10ms 7 /* Timeout of 10 ms (ideal) */
#define T30ms 8 /* Timeout of 30 ms (ideal) */
#define T100ms 9 /* Timeout of 100 ms (ideal) */
#define T300ms 10 /* Timeout of 300 ms (ideal) */
#define T1s 11 /* Timeout of 1 s (ideal) */
#define T3s 12 /* Timeout of 3 s (ideal) */
#define T10s 13 /* Timeout of 10 s (ideal) */
#define T30s 14 /* Timeout of 30 s (ideal) */
#define T100s 15 /* Timeout of 100 s (ideal) */
#define T300s 16 /* Timeout of 300 s (ideal) */
#define T1000s 17 /* Timeout of 1000 s (ideal) */
/* IBLN Constants */
#define NO_SAD 0
#define ALL_SAD -1
/* The following constants are used for the second parameter of the
* ibconfig function. They are the "option" selection codes.
jscn123789abc 2008-04-29
  • 打赏
  • 举报
回复
//////////////////////////////////////////////////////////////////////////////////
//文件Simple.c
//////////////////////////////////////////////////////////////////////////////////
/* Filename - Simple.c
*
* This application demonstrates how to read from and write to the
* Tektronix PS2520G Programmable Power Supply.
*
* This sample application is comprised of three basic parts:
*
* 1. Initialization
* 2. Main Body
* 3. Cleanup
*
* The Initialization portion consists of getting a handle to a
* device and then clearing the device.
*
* In the Main Body, this application queries a device for its
* identification code by issuing the '*IDN?' command. Many
* instruments respond to this command with an identification string.
* Note, 488.2 compliant devices are required to respond to this
* command.
*
* The last step, Cleanup, takes the device offline.
*/
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
/*
* Include the WINDOWS.H and NI488.H files. The standard Windows
* header file, WINDOWS.H, contains definitions used by NI488.H and
* NI488.H contains prototypes for the GPIB routines and constants.
*/
#include <windows.h>
#include "..\\ni488.h"
#define ARRAYSIZE 1024 // Size of read buffer
#define BDINDEX 0 // Board Index
#define PRIMARY_ADDR_OF_PPS 1 // Primary address of device
#define NO_SECONDARY_ADDR 0 // Secondary address of device
#define TIMEOUT T10s // Timeout value = 10 seconds
#define EOTMODE 1 // Enable the END message
#define EOSMODE 0 // Disable the EOS mode
int Dev;
char ValueStr[ARRAYSIZE + 1];
char ErrorMnemonic[21][5] = {"EDVR", "ECIC", "ENOL", "EADR", "EARG",
"ESAC", "EABO", "ENEB", "EDMA", "",
"EOIP", "ECAP", "EFSO", "", "EBUS",
"ESTB", "ESRQ", "", "", "", "ETAB"};
void GPIBCleanup(int Dev, char* ErrorMsg);
int main()
{

/*
* ========================================================================
*
* INITIALIZATION SECTION
*
* ========================================================================
*/
/*
* The application brings the power supply online using ibdev. A
* device handle, Dev, is returned and is used in all subsequent
* calls to the device.
*/
Dev = ibdev(BDINDEX, PRIMARY_ADDR_OF_PPS, NO_SECONDARY_ADDR,
TIMEOUT, EOTMODE, EOSMODE);
if (ibsta & ERR)
{
printf("Unable to open device\nibsta = 0x%x iberr = %d\n",
ibsta, iberr);
return 1;
}
/*
* Clear the internal or device functions of the device. If the
* error bit ERR is set in ibsta, call GPIBCleanup with an error
* message.
*/
ibclr (Dev);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to clear device");
return 1;
}
/*
* ========================================================================
*
* MAIN BODY SECTION
*
* In this application, the Main Body communicates with the instrument
* by writing a command to it and reading its response. This would be
* the right place to put other instrument communication.
*
* ========================================================================
*/
/*
* The application issues the '*IDN?' command to the power supply.
*/
ibwrt (Dev, "*IDN?\n", 6L);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to write to the Power Supply");
return 1;
}
/*
* The application reads the identification code in the form of an
* ASCII string from the power supply into the ValueStr variable.
*/
ibrd (Dev, ValueStr, ARRAYSIZE);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to read data from Power Supply");
return 1;
}
/*
* Assume that the returned string contains ASCII data. NULL
* terminate the string using the value in ibcntl which is the
* number of bytes read in. Use printf to display the string.
*/
ValueStr[ibcntl - 1] = '\0';
printf("Data read: %s\n", ValueStr);
/*
* ========================================================================
*
* CLEANUP SECTION
*
* ========================================================================
*/
/* The device is taken offline. */
ibonl(Dev, 0);
return 0;
}
/*
* After each GPIB call, the application checks whether the call
* succeeded. If an NI-488.2 call fails, the GPIB driver sets the
* corresponding bit in the global status variable. If the call
* failed, this procedure prints an error message, takes the device
* offline and exits.
*/
void GPIBCleanup(int Dev, char* ErrorMsg)
{
printf("Error : %s\nibsta = 0x%x iberr = %d (%s)\n",
ErrorMsg, ibsta, iberr, ErrorMnemonic[iberr]);
if (Dev != -1)
{
printf("Cleanup: Taking device off-line\n");
ibonl (Dev, 0);
}
}

27,374

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 单片机/工控
社区管理员
  • 单片机/工控社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧