LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

C# activeX

Solved!
Go to solution

I have a project that need translate the attached C# code into LabVIEW GUI (CSharp_EventLog.pdf), trying to do some basic code shown as EventLog.PNG, but seems not working. I do send event from server side, but this piece of code does not get any response. I am not familiar with ActiveX and C#, need some suggestions on:

 

1. Is there any wrong with my LabVIEW code, why there is no event response? Read C# code, there seems Class cast and/or Automation refnum cast? not sure how to code it in LabVIEW.

2. In the Call back vi, event data is variant, I expected to be string. 

 

Thanks in advance.

 

Jason

Download All
0 Kudos
Message 1 of 11
(4,764 Views)

When you register and create a callback VI like that, you need to remember that it's called outside the normal dataflow process.  So your callback VI might be running and you just can't tell.  Since it's re-entrant, even if you have the VI windows open you won't notice it doing anything.  Instead, you need to have the callback do something that sends a message to the rest of your program (add a message to a queue, fire a user event, set a global variable of some kind, open a dialog box, etc.).

 

Also, if the event data should be a string but it's a variant, what happens when you use the "Variant to data" function to try to make it into a string?

0 Kudos
Message 2 of 11
(4,736 Views)
What is inside your callback VI? Why do you think it's not running?

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 3 of 11
(4,708 Views)

Hi Kyle97330,

 

You are right, I tried to put a dialog box as shown in the in the attached file (CallBackVI.PGN), dialog does show up whenever there is an event. and I also use "Variant to data" function to try to make it a string, unfortunately the string is empty, that is not what I expected. Actually I expect the event data like in the attached file EventLogger.PNG. It should include Class,Source,Timestamp and Message etc. My main problem is how I could get these information by LabVIEW call back VI?

 

Jason

Download All
0 Kudos
Message 4 of 11
(4,652 Views)

Hello Mike,

 

My mistake, actually the callback vi is running, the problem now is I am not sure how to get the correct message from callback VI.  I tried to put a dialog box as shown in the in the attached file (CallBackVI.PGN), dialog does show up whenever there is an event. and I also use "Variant to data" function to try to make it a string, unfortunately the string is empty, that is not what I expected. I expect the event data like in the attached file EventLogger.PNG. It should include Class,Source,Timestamp and Message etc. My main problem is how I could get these information by LabVIEW callback VI or why I cannot get them?

 

Jason

Download All
0 Kudos
Message 5 of 11
(4,647 Views)

I think you need to connect a reference to the GUI control you want updated to the User Parameter input of the Register Event Callback node. I'm also not sure about the carriage return you're adding at the end of the obtained string.

 

Ben64

0 Kudos
Message 6 of 11
(4,619 Views)

Hi Ben64

 

I do connect a reference to a GUI control to the User Parameter Input of the Register Event Callback node as shown in the attachment. GUI reference is a String control with multiple lines.  I expected event message from callback vi.

 

Jason

0 Kudos
Message 7 of 11
(4,580 Views)

Try to show message you receive in event dialog in callback vi, maybe conversion fails. You can also show variant to data error (with Simple erorr handler) for debug.

You understand, that it will not extend previous messages with a new one on next line when you receive message - it will replace old string value. If message is empty, you will not see it. 

0 Kudos
Message 8 of 11
(4,560 Views)

Change callback vi as in the attachment NewCallbackVI.PNG and EventLogCallbackVI.PNG to show message in event dialog, add a variant control to check the actual variant value from callback vi.

Do get error when event happens as shown in VariantConvertError.PNG, Variant value in the main VI is something like "Value -> 20024F94", for different event, the value will be change but seems always 8 digit Hex. The expected message is not here.

0 Kudos
Message 9 of 11
(4,528 Views)
Solution
Accepted by topic author Jason2010

It looks like you are receiving not event data, but reference to event object. You need to convert it to ActiveX object, not to string. Then you can work with activex object: get properties (Property node should show field Date C# analog is evt.Date) and call methods (GetEventKey(evt)).

You can not write in C# something like ToString(evt). May be you can, but you will get the same 64 bit hex number, not event data. You write ToString(evt.Date) - first get evt field Date, then show it as string.

To convert, you need class specifier constant. Copy TCEVENTLogger... control to callback vi, convert it to constant and select correct ActiveX class (something like Event from TCEVENTLOGGERLib).

0 Kudos
Message 10 of 11
(4,456 Views)