Call multiple instances of a LabVIEW executable with command line arguments
It might happen that you find yourself in a situation where you need to call multiple instances of a LabVIEW executable, but you need to pass to it some information that you may later use in the application.
In a normal scenario, you would use a re-entrant VI with all it’s respective design behind, to be able to run multiple clones of that main VI. In that case, if that ship hasn’t sailed for you already, i would recommend to use reentrant VIs, or something like DQMH framework.
However, if you already designed the entire application in a certain way, where re-entrancy is no longer an option, and you want to manage multiple instances of a LabVIEW executable, then this is the right article for you.
The concept
The idea is this: You will call your main application using comand lines and passing arguments to it. These arguments are the information you will use in your instances. For example, and ID for the instance you are calling, or any other information you may need.
Keep in mind that for passing arguments to your application, you will need to edit the source code of it, to add the VIs that will allow it to do something with those argumenst. There’s no point in adding command arguments if you can’t do anything with it inside your VI.
Therefore, we need to add in our main application the settings to be able to read the command line arguments and run multiple instances of it. Then, we will need another VI, application or batch file that will call all these instances.
1. The command line arguments
Let’s say that you need to identify each instance of the application with an ID, with values 1… n. Therefore you have to call your application from the command line and add the ID separated with spaces:
"C:\ProgramFiles\YourProgram.exe" 1
If besides the ID you must add a second argument, for example, a baud rate, then you would have something like this:
"C:\ProgramFiles\YourProgram.exe" 1 9600
As you can see, you call your app, and pass the arguments to it.
You have different options for creating the caller for the multiple instances, but it can be as simple as a batch file (.bat) with the call for all the instances and its arguments:
start "C:\ProgramFiles\YourProgram.exe" 1 9600
start "C:\ProgramFiles\YourProgram.exe" 2 19200
start "C:\ProgramFiles\YourProgram.exe" 3 38400
Or if you want something more sofisticated, you could create another VI, that uses the system exec VI to call your executable. (Please keep in maind that if you need to pass arguments you still will need a batch file).
2. Reading command line arguments in the LabVIEW application
At this point you already know how to call your LabVIEW executable or application passing command line arguments to it. However, we need to be able to read those parameters inside our application. For that, we will use the «Get Command Line Arguments.vi» which is located in the application pallete.
This VI will provide the information comming from the command line input as an array in the arguments. Following the same example of having parameters as ID and baud rate, we could parse those values an use in our application as follows.
Finally, before building the LabVIEW executable, you need to enable the option of passing these command line arguments to your application
Depending on the LabVIEW version, the process above could be slightly different. In that case i would suggest reading the documentation from the NI page.
3. Configure the LabVIEW executable to run multiple instances
Last but not least, you will need to add a key to the application configuration file to enable the multiple instances to be executed.
Every LabVIEW application build genertes three files:
- Application.exe
- Application.ini
- Application.aliases
We will need to modify the Application.ini file and add the key:
AllowMultipleInstances=True
That will make the .ini file to look like this:
useLocaleDecimalPt=False
server.app.propertiesEnabled=True
server.tcp.paranoid=True
server.tcp.serviceName="My Computer/VI Server"
server.vi.callsEnabled=True
server.vi.propertiesEnabled=True
WebServer.TcpAccess="c+*"
WebServer.ViAccess="+*"
DebugServerEnabled=False
DebugServerWaitOnLaunch=False
AllowMultipleInstances=True
With that configuration you should be able to run multiple instances of your application.
If you don’t want to add that line to the .ini file everytime you build your application, you can create a custom .ini file, already with that line, and use it before building your application.
For more information about allowing multiple instances, check this page from NI.
Now we are done. After all the settings above, you should be able to build your application, and call the multiple instances from a batch file.
Good Luck!