12-18-2015 01:45 PM
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
Solved! Go to Solution.
12-18-2015 03:10 PM
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?
12-18-2015 07:43 PM
12-21-2015 01:08 PM
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
12-21-2015 01:12 PM
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
12-21-2015 01:56 PM
12-22-2015 01:37 PM
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
12-22-2015 05:40 PM
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.
12-23-2015 03:39 PM
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.
12-27-2015 10:37 PM - edited 12-27-2015 10:41 PM
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).