LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

MIDI in using DLL callback function

I am trying to get MIDI into LV. The dll used is winmm.dll and the function midiinopen (plus others) is described here:
 
 
The main problem is I don't know how to program the Call Library Function Node properly in order to perform the call
plus set it to start receiving callback data, being midi messages. I have tried creating and registering a User Event and
passing the Event ref to the dll's "dwCallback" and then trapping the callback in an Event Structure, but nothing happens.
 
I have studied the "Communicating with a Windows MIDI Device in LabVIEW" example but it gives no hint since midi out
does not require the use of callbacks.
 
Please advice,
Stefan
0 Kudos
Message 1 of 4
(5,433 Views)


@Vedeja wrote:
I am trying to get MIDI into LV. The dll used is winmm.dll and the function midiinopen (plus others) is described here:
 
 
The main problem is I don't know how to program the Call Library Function Node properly in order to perform the call
plus set it to start receiving callback data, being midi messages. I have tried creating and registering a User Event and
passing the Event ref to the dll's "dwCallback" and then trapping the callback in an Event Structure, but nothing happens.

Damn! Need to make this post shorter as this message board just silently told me that it needs to be shorter than 5000 words and ate up my lengthy repsonse with no way to get it back.

You can't configure a Call Library Node to pass a Callback function to another function. Callback functions have been alien to LabVIEW for a long time with good reasons and what it has now as callback function in LabVIEw 7.1 and newer is not directly compatible with C callback functions.

Basically as you want to get data from the callback function back into LabVIEW there is really no way around some intermediate software layer which in this case almost surely means your own specific wrapper DLL written in C.

If you use LabVIEW 7.1 you could use user events but not in the way you describe. Attached is an example of how you can use user events from external code. Note the extra DLL you will have to write. You have to watch out what data you pass back to the user event as it has to match exactly the type you configured the user event for, otherwise LabVIEW will simply crash on you.

For numerics this is quite simply and also shown in the example. For strings you can't just pass back a C string pointer but you will have to allocate a LabVIEW string handle with

handle = DSNewHandle(sizeof(int32) + <length of C string>)

and then copy the C string into it. For specifics about how to do this you should refer to the External Code reference manual in your Online Bookshelf. Similar rules apply for arrays or clusters for that matter.

If you want or need to do this for LabVIEW < 7.1 there are two possible approaches but both are even less trivial. You could either create a wrapper DLL that translates your callback events into LabVIEW occurrences and for the data transfer back to LabVIEW you would have to implement your own queing too, or you could use the Windows Message Queue example somewhere here in the NI examples and adapt it to return your specific data. That would solve the data queueing more or less for you without having to worry about that.

Rolf Kalbermatter

Message Edited by rolfk on 05-22-2006 11:22 AM

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 2 of 4
(5,415 Views)

So I call this "wrapper" which in turn calls the dll plus handles the callback and finally triggers an event back to LV? It sounds straight forward, looking at your dll source code. However, I am unfortunately no C programmer. The function I'm trying to use returns a structure which makes the procedure even more complicated.

What about the example in the following thread, is is not applicable in my case?

http://forums.ni.com/ni/board/message?board.id=170&message.id=99400&query.id=69472#M99400

/Vedeja

Message Edited by Vedeja on 05-22-2006 07:04 AM

Message Edited by Vedeja on 05-22-2006 07:05 AM

0 Kudos
Message 3 of 4
(5,397 Views)
just found this thread while I was searching for "how to send a sysex midi message with LabView".

There is now a tutorial on receiving midi short messages (using UserEvents as stated was noted in this thread). See here: http://zone.ni.com/devzone/cda/tut/p/id/6223

And now back to figuring out how to speak to winmm.dll in order to send sysex messages using MidiOutLongMsg.

Message Edited by WildEnte on 11-05-2007 08:33 AM
0 Kudos
Message 4 of 4
(4,930 Views)