LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using Enums with Python and Labview / Python Integration

I have the Labview to Python code as shown below in Image 1. The first Two inputs are arrays. The Python code does some math based on those arrays.

 

The third / Bottom-most input is an enum. For my production we have several different types of components, let's just say 2 types for simplicity. The two are slightly different by a constant amount. The enum, titled "TypeOfModule" is selected at the beginning of the production run. I want to feed that enum into Python and then assign that enum a constant. So you would select the type before production run and then Python would go okay - "If type one = shift x by 10" or "if type two = shift in x by 20" or so on.

 

The problem is that I'm not sure how Labview is feeding the data type to Python. When I just do a simple

 

if TypeOfModule == 0:

    Shift = 10

 

Then later add that Shift to the x axis - it sends back - "Python returned the following error: <class 'NameError'>
name 'TypeofHexaboard' is not defined" 

 

Does anyone have any idea how to do this? I'm kinda stuck and have spent a long time working on this but I'm not sure what else to do - I've tried most fixes. My Python Code is attached to the bottom. Thank you for your time.

 

 

Labview Forums Question Image 1.PNG

Image 1 - LabVIEW Code

 

Download All
0 Kudos
Message 1 of 2
(926 Views)

Running just a basic enum test, python seems happy as treating it like an integer. 


rdance_0-1690797308355.png

rdance_1-1690797926635.png

 

 

At the top of your python code you do have just some straight code that's not in a function. I'm pretty sure labview would just run that piece of code - because it needs to load the imports and library sets etc. So that's probably the error you're seeing

rdance_3-1690798104552.png

 

For labview - python integration, I'd recommend testing the python code on it's own before to try and help capture just errors like that.

You can always wrap your test calls in "if __name__ == "__main__": 

Which means that python code will run if you run the python file natively (and not from another python file/labview)

rdance_4-1690798340225.png

 

good luck. 

0 Kudos
Message 2 of 2
(719 Views)