LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Logging example using custom events

Solved!
Go to solution

This is my first real attempt at creating an example VI that's actually useful.  🙂  The idea was to create a logging function which can run separate from the user control loop and can be called from anywhere when needed.  In our ultimate application the logger will store logs from everywhere and then dump everything to a file after all testing is complete.  Some links to info I used in creating this VI:

 

https://www.ni.com/docs/en-US/bundle/labview/page/lvhowto/creating_user_events.html

 

https://flylib.com/books/en/3.352.1.101/1/

 

https://forums.ni.com/t5/LabVIEW/Event-Structure-prevents-button-from-working/m-p/4250587#M1236699

 

It seems to work fairly well.  Although I'm not completely happy with the way the error clusters run.  Any ideas on how I could synchronize the termination of the two while loops?

 

What do you think of this solution?

 

logger_v1.png

 

 

0 Kudos
Message 1 of 6
(1,943 Views)

Add another user even with just a boolean to send the terminate event to all loops.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 2 of 6
(1,901 Views)
Solution
Accepted by arcadebench

I think you did a very good job for your first "real" vi! 

 

A modified version of your code is attached to give some ideas on how to clean things up a bit.

 

For your question about error handling:

Functions like Create User Event or Register For Events don't fail at runtime so I don't handle them.

File access and Hardware errors do need to be handled well and should not shut down the vi.

At a minimum a Simple Error Handler should be used so the error is displayed before the program closes.

Test Logger Modsm.png

 

----------------------------------------------------------------------------------------------------------------
Founding (and only) member of AUITA - the Anti UI Thread Association.
----------------------------------------------------------------------------------------------------------------
Message 3 of 6
(1,867 Views)

Some outstanding changes!  Thanks for taking the time to review this.  I really like how the clusters are used to clean things up.  Adding the Init and Quit/(Exit) events seems like it would be ubiquitous and useful enough that they would be built into LV.

 

A few questions if I may:

 

*  For the lower loop I noticed that you didn't include "Destroy User Event" for the Init nor Quit events.  Is this optional?  Would they be necessary if for instance the VI was a pop-up window where the application wasn't exiting upon Quit?

 

*  Is the Coerce To Type needed for the array initialization?  Wouldn't the Initialize Array already output a 1D array?  Just trying to understand the nuance there.

q2.png

 

*  For the Quit Event you mentioned that you normally pass a variant with Address, Command, and Data.  Can you give a use case where that would be useful?

 

 

 

0 Kudos
Message 4 of 6
(1,839 Views)

@arcadebench wrote:

Some outstanding changes!  Thanks for taking the time to review this.  I really like how the clusters are used to clean things up.  Adding the Init and Quit/(Exit) events seems like it would be ubiquitous and useful enough that they would be built into LV.

 

A few questions if I may:

 

*  For the lower loop I noticed that you didn't include "Destroy User Event" for the Init nor Quit events.  Is this optional?  Would they be necessary if for instance the VI was a pop-up window where the application wasn't exiting upon Quit?

 

*  Is the Coerce To Type needed for the array initialization?  Wouldn't the Initialize Array already output a 1D array?  Just trying to understand the nuance there.

q2.png

 

*  For the Quit Event you mentioned that you normally pass a variant with Address, Command, and Data.  Can you give a use case where that would be useful?

 

 

 


Would they be necessary if for instance the VI was a pop-up window where the application wasn't exiting upon Quit?

I would still put it outside the loop to destroy the event

 

Is the Coerce To Type needed for the array initialization?  Wouldn't the Initialize Array already output a 1D array?

Since he is using bundle operation (not bundle by name which requires a cluster definition), the cluster data type uses the default name for the 1D string array, instead to give a custom name, he is type casting it, now during bundle operation it will take the "Log Array" as the element name.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 5 of 6
(1,827 Views)

> For the lower loop I noticed that you didn't include "Destroy User Event" for the Init nor Quit events.

 

To be honest, I never use the Destroy User Event function. After dozens of systems (some that run for 1100+ hours

continuously) this hasn't caused any issues.

 

> Is the Coerce To Type needed for the array initialization?

 

Santhosh is correct. This is a way to give a name to a wire. And as he mentioned, there are other ways to handle this.

It's good to be aware of different ways to do things.

 

> For the Quit Event you mentioned that you normally pass a variant with Address, Command, and Data
> Can you give a use case where that would be useful?

 

This is intended to be a low speed messaging system (all vis get the messages - but only respond to their name and the

special "All" address). I call it the "GP Event" (General Purpose).

 

The ability to Open, Close (front panel), and Quit (end) a subvi is the most fundamental use. If the Event Loop controls a state

machine (daqmx, serial, camera) then it is responsible for stopping that state machine.

If a vi adheres to this made up standard, I can drop it on the block diagram and know it will play well with the rest of the code.

 

But this is just the beginning of the possibilities. You can control program operation, send info, and send/receive data just to

name a few options.

 

A simple example is attached (back saved from LV 18 to LV17).

----------------------------------------------------------------------------------------------------------------
Founding (and only) member of AUITA - the Anti UI Thread Association.
----------------------------------------------------------------------------------------------------------------
Message 6 of 6
(1,786 Views)