03-22-2012 02:35 AM
I have an "error: 'Ibsta' was not declared in this scope.
I'm trying to program test equipments using C++ and GPIB but so far, I have this problem.
I'm sorry but my knowledge of C++ is very limited as I only took a module on it for about 4 months in college and now I need to rectify it for my project urgently. Any help would be much apprciated, I tried searching the forums but I have yet to find an answer. I think it has something to do with my linker. Btw, I'm using Code Blocks to compile by program so it might be different from the other IDEs posted here such as Borland, Microsoft Visual C++ and Dev C++.
The program I'm writing is as follows:
#include <windows.h>
#include "ni488.h"
#include <stdio.h>
#include <cstdlib>
#include "decl-32.h"
#include <iostream>
using namespace std;
void GpibError(const char * msg); /* Error function declaration */
int Device = 0; /* Device unit descriptor */
int BoardIndex = 0; /* Interface Index (GPIB0=0,GPIB1=1,etc.) */
int main() {
int PrimaryAddress = 28; /* Primary address of the device */
int SecondaryAddress = 0; /* Secondary address of the device */
char Buffer[101]; /* Read buffer */
/*****************************************************************************
* Initialization - Done only once at the beginning of your application.
*****************************************************************************/
Device = ibdev( /* Create a unit descriptor handle */
BoardIndex, /* Board Index (GPIB0 = 0, GPIB1 = 1, ...) */
PrimaryAddress, /* Device primary address */
SecondaryAddress, /* Device secondary address */
T10s, /* Timeout setting (T10s = 10 seconds) */
1, /* Assert EOI line at end of write */
0); /* EOS termination mode */
if (Ibsta() & ERR) { /* Check for GPIB Error */
GpibError("ibdev Error");
}
ibclr(Device); /* Clear the device */
if (Ibsta() & ERR) {
GpibError("ibclr Error");
}
/*****************************************************************************
* Main Application Body - Write the majority of your GPIB code here.
*****************************************************************************/
ibwrt(Device, "*IDN?", 5); /* Send the identification query command */
if (Ibsta() & ERR) {
GpibError("ibwrt Error");
}
ibrd(Device, Buffer, 100); /* Read up to 100 bytes from the device */
if (Ibsta() & ERR) {
GpibError("ibrd Error");
}
Buffer[Ibcnt()] = '\0'; /* Null terminate the ASCII string */
printf("%s\n", Buffer); /* Print the device identification */
/*****************************************************************************
* Uninitialization - Done only once at the end of your application.
*****************************************************************************/
ibonl(Device, 0); /* Take the device offline */
if (Ibsta() & ERR) {
GpibError("ibonl Error");
}
}
/*****************************************************************************
* Function GPIBERROR
* This function will notify you that a NI-488 function failed by
* printing an error message. The status variable IBSTA will also be
* printed in hexadecimal along with the mnemonic meaning of the bit
* position. The status variable IBERR will be printed in decimal
* along with the mnemonic meaning of the decimal value. The status
* variable IBCNT will be printed in decimal.
*
* The NI-488 function IBONL is called to disable the hardware and
* software.
*
* The EXIT function will terminate this program.
*****************************************************************************/
void GpibError(const char *msg) {
printf("%s\n", msg);
printf("Ibsta() = 0x%x <", Ibsta());
if (Ibsta() & ERR ) printf(" ERR");
if (Ibsta() & TIMO) printf(" TIMO");
if (Ibsta() & END ) printf(" END");
if (Ibsta() & SRQI) printf(" SRQI");
if (Ibsta() & RQS ) printf(" RQS");
if (Ibsta() & CMPL) printf(" CMPL");
if (Ibsta() & LOK ) printf(" LOK");
if (Ibsta() & REM ) printf(" REM");
if (Ibsta() & CIC ) printf(" CIC");
if (Ibsta() & ATN ) printf(" ATN");
if (Ibsta() & TACS) printf(" TACS");
if (Ibsta() & LACS) printf(" LACS");
if (Ibsta() & DTAS) printf(" DTAS");
if (Ibsta() & DCAS) printf(" DCAS");
printf (" >\n");
printf ("Iberr() = %d", Iberr());
if (Iberr() == EDVR) printf(" EDVR <Driver error>\n");
if (Iberr() == ECIC) printf(" ECIC <Not Controller-In-Charge>\n");
if (Iberr() == ENOL) printf(" ENOL <No Listener>\n");
if (Iberr() == EADR) printf(" EADR <Address error>\n");
if (Iberr() == EARG) printf(" EARG <Invalid argument>\n");
if (Iberr() == ESAC) printf(" ESAC <Not System Controller>\n");
if (Iberr() == EABO) printf(" EABO <Operation aborted>\n");
if (Iberr() == ENEB) printf(" ENEB <No GPIB board>\n");
if (Iberr() == EOIP) printf(" EOIP <Async I/O in progress>\n");
if (Iberr() == ECAP) printf(" ECAP <No capability>\n");
if (Iberr() == EFSO) printf(" EFSO <File system error>\n");
if (Iberr() == EBUS) printf(" EBUS <Command error>\n");
if (Iberr() == ESTB) printf(" ESTB <Status byte lost>\n");
if (Iberr() == ESRQ) printf(" ESRQ <SRQ stuck on>\n");
if (Iberr() == ETAB) printf(" ETAB <Table Overflow>\n");
if (Iberr() == ELCK) printf(" ELCK <Lock error>\n");
if (Iberr() == EARM) printf(" EARM <Ibnotify rearm error>\n");
if (Iberr() == EHDL) printf(" EHDL <Invalid Handle>\n");
if (Iberr() == EWIP) printf(" EWIP <Wait already in progress>\n");
if (Iberr() == ERST) printf(" ERST <Notification cancelled due to reset>\n");
if (Iberr() == EPWR) printf(" EPWR <Power error>\n");
printf("Ibcnt() = %u\n", Ibcnt());
printf("\n");
/* Call ibonl to take the device and interface offline */
ibonl(Device, 0);
exit (1);
}
The program I got is a sample I found from the National Instrument Software called Explore GPIB.
Solved! Go to Solution.
03-22-2012 02:37 PM
Look at the RdWrt.c file in C:\Documents and Settings\All Users\Documents\National Instruments\NI-VISA\Examples\C\General
It is simpler and easier to understand.
I prefer to work with VISA.
03-22-2012 08:26 PM
how do I download VISA??
03-22-2012 08:29 PM
03-22-2012 10:34 PM
Thank you for replying nyc.
Ok, I have downloaded VISA and opened the Rdwrt.c file as you have suggested, but a couple of problems arise as I tried compiling the program as it couldnt detect the "visa.h" and "visatype.h" file. So I searched for the relevant header files and copied them to my Codeblocks MingW include folder but now I have a new error stating that it has : undefined reference to 'viOpenDefaultRm@4' and a couple of other lines similar like this.
Is it a linker problem?
I'm really sorry as I'm really new to programming test equipments.
03-23-2012 08:32 AM
Hi,
Back in 2008 with NI-488.2 for Windows, Version 2.6, the C/C++ programming language interface was split into 2. The traditional one is the GPIB-32 API which uses the header files, ni488.h or decl-32.h, which are linked to gpib-32.obj. Also the global variables, ibsta, iberr, ibcnt/ibcntl, are simply variables.
The newer one is the NI4882 API uses the ni4882.h header and links to ni4882.obj. The sample programs that are included when you install NI-488.2 are written using the newer API. With the new API, the global variables have been updated to be function calls, Ibsta(), Iberr(), and Ibcnt().
The sample program that you have modified is referring to the GPIB-32 API by including the ni488.h and decl-32.h files and you are probably linking it to gpib-32.obj. But the sample program that is installed uses the new Ibsta() function rather than the global variable. That is why you are seeing the error about Ibsta() not declared.
If you want to modify a sample program that uses the traditional GPIB-32 API, you can download the samples from here:
Language Interface: 32-bit Microsoft Visual C/C++
If you want to learn more about the differences between the two APIs, please refer to:
Differences Between the GPIB32 API and the NI4882 API
Hope this information helps.
gpibtester
03-25-2012 11:20 PM
thank you for your help gpibtester.
now I got this error : undefined error to
I have attached my errors and the headers I have included to the files below.
03-26-2012 08:27 AM
Hi,
Sorry to hear that you are still having problems. Thanks for attaching the screenshots. In the column on the left, the project lists both APIs under Others. If you want to use the newer NI4882 API, then you only need to include ni4882.obj. Try removing gpib-32.obj and I think your compile/link problems should go away.
gpibtester
03-26-2012 08:35 PM
the problem still doesn't seem to go away....:'(
I think it's my linker settings. I don't seem to have the appropriate library linked to my program.
if it really is the problem where do you think I can find the correct library?
03-26-2012 11:09 PM
Oh yeah, 1 more question. If my program is using the traditional API with traditional global variables ibsta, iberr etc....., would I need to use the ni488.h headers or can I just use the new ni4882.h header and link to ni4882.obj?