LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW not seeing Occurrence set in DLL

I have a LabVIEW VI, which calls a DLL (that I've written in Borland C) and then waits for the DLL to set an occurrence. However, it never sees the occurrence.

I've checked the following:
1) The DLL is running
2) The Occurrence value that is used in the DLL is the same as the one being waited for in LabVIEW
3) The VI does detect occurrences in general (set in a subVI, for testing and for exit)

I have an example dll and VI which works, so I know that it is possible. Any ideas why it's not working for me? I've done a check on the error code returned by the Occur() call in the DLL, and it seems to be 1: does this indicate success, error, warning? And is there any documentation anywhere on error codes returned by Occu
r()?

Thanks!
0 Kudos
Message 1 of 14
(3,608 Views)
Error code 1 usually indicates "Bad Parameter", meaning one of the arguments to the call is invalid. (Use General Error Handler to find this out).

I don't know specifically about the Occur() call, but I would guess that it means the refnum you passed it is not valid.

You say you checked the Occurrence "value" (refnum. I assume) between the DLL setting it, and the VI waiting for it - how did you check this?

I assume you're passing the refnum from VI to DLL.

I would double-check whether you're passing the right refnum to the Occur() call, or maybe you're passing a pointer to it, or a handle to it, or something else.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 2 of 14
(3,608 Views)
You're right, there's definitely something wrong with the parameter as I'm receiving it in the dll.

I managed to find some data on Occur(), and an error code of 1 is "mgArgErr" which means "not a valid user event" - which I assume means that the Occurrence parameter is invalid.

Here's what I'm doing:
In LV, I've wired the output from "Generate Occurrence" into my dll call. The dll function parameter is configured as "adapt to type", and "handles by value". For testing purposes, I've also cast the Occurrence to a I32, and pass that as a 2nd parameter of the dll function.

In my dll (in C), I've declared the function as follows:
BeginGetData(LVRefNum* MyOccurrenceToSet, int Arg) (with all the dll export stuff in front of it). The Occur call looks
like this:
MgErr result = Occur(*MyOccurrenceToSet);

If I put a probe on the I32 typecast value in LV, I get the same number as if I do a fprintf on *MyOccurrenceToSet in the dll function call, so I assume that the Occurrence is being passed correctly - although I may well be using it wrongly. Casting *MyOccurrenceToSet to an Occurrence does not seem to do anything.

I have an example VI & dll which I downloaded from a posting on one of the forums, and that works perfectly - and from what I can see, all my types are the same and the calls are done in the same way, so I don't understand why mine is not working.
0 Kudos
Message 3 of 14
(3,608 Views)
> I've checked the following:
> 1) The DLL is running
> 2) The Occurrence value that is used in the DLL is the same as the one
> being waited for in LabVIEW
> 3) The VI does detect occurrences in general (set in a subVI, for
> testing and for exit)
>

One possibility is that the VI that created the occurrence is no longer
running. An occurrence is a refnum that gets garbage collected when the
VI goes idle. Error 1 coming from the Occur() function will also be
explained by the Explain Error dialog in the Help menu. It is a pretty
generic Argument error, which basically means that the occurrence refnum
wasn't created by LV or is no longer valid.

So make sure the occurrence constant is in a running or sleeping VI, and
I think it will work just fine.


Greg McKaskle
0 Kudos
Message 4 of 14
(3,438 Views)
In LV, I've wired the output from "Generate Occurrence" into my dll call.  The dll function parameter is configured as "adapt to type", and "handles by value".

So, what's on the stack is a HANDLE to a refnum. ( **RefNum )

In my dll (in C), I've declared the function as follows:
BeginGetData(LVRefNum* MyOccurrenceToSet, int Arg)

But you're declaring it here as a POINTER to a refnum ( *RefNum ).


MgErr result = Occur(*MyOccurrenceToSet);

You've told it that "MyOccurrenceToSet" is a POINTER to a RefNum (not true), so it thinks that * MyOccurrenceToSet is a RefNum (not true).

What does the prototype for Occur() want? A RefNum, or a POINTER to a RefNum?


Check the example you downloaded and see if it
passes a RefNum, a *RefNum, or a **RefNum.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 5 of 14
(3,608 Views)
Okay, that makes sense once you know that "handles by value" is a **RefNum.

So if a **RefNum is on the stack, I should declare
BeginGetData(LVRefNum** MyOccurrenceToSet, int Arg), so it receives it properly.

Now there's a bit of confusion: the docs say that Occur() takes a RefNum, and looking at the headers Occur() takes a MagicCookie, which is #defined as a LVRefNum. However, the compiler complains that it is expecting a MagicCookie_t*, don't ask me why!
0 Kudos
Message 6 of 14
(3,608 Views)
You really ought to let LabVIEW generate the prototype for you (Generate C file), but AFTER you set all the pass by handle, pass by pointer, etc. stuff.

I've heard tell of LV 7 making mistakes in this area, but I can't vouch for it one way or the other. Are you using LV 7?
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 7 of 14
(3,608 Views)
If I let LV generate the prototype, I get:
BeginGetData(Occurrence* MyOccurrenceToSet)

So the call to Occur() should look like this:
Occur(*MyOccurrenceToSet), if Occur() wants an Occurrence rather than a pointer to an Occurrence. But this still doesn't work.

I am using LV7, so I guess the prototype could be wrong: if I go with BeginGetData(Occurrence** MyOccurrenceToSet), and call Occur() with **MyOccurrenceToSet, I get a memory error (which makes sense: I'm obviously dereferencing something which isn't a pointer, so I'm ending up somewhere illegal).
0 Kudos
Message 8 of 14
(3,608 Views)
A good point, but the VI is definitely running: I have a loop polling for an exit button press (with a 100ms delay) - if the exit button is pressed, an Occurrence is generated to allow the WaitForOccurrence to finish and the VI to exit. That Occurrence is being noticed, and it uses the same refnum as the one in the dll function call.

Thanks for the suggestion anyway.
0 Kudos
Message 9 of 14
(3,438 Views)
All right, but I still bet the problem is in this area.

I just reviewed the dialog I had with another user last month:
http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=137&HOID=506500000005000000590E0100&HTHREAD=000069209&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0

We came to the conclusion that the LabVIEW-generated C file is wrong, in some cases.

Specifically, in his case, LV was passing a handle, but incorrectly declaring it to be a POINTER to a handle.

Whether that applies to you or not, I don't know.

But it's worth a try - make a run assuming that where LV says it's passing a *RefNum, it's really a RefNum, and see it it works. It's not likely to crash any worse than wh
at you have now.

If that's it, then I strongly suggest you contact tech support and report this - that's a BIG issue.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 10 of 14
(3,608 Views)