07-25-2022 02:27 PM - edited 07-25-2022 02:29 PM
I am able to implement the following python successfully. It works fine.
Python code:
My LabView code:
Front panel:
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:
My LabView Code:
P.S.: I am new to python. I'm learning it.
07-25-2022 03:30 PM
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...
07-25-2022 03:57 PM - edited 07-25-2022 04:11 PM
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)
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