LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to show the event data, which sent by C# DLL

Solved!
Go to solution

when labview got event from a C# DLL, how can i check the event data?  I try the official example, the panel operated well, but the event data keep zero value.

0 Kudos
Message 1 of 6
(2,707 Views)

Open the Callback subVI.  The data is inside it when it's called.

 

 

George Zou
0 Kudos
Message 2 of 6
(2,672 Views)

I am a new learner of labview,  The official site example I used determined that the event data could not be displayed。 Today, I try use another method to study the issue, And got the same result, i feel  A little helpless.

I guess the official example may not use any C# Dll  "event data" , It just responce the fitted "event action" only, So i make another C# DLL which has eventArgs  which defined by myself 。 

 

the  step is: 

 1. I write a samp C# dll, which input a int32 number, example as 100, if method called, it will fire a event  with eventArgs data as number 105 (just simply added by 5).that is all. I test it in c# work correctly. 

2. then i write a labview vi to use the C# dll, and try my best to catch the event  data(expected 105, if i input 100 before call DLL),  But the callback event vi seems  not been  callbacked, 

3. labview 2020 study version is just 32bit(the official web suggest me try use 32bit), use NET4.0 CLR, and visual studio 2019 also use Net4.0, but 64bit 

4. I attatched all  the document below, anybody can give me some suggestion?  guohuimao@163.com  thanks a lot.

 

Download All
0 Kudos
Message 3 of 6
(2,631 Views)
Solution
Accepted by guohuimao

You have two problems, based on a mis-understanding of how LabVIEW executes code:

 

  1. In order to pass data back from your Callback to your main "labVIEW_Call_DLL.vi", you need to provide a path to transfer that data. Your callback is being executed by a CLR thread. The example in the Example Finder uses control references as a way of providing this mechanism. Your example does not have any mechanism at all.
  2. You are unpinning the object reference, and ending the VI hierarchy, non-deterministically. This is due to LabVIEW's inherent multi-threaded nature. So your VI is more often than not ending, and un-pinning all .NET objects, before the event firing actually occurs (race condition). Events are designed to be asnychronous in nature.

Attached is a modified example that adds a control reference to the user parameter when the callback is registered. The callback can access this reference in order to write data to it. Your main VI execution settings have also been changed to run in the single user interface thread so that no multi-threading occurs. 

 

When I run this example, the control value "before call DLL" matches the control that whose reference was passed to the callback "From event". I see from your C# code that you aren't doing any "+5" addition to the number provided to the args class so we should expect these two controls to be the same value.

Message 4 of 6
(2,621 Views)

Dear expert:

   Thanks a lot, I now understand some of what you said. But i down and try run the new project which corrected by you, It seems can not load my C# dll now.

  I recompiled the C# project , and replace into the labview diagram again, still can not load it...

  Maybe It caused by the diffrence of our visual studio ?

 Yours  

0 Kudos
Message 5 of 6
(2,608 Views)
Solution
Accepted by guohuimao

I didn't modify your assembly or C# source code files / solution. I did update your main VI and add a replacement callback.

 

Try editing the .NET node in your block diagram and re-selecting class and member.

0 Kudos
Message 6 of 6
(2,598 Views)