LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Strange "Call Library function" behaviour


smercurio_fc wrote:
 exactly is "not good for you"? Does it generate an error? Does it not perform the operations? As I noted, since you have a static class, you should not be wiring a .NET constant to the Invoke nodes. Thus, delete that little .NET constant that you have on your block diagram, and specify the class to use directly with the Invoke Node. 

 

As for the DLL, we can't run the DLL, so there's no way to test this. Have you verified that you're passing the correct values to the function? Like the correct password?


My .NET vi is able to connect to the device without generating error (with and without the constant I have same result). Yesterday I tried to develop the .NET vi but I wasn't able to accomplish my goal. After connection is possible to ask the device to send one of the 8  video stream (attached you can find description of this function).

 

With .NET I wasn't able to understand how to build the code for this. With CLN I cannot try because the connection does't work (and in this case to It will be not easy because there is a callback function that I don't know how to face).

 

In any case I think you can run the DLL because if you pass an IP address of a NON EXISTING device the function return "Connection Fail" (correctly) and not "Operation fail2" (not correct!!).

 

Thanks for your time

Golzio

Download All
0 Kudos
Message 11 of 21
(1,206 Views)

smercurio_fc wrote:
.......... Have you verified that you're passing the correct values to the function? Like the correct password?

Yes I'm sure because I compile a C version of the code and It works with these same parameter and always give the correct answers!!

0 Kudos
Message 12 of 21
(1,204 Views)

Golziante wrote:
My .NET vi is able to connect to the device without generating error (with and without the constant I have same result). Yesterday I tried to develop the .NET vi but I wasn't able to accomplish my goal. After connection is possible to ask the device to send one of the 8  video stream (attached you can find description of this function).

The PDF you attached explains the function in the DLL, not the .NET one. There would be different documentation for the .NET library. Where did this library come from?

 


In any case I think you can run the DLL because if you pass an IP address of a NON EXISTING device the function return "Connection Fail" (correctly) and not "Operation fail2" (not correct!!).


When I tried to run your example using the DLL I couldn't get past the Init - it returned a -1, which I assume is an error. I don't know since I don't have the documentation for this DLL. The DVRRESULT indicator was "DVRErrOperationFail". Most likely because I can't create a proper handle.

 

0 Kudos
Message 13 of 21
(1,189 Views)

smercurio_fc wrote:
...........When I tried to run your example using the DLL I couldn't get past the Init - it returned a -1, which I assume is an error. I don't know since I don't have the documentation for this DLL. The DVRRESULT indicator was "DVRErrOperationFail". Most likely because I can't create a proper handle.

 


I check the DVRInit function and I made a mistake considering that function working ok. In fact in my opinion that function has to return 0 or 1 according to the passed argument.

 

The manual only state this: 

 

BOOL DVRInitLibrary (bool bIsWindowApp = true);

 

It loads and initializes OpenAPI dll (Dynamic Link Library).

 

Reference

 

- Parameters:

true (Default): Use Windows Message

false: Console Type Application, CallBack notification goes to child thread or DLL

- Return Value: TRUE or FALSE

 

 

I never implement a function with BOOL using CLN and for this reason I consider it I32 as you can see from my labview code. All the documentation come from Honeywell and I attached here a zip file.

 

Regards

Golzio

0 Kudos
Message 14 of 21
(1,176 Views)

BOOL is defined as an int in WinDef.h, with TRUE = 1 and FALSE = 0. I have no idea why the function call is returning -1 when I try it. It also promptly freezes up LabVIEW after a while.

 

The .NET assembly they provide is a wrapper around each function, providing nice datatypes to deal with in LabVIEW. You had said your problem with the .NET assembly wasn't really with .NET, but rather what you're supposed to put in the loop. I certainly can't answer this question since I don't know this library, and haven't a clue as to how to use it. There are several examples with the documentation you provided, so they should be able to tell you what you're supposed to put in the loop. 

0 Kudos
Message 15 of 21
(1,157 Views)

Some updates:

 

I discover the reason of the generic error that I didn't understand. Although the documentation specify that "You must copy OpnDVRLib.dll into your application directory" this is not enough. There are more file that has to copied together with DLL (some of this file with extension .DSI!!!). Same thing for .NET dll.

 

I continue to investigate the .NET approach too. I was able to connect to the device and request the first frame specifying date and time. Now I have to get the image frame using the following function:

 

 

DVRRESULT WINAPI DVRSearchGetImage( HANDLE SearchHandle,
INT nCamera,

LPVOID lpBuffer,

INT nBufferSize );

 

Attached there is the labview source code. All the function returns correctly but not DVRSearchGetImage. I think that the problem is how I pass the temporary image buffer lpbuffer (I highlighted  this point into the attached jpeg).

May some Labview user help me in using this IntPrt contructor??

 

Thanks

Golzio 

 

 

 

Download All
0 Kudos
Message 16 of 21
(1,106 Views)

The function you are showing the prototype of seems very much like a C prototype. But then you go and call that with .Net. That looks a bit suspicious to me.

 

Also before you call the GetImage function you also retrieve some properties or something among them also the nCamera. Another one seems to be dwImageSize. I haven't read the API documentation but I would very much guess that it is not enough to only instantiate an IntPtr but that you have also to size that IntPtr to the proper size before passing it to GetImage  function. The IntPtr consructor is most likely not the right one here.

 

Instead you should probably alloc the necessary amount of memory using a .Net MemAlloc method of some kind with the size you got from the  dwImageSize Parameter. Not sure which .Net method you should use for that though.

Rolf Kalbermatter
My Blog
0 Kudos
Message 17 of 21
(1,089 Views)

rolfk wrote:

............it is not enough to only instantiate an IntPtr but that you have also to size that IntPtr to the proper size before passing it to GetImage  function. The IntPtr consructor is most likely not the right one here.

 


Absolutely CORRECT!!! I made some trials sizing IntPtr but without success!! I choose IntPtr because that one is automatically proposed by .NET labview node but, at the moment I'm not able to inizialize it with proper size.

In my C version of that function I instantiate a pointer to an U8 array (initialized with dwimageSize size).

 


rolfk wrote:

 

Instead you should probably alloc the necessary amount of memory using a .Net MemAlloc method of some kind with the size you got from the  dwImageSize Parameter. Not sure which .Net method you should use for that though.


 

 I will try this advice thank you Rolfk......I'm a newbbie using :NET Smiley Tongue

 

Bye

Golzio

 

 

 

0 Kudos
Message 18 of 21
(1,076 Views)

rolfk wrote:

 

Instead you should probably alloc the necessary amount of memory using a .Net MemAlloc method of some kind with the size you got from the  dwImageSize Parameter. Not sure which .Net method you should use for that though.


Attached there is a picture showing Marshal .NET class for allocating memory. Now the function for getting image returns successfully but I don't know how to copy the memory that i allocate in a Labview Array. I will work for this during the afternoon.

 

Thank you again Rolfk 

Golzio

0 Kudos
Message 19 of 21
(1,066 Views)

Most likely you want to use the Marshal.Copy method for that. Look for the variant that copies from an IntPtr to an Byte Array which then will be a native LabVIEW byte array which you have to allocate accordingly using the Initialize Array node, before passing to this method.

 

Net exactly high performance and it would have been easier if your .Net assembly also supported an unmanaged variant of the GetImage method, where you could pass in that byte array directly.

Rolf Kalbermatter
My Blog
0 Kudos
Message 20 of 21
(1,055 Views)