Developer Center Blog

Community Browser
cancel
Showing results for 
Search instead for 
Did you mean: 

Efficient Run-Time Licensing Using Functional Global Variables

David_L
Active Participant

In many LabVIEW APIs (toolkits, drivers, etc), it can be important to have run-time licensing checks built in such that the VIs can only be run when they have been purchased and activated.  The add-on licensing tool of the Third Party Licensing & Activation Toolkit (TPLAT) is very useful for protecting code in the LabVIEW development environment, but this does not protect activated code from running after it has been built into an executable.  To protect code at Run-time, you can instead use the TPLAT API to build licensing checks into the code itself.

One drawback to building in run-time licensing checks is that there is an overhead cost to check the license each time any of the API VIs run.  Fortunately, most APIs already need to be initialized before the rest of the code works to open resources, allocate memory, etc.  Run-time licensing checks can easily be added to this initialize function so it only needs to be called once. 

However there are many situations in which an API doesn't have an open or initialize function (such as analysis functions or a collection of reuse code) and therefore the license checks need to be in each VI in order to ensure total protection.  To overcome this final hurdle and make the license check faster and more efficient, we can turn to the functional global variable.  With this architecture we can have the API do the license check on the first call only and then store the state (expired, activated, evaluation, etc) in the functional global variable.

Check License (Core)

The core functionality of this architecture is the Check License VI.  As mentioned it is a functional global that checks the license status on first call and then stores the status for subsequent calls.  Because of this, there is some overhead on the first call of this function (however long it takes for the licensing check to take place) but there is very little overhead on later calls.  You can also force a license check by using the appropriate control.  In the attached example, the license check is a simple dialog box, but this should be replaced by your appropriate license checking code.

Check License Status.png

API VIs

Now that you have your core functional global variable created, all you need to do is add this to your API VIs and surround the rest of the code with a case structure.  Then your code will run differently depending on the license status.  The most common situation would be to run normally if the license is in Evaluation or Activated state, and to throw an error if in Expired or Invalid state, but this can be changed based on your licensing scheme.

API 1.png

API 2.png

Initialize VI

Now that you have a licensing solution, you can create a new Initialize VI that will does nothing but check the license status.  This allows a developer to do the licensing check as required, but to ensure no delays in their critical code.

Init.png

Summary

The attached example shows how to add run-time licensing checks to an API such that you can avoid the overhead of checking licensing in every VI.  It does this by using a functional Global Variable and the "First Call?" function to check licensing on the first call and then storing the status for subsequent calls.  Have you used a similar strategy?  What other methods do you use for efficient run-time licensing?