From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Subscribe to instrument events in CVI using .net assembly

Solved!
Go to solution

Hi All, 

I'm developping CVI instrument wrapper for Tektronix Logic Analyzer, TLA7012.

For now, I was able to implement client connection using the *.dll assembly and *.config files, and now I just can't figure out how to impliment remote system events subscribtion.

As far as I know, I have to create a delegate function that is going to represent my event handler.  After that, using an event handler, I will run the some assembly _add function, in order to "listen"-and-handle specific events.

What functions/methods should I use in order to create my event handler? 

I am using CVI2015 and CPP example attached (contains TlaNeInterfaces.dll)

Thanks in advance for your help.

0 Kudos
Message 1 of 12
(4,347 Views)

Hi ArtB83

 

Have you seen this forum post? This at least talks about how to handle .NET delegates and where to find examples on how to handle .NET objects.

 

If this doesn't help you, what event are you trying to register? Which function are you looking to create a delegate for? And what do you mean when you say


 


 After that, using an event handler, I will run the some assembly _add function, in order to "listen"-and-handle specific events.

 

 

Andy F.
Applications Engineering
National Instruments
0 Kudos
Message 2 of 12
(4,319 Views)

Hi Andy, 

Thanks for your reply.

I am trying to subscribe to hardware events, that signal when the run state of logic analyzer  changes.

Yes, I saw that post, that you've mentioned and I saw the timer example. As I understood the post and the example, the flow is prety simple when using standart .NET library from CVI - the flow is different when I use the assembly file only in order to create objects and manipulate them. Mostly, because of types and different operators/constructors/handlers/overloading that implemented in my assembly. 

I rely on C# example that come with the assembly file, and I am trying to recreate the following 

 

// Subscribe to ITlaRunControl.RunStarted.
m_runStartHandler = EventRemoter.Create(new EventHandler(OnRunStarted));
m_system.RunControl.RunStarted += m_runStartHandler;

/********************************************************************************/

I will put some details of my understanding, that I have right now.

 

From observing the class, m_runStartHandle - is a data member, of type  EventHandler. 

And probably this is some kind of descriptor of previously declared type.

So, I need some way to create that type, initialize that descriptor and to ensure that it has correct functionality. I can't clearly figure out how to do that using my assembly file. My assembly file has class - Event_Remoter - but the class has no way of creating EventHandler. Some other class, has method of creating the Handler, but it has no way(that visible to me) of subsribing. 

 

If we take a look to methods and member functions.

The EventRemoter.Create - probably declares the event handler descriptor.

The (new EventHandler(OnRunStarted)) - is the decriptor init operation, and the delegate itself is OnRunStarted. How do I declare some function as delegate, using my assembly?

 

Now,  m_system.RunControl.RunStarted += m_runStartHandler;

m_system - my MAIN SYSTEM CLIENT object.

RunControl - type of event that m_system "listens" to. 

RunStarted - the EVENT itself (there is also RunComplete).

Operator += performs the subscription using initialized event descriptor.

 

And again, I observe classes in my assembly, and just can't find these methods or appropriate types that required to implement my subscription.

I have a class ITla_Runcontrol - it has a method ITla_Runcontrol_add (probably +=) 

It requires as argument a handle representing a .NET object of type: Tektronix.LogicAnalyzer.TpiNet.ITlaRunControl - that probably represents the descriptor, but I don't have a CREATE method in order to create such handle of ITlaRunControl type. 

 

This is the whole picture in details. May be I use the assembly in some incorrect way, if so please let me know. 

In my 1st post, I have accidentaly uploaded CPP example, here is C#.

Kind Regards

0 Kudos
Message 3 of 12
(4,306 Views)

Hi ArtB83,

 

I noticed that the assembly was written in C# (and C++ above). It seems like it would be easier to use this assembly in a .NET environment. What were your thoughts behind using LabWindows™/CVI™ for this project?

 

I would suggest talking with Tektronix about using their assembly in an ANSI C environment. They may not have designed their assembly to be called in C, and if that is the case, some methods and properties may not translate nicely. They may have included some documentation with their assembly that you can look through, and if nothing else, they would probably be of more help in using their driver in ANSI C.

 

Andy F.
Applications Engineering
National Instruments
0 Kudos
Message 4 of 12
(4,283 Views)
Hi Andy,
That's 100% true, it should be implemented in .net, and not the C. But, the CLIENT wants CVI compatibility for his own purpose. There is a Labview driver for that device, but it implemented in the same way, with the same assembly file. Should it be almost the same for CVI?
The only manual I have got from Tektonics is .net manual, describing classes and methods. I'll ask for additional info regarding ansi C, that you've mentioned. Because it's realy does not translate nicely into C 🙂
Thanks for the support.

Best Regards,
Arthur
0 Kudos
Message 5 of 12
(4,279 Views)

Hi ArtB83,

 

The implementation in LabVIEW is slightly different because LabVIEW uses an object-oriented language (G). Because ANSI C is not object-oriented, using .NET assembly files is a bit trickier. Once you hear back from Tektronix, feel free to post your findings on the forum, and we can work from there!

 

Andy F.
Applications Engineering
National Instruments
0 Kudos
Message 6 of 12
(4,263 Views)

Hello again,

 

I have been waiting for a week to get an answer from Tektronix, but I didn't get anything. Meanwhile, I am trying to solve my problem from enother perspective. 

I tried to investigate the wrapper code in order to extract the root of my problems.

My wrapper function signature is:

int CVIFUNC TLA_TpiNet_ITlaRunControl_add_RunStarted(
TLA_TpiNet_ITlaRunControl __instance,
System_EventHandler value,
CDotNetHandle * __exception);

 

Looks like my major problem is declaring an instance of type/class - System_EventHandler and initialize it with function pointer which makes it a "delegate". 

 

 

How do I make that "delegate"? 

0 Kudos
Message 7 of 12
(4,206 Views)

Hi ArtB83,

 

After doing a little digging, I've found a function called CDotNetCreateDelegate that you should be able to use for your project. I haven't used this function myself, but I have linked the help here. If you have any questions on how to use this function, feel free to reply back on this thread!

 

Andy F.
Applications Engineering
National Instruments
0 Kudos
Message 8 of 12
(4,177 Views)
Solution
Accepted by topic author ArtB83

Hi Andy,

I think I found the solution after digging in Tektronix C++ sample codes. They use the mscorlib library to emplement simple events. I thoght that the System_EventHandler type belongs to their own dll, but it actually comes from the framework itself (or the OS) . 

So I added the mscorlib.fp to my project, and vualla - I have a class and a method - System_EventHandler__Create 🙂 

0 Kudos
Message 9 of 12
(4,162 Views)

Hi ArtB83,

 

That's exciting news! I'm glad you were able to get your Tektronix dll working in LabWindows™/CVI™! If you want to mark your answer as correct, it would boost your stats on the forum and allow others who find this thread to skip to the solution.

 

Thanks for posting your answer on the forum!

 

Andy F.
Applications Engineering
National Instruments
0 Kudos
Message 10 of 12
(4,152 Views)