Skip to main content

Variable Transfer

adminLess than 1 minute

Tips

source code in this tutorial

variable_transfer_example.zip

Introduction

1. Send and Receive Variables from labVIEW to Python

To send variables, use Add Argument.vi and wire the variable to "Argument" terminal. Then pass the "Argument Object Variant Out" to Call Py Method.vi.

To Receive variables, use Pop Return Object.vim. Notice that LabVIEW should define a type when use a variable, so when receive a variable to an indicator, you should wire "Data Type (default value)" too.

2. Supported Variable Type

Type in LabVIEWType in Python
unsigned/signed Byte, Word, Long, Quadint
Single, Doublefloat
Boolbool
Stringstring
Numeric Arrayndarray
Other Arraylist
Clusterdictionary
  • int in python 3 has no limitless, and float is same as double so data transfer has no precision loss.
  • on LabVIEW, Cluster Array is not supported.

3. Sample Scripts

This tutorial shows that how to transfer argument and receive the return value to LabVIEW. The return values are None Type, Bool, Int, String, Numeric Array, String Array and Double.

/script_folder/function.py

import numpy as np

def variable_transfer(b, d, str, array, d2=1919, d3=810):
    if str == "":
        str = "pykit-for-labview"
    else:
        str += "!"
    return None, not b, d + 1, str, array + 1, np.random.random((3, 3)), ["abc", "def", ""], d2+d3*10

There are two sample VIs included in the source code file. Both them works the same.

variable_transfer_example.vi
variable_transfer_example.vi

The advance example shows that, if there are so many types to stack, you can simplify by using "Add Arguments Ex" express vi and pop 4 variables all at once.

variable_transfer_example(Advance).vi
variable_transfer_example(Advance).vi

Press Run Button several time to see the variable change on Indicator.

Last update:
Contributors: ZHUO DIAO