Example Code

Producer-Consumer (Events) with Error Handling

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview
This example helps address the problem that was fixed by the Truncate Long Paths LabVIEW Idea Exchange for versions before LabVIEW 2012.


Description
This example helps address the problem that was fixed by the Truncate Long Paths LabVIEW Idea Exchange for versions before LabVIEW 2012.Note the three states:

Store Files Paths,Output Stripped Paths and Output Full Paths

 

Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

 

  1. Run the VI.
  2. Select Store Files Paths to save an array of paths in this FGV.
  3. Select Output Stripped Paths to remove the excess directories (user specified, defaults to the file + 1 directory) which may not permit the file in question to be displayed, and output the result.
  4. Select Output Full Paths to output the original full file paths.

 

 

Additional Information or References
VI Block Diagram

 1.png

 

 **This document has been updated to meet the current required format for the NI Code Exchange.**

 

 

Robert Ward
Applications Engineer, NI

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
mtedaldi
Member
Member
on

That's a really great way to handle errors. I can tell so from my own experience.

Especially if you have more than one comsumer/slave this becomes more important.

If I had seen your post earlier, I could have saved quite some time developing my own solution https://decibel.ni.com/content/docs/DOC-29608

--
Marco Tedaldi, University of Zurich, CLAD
GTT_RonA
Member
Member
on

Thanks a lot for this article. I was going around in circles trying to figure out a simple way to pass an error from the consumer back to the producer. This was a huge help!

aejulian
Member
Member
on

Thanks for the example, Rob, it made the process make much more sense. I noticed when I ran the VI in LV2016 that the consumer loop wouldn't actually trigger an event when it saw an error. I think this happens because the Generate User Event VI has the error data going to the error in terminal and thus the VI just passes the error through without generating an event. I found that the solution below achieves the proper response in the case of triggering an error event from the consumer loop:

 

image.png

I think your solution will still work fine if you want to trigger from a consumer loop event with a non-error data type. Perhaps there was a change to the Gen Event VI between LV2012 and now that caused the issue.

 

edit: the same issue also applies to when the producer loop throws an error

 

-Alex