LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing Command Line/PowerShell Arguments to LabVIEW VI Controls

Hello, 

 

I'm facing a bit of a challenge here. My task is to be able to pass arguments to a LabVIEW executable and have it be recognized in the appropriate format. Using the latest version of Windows and LabVIEW. 

 

I've tried following the guide on the NI website on how to do this. However, there is a problem with this - the arguments always get interpreted as a string array. If, say, I wanted to pass arguments '2' and '2' in order for the .exe to add them and result in '4', I would have to parse the string and convert from a string to an int within the LabVIEW program. This isn't scalable - if I have 50 executables, I'd have to make a subVI to accommodate for each one, as they take in different data types and different numbers of arguments.

 

Because of this, I've tried a different approach. I wrote a PowerShell script that intakes parameters, converts them from a string to an integer, and launches a LabVIEW executable. The challenge I've hit is being able to take there converted arguments and passing them to the LabVIEW .exe. For example, I want to pass '2' to Control X and '2' to Control Y in order for the indicator to result in '4'. So far, I haven't been able to find any way to do this. I would greatly appreciate the help.

 

PowerShell script code below:

#Intaking Arguments
"`n Arguments Entered: `n"

for([int]$i = 0; $i -lt $args.Count; $i++){
    try{
        [int]$parameterAsDecimal = [convert]::ToInt32($args[$i], 10)
        "   $i - $parameterAsDecimal"
    }catch{
        [string]$parameterAsString = $args[$i]
        "   $i - $parameterAsString"
    }
}

"`n Number of arguments passed: $($args.Count)"

#Starting LabVIEW executable
Set-Location C:\Users\[user]\Desktop\LabVIEWProjects\builds\passing_parameters_proj\IntAddition
Start-Process IntAddition.exe

"-------------------------------------------------------------------------------------------------------"
#In Command Prompt, initially, 'cd Desktop\PowerShell_scripts' #Call with 'powershell.exe -file passing_arguments.ps1 [input parameters here]'

Thank you,

 

Sav

0 Kudos
Message 1 of 2
(2,275 Views)

Hi Sav,

 

This isn't scalable - if I have 50 executables, I'd have to make a subVI to accommodate for each one, as they take in different data types and different numbers of arguments.

Well, the usual way is to use strings as inputs to a command line tool…

It becomes scalable as soon as you program a library of VIs doing the parsing for you. Then you could use that library for each of your 50 executables!

 

 

Spoiler

25 years ago I was programming in Assembler on a home computer. It had a library (let's call it DLL for easy understanding) which implemented command line arguments for own tools. All I had to provide was a list of argument name, desired datatype and default value. This way you could easily create tools with lots of arguments! You may recreate such a library too. I guess people will be happy to see/review your upload in the LabVIEW documents board or in the LabVIEW tools network!

Hint: use a common char to separate arguments like "-" (on Unix like machines) or "/" on Windows. It greatly simplifies parsing the arguments…

 Edit: In VIPM you may search for "cli" to find a toolkit by Wiresmith supporting command line interfaces (from a quick glance at its description)…

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
0 Kudos
Message 2 of 2
(2,268 Views)