Jump to content
EricLarsen

Creating .NET ICollection

Recommended Posts

After a 20 year hiatus, I'm back to writing text code again. Not just any text code, but C# .NET assemblies. After about a day and a half of googling and self teaching, I've hit the wall.

 

I've got a .NET assembly that was provided by a manufacturer that controls some hardware. We are calling the higher level .NET functions from Labview and they work. But we aren't getting acceptable performance for the high level calls, so we are trying to drill down into the lower level calls.

 

One of the .NET methods requires an ICollection<T> input, there in this case T is a channel object that is created elsewhere. The ICollection function is described the in the MSDN article: http://msdn.microsoft.com/en-us/library/92t2ye13

 

For reasons I don't really understand, Labview doesn't apparently support a constructor to ICollection. Something about Labivew not supporting calls to .NET generics, but I'd be lying if I said I understood that. But it seems like it should be possible to create a .NET assembly that creates a reference to an ICollection .NET object that can be passed to Labview. But I can't get it to work.

 

I've written a simple program that contains two methods. The first method GetUInt32 simply returns an input integer and was written as a test to see if I could write and assembly and call it from Labview. It works great.

 

The second method, GetICollection, is a test case to create a collection of UInt32 integers. Should be really simple, but it generates a compiler error. I suspect I'm doing something really basic incorrectly, but I'm at a loss to understand what. Can someone point me in the correct direction?

 

 

 

 

post-7727-0-66918400-1367508522_thumb.pn

Share this post


Link to post
Share on other sites

The problem is that you can't instantiate an abstract or interface class. The ICollection interface requires you to create a class that implements the ICollection interface. See

 

http://msdn.microsoft.com/en-us/library/ms173156(v=vs.90).aspx

 

For more explanation.

 

I don't have Visual Studio handy or I'd write a brief example. Let me know if you need the example and I'll get to it.

 

Mark

 

 

Share this post


Link to post
Share on other sites

LabVIEW simply does not support working with any generic data type. See "Which .NET Features Are Not Supported In LabVIEW?" here:

http://digital.ni.com/public.nsf/allkb/DC41DCDA972642CF8625787E00732DDD

 

You will need to create a wrapper (in C# code) around some ICollection class of a concrete instantiation, compile that as an assembly, and then instantiate that in LabVIEW.

Share this post


Link to post
Share on other sites

Ah, I get it now.  Yep, creating an instance of a concrete class did it.  My wrapper code appears to be working.  Thanks!

 

I'm up to 2 whole days of programming .NET.  Time to add .NET programmer to my resume.

Share this post


Link to post
Share on other sites
I'm up to 2 whole days of programming .NET.  Time to add .NET programmer to my resume.

I've seen people add LabVIEW to their resume with less experience then that.

  • Like 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.