LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling Java method with .NET VIs

I'm starting a program that is using the .NET VIs to make calls to a Java API .dll.  The problem is that the method I'm calling doesn't return a value.  The call looks like this: read(int startAddr, boolean readContinue, byte[] readBuf, int offset, int len) and the value I'm trying to get is readBuf, but LabVIEW only sees it as an input because the varaiable is actually just a reference in Java.  I can't pass it a reference to a byte array because the invoke node is looking for an actual byte array.  Is there any way to call this Java method and get the value of readBuf?  I've attached the invoke node to show what I mean.
0 Kudos
Message 1 of 5
(3,099 Views)
*shakes his head sadly* I'm afraid you have just run into a bug that I must take "credit" for. Due to a seperate problem that existed in LV 7's support for .NET, we decided to put in detailed code to ensure that our Invoke nodes had the right in/out settings. Unfortunately, I forgot to take into the case that you have run into - an input only parameter where the data is copied by LV. If it were something like an ArrayList, it would work fine because we pass that by reference (refnum wire in LV). But in this case, we copy the LV data into .NET data...but not back again. Special case condition I missed - my apologies....
 
To work around the problem in LV 8, you need to either
 
a. Create a wrapper assembly - Fairly simple code that is the same signature as the one you want to call, but where the byte[] is by "ref", such as
 
read(int startAddr, boolean readContinue, ref byte[] readBuf, int offset, int len)
 
Then just turn around and call the true method inside your wrapper.
 
b. Use the .NET reflection API to call this particular method. Reflection isn't a pretty API but it is fairly simple. If you decide to go this way, let me know and I can give some pointers if you need them.
0 Kudos
Message 2 of 5
(3,071 Views)

I found a solution.  The people that made this API also made a COM object, and they replaced the byte[] with a seperate class called ByteArray that takes a reference, so everything works now.  However, maybe you can help with a problem I'm now having.  In the write() function, LV takes a couple ints and this ByteArray as inputs.  The ByteArray is a variant, so I convert the ref to variant data, the same way I did in read(), but the method call gives me an error saying "Invalid number of parameters."  Any idea what this could mean?  LV loads the number of parameters from the method's signature, and there is only one version of this particular method.

 

Thanks for your help

0 Kudos
Message 3 of 5
(3,067 Views)
I'm assuming you are calling the COM object directly with the ActiveX nodes, not using the interop assemblies in .NET? If that is the case, I'm not sure what it is complaining about. If the COM interface is an IDispatch interface, then it receives the arguments as an array and makes the decision internally whether it got everything it needed. If the type library for the method differs from the internal implementation, it could cause the problem - but that would be surprising. I'm sure it's something else, I just can't think what it would be.
0 Kudos
Message 4 of 5
(3,059 Views)
Yes, I'm using the ActiveX nodes.  I changed the whole program so it doesn't use .NET anymore.  Although I think the COM .dll just references the functions in the .NET assembly.  In which case, the same function is being called, so it should work since it did when I used direct calls to the .NET assembly.  If worse comes to worse I could just use 2 different APIs for reading and writing, but I don't really want to do that.  Thanks for your help, if anything comes to mind let me know, otherwise I'm sure I'll figure something out.
0 Kudos
Message 5 of 5
(3,057 Views)