Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help using NI-488.2 with C++

First some background. I have an existing Windows application (written in MS Visual C++ 6.0) that essentially acts like a printer/plotter. There is a worker thread that receives data asynchronously from a serial port and writes the data to a file for later processing.

Now some of my customers want me to add a GPIB interface in addition to the serial interface. I have downloaded every document, application note, etc., from NI's site that I could find but I'm not finding enough information to help me figure out how to add the interface.

This is what I want to do (in a nutshell):

1) Application has to run on Win95/98/NT/2K/XP. This shouldn't be any problem but I thought I'd mention it.
2) Application has to run whether the
NI-488.2 device driver is loaded or not. For this reason I'll use what NI calls "direct entry" to access the GPIB-32.DLL (i.e. use LoadLibrary(), GetProcAddress(), etc.).
3) Receive GPIB data asynchronously from an NI GPIB interface board (e.g. PCI-GPIB) using a worker thread (same as I do for serial data).

The requirement as I see it is very simple - receive data asynchronously. But for the life of me I don't see any functions in the NI-488.2 API that I can use for event notification in a worker thread. It also seems like there isn't much in the way of sample code that I could find. The sample code I did find involved sending a command to a GPIB device and then reading the data back from the device.

I'm just in the research stage so I haven't installed the NI-488.2 driver or a GPIB card. No point spending money unless I can see a reasonable chance of success.

Does anybody know of some sample code, guidelines, etc., that may help me figure out how to use the NI-488.2 d
river to receive asynchronous data using a worker thread?

Thanks,
Mike
0 Kudos
Message 1 of 12
(4,190 Views)
NI-488.2 has ibnotify, which offers asynchronous event notification. However, for your application, you are probably better off with NI-Device. This is a C++ driver with a MSVC 6.0 language interface. It allows you to create a device. All I/O received is through asynchronous event handlers.

http://sine.ni.com/apps/we/nioc.vp?cid=13047〈=US
0 Kudos
Message 2 of 12
(4,189 Views)
I saw ibnotify() and ibwait() but the problem is that I haven't found enough information to know what event to check for. For example, what event would be triggered when data is received by my GPIB board?

Also, NI-Device sounds like a possibility but I couldn't find either a user's guide or an API reference manual so I can't tell if it will do the job for me. Is the NI-Device driver a DLL that can be loaded by my application installation?

Mike
0 Kudos
Message 3 of 12
(4,189 Views)
I have copied the user manual for NI-Device to the NI ftp site.

ftp://ftp.natinst.com/incoming/nidevice.chm

NI-Device is a driver, similar to NI-488.2. However, it is a bit more of a driver framwork, meaning that it provides a base class that you derive from and event handlers that you override.
0 Kudos
Message 4 of 12
(4,189 Views)
Thanks for the help file! I've downloaded it and will read it to see if NI-Device will fit into my program. I'll probably be back with more questions after I've digested the information.

Mike
0 Kudos
Message 5 of 12
(4,189 Views)
If file NIDevice.chm is intended for viewing by all customers, could you please move it to:
ftp://ftp.ni.com/outgoing/NIDevice.chm

A notice on machine ftp.ni.com says that as of January 23, 2004, it longer allows downloads from the incoming directory.

Domain name ftp.natinst.com doesn't seem to be accessible at all, though ftp.ni.com was accessible with the above notice.

By the way, some time ago I looked at the marketing pages for NIDevice and saw two different versions with wildly different prices (I think one cost about 20 times what the other cost). Can you say what the differences are?

Also a comment for the original poster: As a non-controller, I used ibnotify() to get a callback when the LACS bit turned on, i.e. w
hen the controller told me to listen. On speculation that the controller would really follow up that command by sending me data, my callback routine did an ibrda() and ibwait() with timeout.
0 Kudos
Message 6 of 12
(4,189 Views)
I am working on getting the manual placed on ni.com in the manuals area. NI-Device Standard supports GPIB and is roughly the same cost as NI-488.2. NI-Device Plus adds support for native Ethernet (using VXI-11) and USB (using USBTMC) protocols. As other non-GPIB buses become available, they will be added to the Plus package.

A different use of ibnotify is to start an asynchronous read and do an ibnotify on CMPL TACS DCAS DTAS (if you support trigger). Then, when the read completes you will have your message in the notify callback or if you get cleared or you are requested for a response. Once you get in the notify callback, you can rearm the callback based on what you need to do. For example, if you received a command, you
would start a new read and notify on the same conditions. However, if you received a query, you would start a write and notify on different conditions. Just a thought.
0 Kudos
Message 7 of 12
(4,189 Views)
I appreciate the comments from both ndiamond and GPIB Guru. I have also reviewed all the possible software packages offered by NI and I keep coming back to NI-488.2 as the best solution for my application. NI-Device looks good but I don't like the fact that I could have 2 software packages competing for the NI hardware. Measurement Studio is too expensive for my application. VISA uses NI-488.2 but when someone installs my program the NI GPIB hardware/NI-488.2 driver may or may not exist. With NI-488.2 I can used the direct entry method to determine if the NI-488.2 driver exists and then use it if it does.

The problem I'm trying to solve is to ideally come up with a method of using NI-488.2 that can be used with Wa
itForMultipleObjects() in my worker thread. Seems like I should be able to do this using the GPIB as a listener. Still reading and learning.
0 Kudos
Message 8 of 12
(4,189 Views)
>> NI-Device looks good but I don't like the fact that I could have 2 software packages competing for the NI hardware.

If you could elaborate, I would appreciate it. Yes, both software packages CAN talk to the same hardware, but only one will be using the hardware at a time and it is not a dynamic operation (meaning there are manual steps to change it from one to the other). In that regard, they are not actually competing for the same hardware.
0 Kudos
Message 9 of 12
(4,189 Views)
The "manual steps to change..." is one that I would like to avoid I can. I don't want my customer to have to manually setup the card access if I can help it. I would like the use of my software to be completely transparent to the user - at least that's what I'm hoping for.
0 Kudos
Message 10 of 12
(4,189 Views)