You don't have to poll.
The fact that you want a non-LabVIEW application to get notification is
another problem (I'll talk about later on). The FPGA can send notifications
to a LabVIEW VI (or app. or dll) through a FIFO or queue. Basically, the
FPGA uses a case with a queue in it, and when the case switches, it puts an
element on the queue. You'll have to program that the elements get queued
only when a state changes, but that's as easy as using an XOR over the
current and the previous value... On the host VI, you'll get a queue
nitification. In a way, you still need to poll the data. The time out of the
read queue isn' working properly, so if yuo put it to e.g. 100000, the
processor will be 100% occupied... So, in a while loop you read the queue,
if it has an element, read it (you get an array of elements, so you can use
a for loop to process each element)... Still sound a lot like polling. But a
difference is that the queues use DMA, and that should be pretty efficient.
If you put the time out on 0, and you put a 2 ms wait in the loop, it hardly
uses processor time. You only have 3 channels though, but you can merge a
channel ID, and a state in an integer to get as much channels as you
require.
On the external program, there are but a few options. You can call a
function that quits only when a signal is received. This is not very
practical, since the rest of the application hangs, and you'll have to
create seperate threads. A callback is a good mechanism for this. It's
standard in C/C++, but not that easy to do in LabVIEW. Normally, the
question is make a vi that acts as callback, in your case you want to call a
callback. So you need to be able to call a function at a given pointer. The
main application needs to tell the LV dll what this pointer is. So you make
a function "WaitForStateChange" with a pointer parameter. The application
puts it's callback functions' pointer there when the function is called. To
do this, a long time ago I've created a dll (called calldlldll.dll). Check
out
http://forums.ni.com/ni/board/message?board.id=170&thread.id=39381&view=by_date_ascending&page=2 .
The example gets a pointer from LoadLibrary, GetProcAddress. In your case,
use the given pointer. The parameters should be the same, as if you where
calling the original function with a dll.
Regards,
Wiebe.