04-02-2011 03:39 PM
I'm using a .NET library (written in C#) and one of the properties I'm trying to access (using the Property Node) is a fixed byte array in the C# code, but it's seen in Labview as ".NET refnum". It won't let me input it to a function as a byte array. Labview won't even let me index the array, so I guess it's being interpreted as a single value rather than an array of values. Has anyone encountered this problem before?
This is what the code and error looks like:
04-03-2011
08:38 AM
- last edited on
05-20-2025
12:38 PM
by
Content Cleaner
Interesting, from here it looks like Labview should detect the .NET byte array correctly.
Another interesting point that it correclty detects the byte array at "CreateConnection" property at your picture.
Are these properties of the same type inside your C# code?
By the way, if during developement you change the type of properties, it better to remove all references to asseblies and rewrite from
the beginning. (At least in Labview 8.6, now may be fixed).
Michael.
04-03-2011 11:54 AM
You might need to convert the refnum into a byte array by using the .NET Object to Variant.vi function. Then investigate what the variant is. Most likely you can connect it directly to the input or optionally use Variant to Data to convert it explicitedly.
04-05-2011 11:01 AM
Thanks for the suggestion, but it hasn't quite worked. I tried making it a variant and then using the "Variant to Data" function to convert it into a byte array. This compiled but gave me an error at runtime that says this: "The data type of the variant is not compatible with the data type wired to the type input." (I wired a numeric array to the input) When I used an indicator to create a "property" for the value in question, it says it's a FixedElementField, whatever that means. I'm still not sure why it doesn't interpret the "fixed byte array" in C# as a byte array. All "fixed" means is that its length is predetermined and unchangeable. Any suggestions?
04-06-2011 06:05 PM
Based on what you've described, it sounds like everything should be working with those settings, but it'd be nice to take a closer look at it.
Would you be able to post your actual code (or at least the part that you've shown in the picture you linked) that is calling the byte array?
Also, what is your C# function prototype for your device address? Once we're able to look at your code with that known func. prototype, we can help verify your return type.
04-07-2011 11:18 PM
When I try to connect the two items with no variant, it looks like this and gives me a compile error:
http://img31.imageshack.us/img31/1825/deviceaddressconnection.jpg
When I use the .NET Object to Variant tool with the Variant to Data tool, it looks like this but gives me the run-time error I mentioned in my previous post:
http://img198.imageshack.us/img198/6429/deviceaddresstovariantr.jpg
This is my function prototype:
http://img825.imageshack.us/img825/6682/createconnectionfunctio.jpg
And this is where I declare the deviceAddress property:
http://img863.imageshack.us/img863/7838/gapdevicediscoverydonee.jpg
I also created a value indicator and a GetType indicator. Neither of them told me anything. Thanks for any help!
04-08-2011 03:59 PM
Hello,
Hmm, It looks like LabVIEW is still typecasting your input to "slave". Are you sure that the array you are building is EXACTLY the same size/dimensions that your object is expecting? I would not expect labview to have to typecast from similarly sized byte arrays. Try right clicking the terminal to slave, and creating a new constant from there to see exactly what is expected.