LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Has anyone here ever tried to integrate python code to labview? I need help.

I am able to implement the following python successfully. It works fine. 

 

Python code:

GRCK5000_0-1658776386439.png

My LabView code:

GRCK5000_2-1658776516318.png

Front panel:

GRCK5000_1-1658776483866.png

 

The only problem I have is my python code with the if statement below. It does not work at all. I have attached it as well as the labview code. Can someone tell me what I am doing wrong.

 

My if statement python code:

GRCK5000_3-1658776831501.png

My LabView Code:

GRCK5000_4-1658777093798.png

 

 

P.S.: I am new to python. I'm learning it.

 

Download All
0 Kudos
Message 1 of 3
(1,120 Views)

I don't know what error you got but it might just be that python is case sensitive and MyColor != myColor.  Try fixing that and see if it runs...

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
0 Kudos
Message 2 of 3
(1,096 Views)

Labview:

you need to define a "user-defined function" color, it's variables (input), and the variable's data type (string).

you get only one return variable and you need to define it's data type (I32)

Spoiler
string-to-text.png

note: variables can be scalar (as in this example)  or arrays

 

Python: 

 

 

 

def color(input):
  
    D1 = input

    if (D1 == 'Red'):
        D1 = int(1)
    else:
        D1 = int(-1)

    output = D1

    return (output)

 

 

 

 

note:

- when you code a one-digit number in python, it is assumed to be i32.  the int() typcast is here only to make it more obvious.

- a variable can be defined with another variable (D1 = input .... output = D1).

- the python script is executed from top to bottom within the user-defined function

- therefore D1 and output could be completly replaced by input in the above python script:

 

 

 

 

note: the indentation is very important in python, so don't start programming in windows text editor, but in a editor with proper syntax hi-lighting e.g. MS Visual Studio Code

note: sometimes, the ( ) brackets are essential, sometimes, they arent

 

alexderjuengere_0-1658783453740.png

 

 

0 Kudos
Message 3 of 3
(1,085 Views)