LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

callback function take user params from object sender

Solved!
Go to solution

1. This example is special in C# DLL
normally, we use system predefined delegate "Eventhandler" to define a event with no user params, So, we just use all the base class to define callback method
(object sender, EventArgs e) as input params. And Sender meas some UI control trigged action, Such as key/mouse interface etc.,, e is system defined params, such as click, down etc.,
Here, We just raise the event by our application , Not the windows OS hardware actions. And we tied some param within 'Sender' for callback functions....one is percent(int32, 0~100),another is result(bool,true/false) which means the state of dll during receive a file 

2.In labview, how callback function get user information which tied within C# DLL's "sender"?

 

3.labview2020(32bit),visual studio2019 used(64bit).

0 Kudos
Message 1 of 16
(1,548 Views)
Distinguished Expert: I am a new learner of labview. I can't understand the example you provided. Could you please give me some direct answers to my questions or help me correct the project I submitted. That might be easier for me to understand. Since I am just learning to write a program, you might be able to correct a few code errors (I'm sure there are) while you're working on the problem. Thank you very much. Yours
0 Kudos
Message 3 of 16
(1,482 Views)

OK, sorry about the noise. It was only slightly related...

 

There seems to be nothing wrong with the LabVIEW code. Not sure about the C# code.

 

Can't run your code, as I don't have a local webserver... Never mind. The C# code is just a stub...

 

Are the callbacks triggered (put a message box in them, or make them not reentrant and use a probe)? Can you put error handler dialogs in there? Perhaps the Variant To Data fails...

 

Are you sure the assembly is generating events?

0 Kudos
Message 4 of 16
(1,481 Views)

Where did you get the C# code from? Is it based on an example?

 

I'm no C# expert, and I suspect no events are generated at all Intuitively, it seems to me the EventHandlers need to be created (not just defined) and somewhere an AddEventHandler should be used. But this might be completelly wrong.

 

I'd try to make a C# exe that calls the assembly, to and get that working first. Until it works in C#, LabVIEW has no change...

0 Kudos
Message 5 of 16
(1,476 Views)
C# sample wrote by me, It is no problem and work well. It is A little bit special is the parameter mechanism when the event is triggered, as mentioned during the mention. It just use 'Sender' replace 'eventArg' to carry Args! If you check the DLL with C# application ,you will see the progress and the result UI control action corrcetly. I think, The hard part is how we can convert the 'sender' form C# object to labview var, the to int or bool in labview.
0 Kudos
Message 6 of 16
(1,453 Views)

@guohuimao wrote:
The hard part is how we can convert the 'sender' form C# object to labview var, the to int or bool in labview.

The callbacks are not called at all.

 

The conversion happens in the callback. But if they are not called, I think that is the first thing to solve?

0 Kudos
Message 7 of 16
(1,451 Views)
I did not know how to debug the event in labview, I think callback is called by CLR, maybe difficult to catch it to see some action. As i study early about callback in labview, I know callback function has some error sure. So we try to pick out where is the problem ..
0 Kudos
Message 8 of 16
(1,448 Views)
This is the problem that i want to know , thanks. It work in c# correctly, why can not work in labview.
0 Kudos
Message 9 of 16
(1,446 Views)

@guohuimao wrote:
I did not know how to debug the event in labview, I think callback is called by CLR, maybe difficult to catch it to see some action. As i study early about callback in labview, I know callback function has some error sure.

If you make the callbacks non-reentrant, they work like normal VIs. You can put probes in it. But they won't get values, as the callback isn't triggered.

 

You can practice with callback VIs. Simply wire a LabVIEW control reference in stead of the .NET reference. You'll get the usual LV events you normally get in an event structure.

 

You can also put a popup (One Button Dialog) in the callback. If it doesn't show, the callback isn't called.

 

If you have working C# code to test the event, can you post it?

 


@guohuimao wrote:
 So we try to pick out where is the problem ..

I'd be interested in this as well. I've used .NET events before, but never had to create the .NET code.

 

The link I posted in the first reply is an example of an event. It should be that simple, from the LabVIEW side. But I have no idea how to make in in C# and I haven't found any examples either.

0 Kudos
Message 10 of 16
(1,445 Views)