03-01-2023 08:10 PM
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.
Image 1 - LabVIEW Code
07-31-2023 05:14 AM
Running just a basic enum test, python seems happy as treating it like an integer.
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
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)
good luck.