02-21-2017 08:05 AM - edited 02-21-2017 08:10 AM
Hello,
As I mentionned in title, I try to interface a scope HS4 from TiePie with Labview.
For this, I have a dll file from the manufacturer. I already implemented a lots of functions (and it works) but two are missing.
The first one is a callback function and the second one is using event (see pic below):
I don't know how I have to proceed to translate these functions into Labview...
If somebody can help me...I already had a look on the forum but no good answers...
Thanks.
Solved! Go to Solution.
02-22-2017 09:28 AM - edited 02-22-2017 09:29 AM
Well callback without a wrapper DLL written in C is not a feasible solution. There are theoretical ways to do it, but they involve so much of playing C compiler on the LabVIEW diagram to such an amount that I could write a book about it and virtually nobody would be able to reproduce it anyhow. Basically at the point where you can do it, you have so much of C programming knowledge, that writing a wrapper DLL is factors faster than trying to do the pointer vodoo on the LabVIEW diagram yourself. And besides, the wrapper DLL in C is many times more easy to maintain and debug than trying to play assembly language code generation on the LabVIEW diagram.
The HEVENT is a Windows API element. You can call the function CreateEvent() in kernel32.dll to create such an event, and then WaitForSingleObject() in the same DLL to wait for the event to be triggered. It's workable but not very LabVIEW friendly. The WaitForSingleObject() will basically block until your library triggers your event, the dwMilliseconds timeout occurs, or you issue the SetEvent() function for that event handle yourself in some other part of your code. Always close the event created with CreateEvent() after you are done with it by calling CloseHandle() on the event handle.
02-23-2017 01:49 AM
Thanks a lot for your answer! I unsderstand a little bit more the way to do it!
Do you have an example of C wrapper or the way to do it?
02-23-2017 04:02 AM
I tried this for the event....
But the code doesn't detect an event only a timout (100ms), I don't know if it the good way to proceed...
02-23-2017 06:21 AM - edited 02-23-2017 06:25 AM
A picture may say more than 1000 words sometimes, but a LabVIEW program is a lot more than a simple picture. By just posting the pic, you show us only a tiny part of what you are doing. Yes I do not have the hardware to run the DLL on my computer, but I could go into the VIs and check what you have done and if there was a problem somewhere if I had the VIs. In this way all I can say is that it looks ok except that you probably should not continuously call the SetDataReadyEvent() inside the loop but only once before you go into the loop, maybe even before you do the ADC Start.
Also Windows events can be a bit tricky in that they can be created in signaled and non signaled state originally and once signaled need to be reset to detect another signal. You can also set them with flags during creation to either autoreset after a Wait has been triggered or to require explicit resetting. All nice features that make them very powerful but one of these settings wrong and it simply won't work. Reading the MSDN page about those functions very carefully is an absolute requirement.
02-24-2017 07:28 AM
Thanks for your help, I put the SetDataReadyEvent() before the ADC start and I modified a bit the code, and now, all is working fine.
09-30-2021 12:41 AM
Hello, can you send me the source code of your Labview program?