NI Home > Community > NI Discussion Forums

LabWindows/CVI

Reply
Member
Andrew_H
Posts: 4
0 Kudos

Fatal runtime error 'General Protection Fault' when opening GPIB communication

The viOpen command below results in a fatal error when i run a relatively simple program

        /*- Open instrument session ---------------------------------------------*/
            if ((Connect_status = viOpenDefaultRM (&rmSession)) < 0)
                return Connect_status;

            if ((Connect_status = viOpen (rmSession, "GPIB0::8::INSTR", VI_NULL, VI_NULL, (ViPSession)i_Session)) < 0) {
                viClose (rmSession);
                return Connect_status;
            }

The error is 
FATAL RUN-TIME ERROR:   "gpibrw.c", line 64, col 35, thread id 0x00000588:   The program has caused a 'General Protection' fault at 001B:631431C4.

It was initially causing my own program to crash, but i've since copied those lines into the NI GPIB demo code.  Same result.

Using LabWindows 8.0.1 (356) on Windows XP SP1
Visa drivers are installed - the manufacturer's program has no trouble communicating with the device.  However with the code above (which works fine on older installations i'm assured), i can't open the visa session.

Any help welcome.

Regards,
Andrew
Active Participant
jr_2005
Posts: 868
0 Kudos

Re: Fatal runtime error 'General Protection Fault' when opening GPIB communication

The last parameter of viOpen() is expecting an address into which the function can write - are you sure that your variable i_Session represents a valid address at this point in your program? How it is declared and initialised?

JR

Member
Andrew_H
Posts: 4
0 Kudos

Re: Fatal runtime error 'General Protection Fault' when opening GPIB communication

It is declared as a global variable at the beginning of the program.
int i_Session = 0;
Then cast to a ViPSession during the call.
Active Participant
jr_2005
Posts: 868

Re: Fatal runtime error 'General Protection Fault' when opening GPIB communication

There is your problem, then. Simply casting to a pointer type is not enough - you need to tell the compiler to take the variable's address in the call to viOpen().  Without the address operator, the value 0 is passed to the function, resulting in the GPF when it tries to write to memory location 0. Unfortunately, the use of the cast probably prevented the compiler from giving you a warning about this. Try:

    viOpen (rmSession, "GPIB0::8::INSTR", VI_NULL, VI_NULL, (ViPSession) & i_Session);
JR
Member
Andrew_H
Posts: 4
0 Kudos

Re: Fatal runtime error 'General Protection Fault' when opening GPIB communication

That makes sense, my mistake, thanks for the advice.  The situation's now better, but i still get an error, though this time it's not fatal.

NON-FATAL RUN-TIME ERROR:   "Flux Manager.c", line 4495, col 43, thread id 0x00000B2C:   Function viOpen: (return value == -1073807343 [0xbfff0011]). Insufficient location information or the requested device or resource is not present in the system.

The program now knows where to write, but doesn't seem to like opening the visa session.

Member
Andrew_H
Posts: 4
0 Kudos

Re: Fatal runtime error 'General Protection Fault' when opening GPIB communication

aha!
this time it was just that my GPIB address was wrong.  I've got 2 devices on the bus, and i can now communicate with 1 of them, so at least the visa session is working!