Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

GPIB commands

I am learning how to write a program to communicate with GPIB port. I look at MAX help for a list of commands, however, it's not detailed enough. eg. I am now looking at CNi4882Device::Clear(). The help file only tells that the function returns int, but I want to know which value of int represent which error code. So I am looking for a more in-detailed manual. Do you have one? By the way, it will be nice if you let me know the error code that the CNi4882Device::Clear() return. And can I clear the GPIB before I send any data to it?

Thanks
0 Kudos
Message 1 of 3
(3,862 Views)
Irene,

First the easy technical answer: You can call IBCLR any time, you don't need to have sent anything to the instrument first.

I noticed you posted a similar question earlier, so I wanted to try and get some clarification about what you're trying to do. The function you referred to in both posts, CNi4882Device::Clear(), is part of the Measurement Studio C++ API for GPIB. However, you mentioned that you're working in C. If you're planning to use Microsoft Visual C++ and have Measurement Studio, the set of CNi4882- classes are a good way to go. But if you're using another compiler, or are limited only to using ANSI C, or don't have Measurement Studio, that won't be an option.

In regards to your questions about error codes - by default, the C++ API's throw exceptions rather than return status codes. To check the status codes, you must first catch the exception:

try
{
CNi4882Device g("dev1");
g.Clear();
}
catch (CNi4882Exception* e)
{
int code = e.GetError();
}

Alternatively, you can call CNiException::SetExceptionMode(false) to cause the 488.2 interface to return status codes instead of throwing exceptions. If you want the check specific error codes, there are a set of error constants defined on the CNi4882 class, such as CNi4882::ErrorTimeout, ErrorBoardNotCiC, etc. You can find these in the documentation. They are defined in the file Ni4882.h. To determine exactly which error codes a function could return, you will need to correlate the C++ API's entry points to their C counterparts (i.e., CNi4882Device::Clear() in C++ to ibclr in C.) and check the help for the C method to see what error codes it can return. However, it's rare to actually need to check for specific error codes - can you tell me a little more about what you're trying to do with your error handling code?
Message 2 of 3
(3,839 Views)
I am writing a program with Microsoft visual C++ and measurement studio. Sorry I was too genaric. Acutally I just want to clear the GPIB buffer and want to see what the function returns when it clears (eg. I am just hoping it might return a code teling me that my GPIB buffer has some data left ...that way I know that my GPIB buffer really collects junks). And the reason why I want to see if my GPIB buffer has junk in it is because the motion controller sometimes runaway after I improperly shut down something in the same system as the motion controller. It sometimes runaway, but sometimes doesn't so it's kinda unpredictable so I want to really see if the junk in GPIB is really the cause. I'll try your code.
0 Kudos
Message 3 of 3
(3,799 Views)