Once you have defined the event you're registering, follow the below steps to create your Event Callback VI and pass data from it to your main VI:
- Create a reference to a data structure, such as a queue, notifier, or user event, for the data you need to obtain from your callback VI, and pass this data structure reference to the User Parameter input of the Register Event Callback function you have defined for the event you're monitoring. In the example explained in this document, we will pass the Register Event Callback function a queue of string data.
- Right-click the VI Ref input on the Register Event Callback function, and select Create Callback VI. LabVIEW will automatically create a callback VI based on the event you selected and data wired to the user parameter input, which in this case is the queue we will use to pass data back to the calling VI.
- Open your created callback VI, and add code to enqueue the value you want to pass to the calling VI in your data structure. In this example, we're taking the full path to a created file's location and adding it to the queue.
- Now that this value is contained in a queue, we can dequeue it in our main VI and use it in other parts of the code/display it to the user. If you'd like to ensure that you have an element in the queue before attempting to dequeue, use the Get Queue Status function to get the number of elements in the queue, and only dequeue an element if one is present.
- After your code finishes executing, be sure to close the reference to your data structure when cleaning up the rest of your references.