03-10-2020 06:06 AM
I am currently using a python script within a VI to return a single value. VI has a for loop which then generates a array of values obtained through the python node.
I can see this on NI help page for the python node (http://zone.ni.com/reference/en-XX/help/371361R-01/glang/python_node/)
I was hoping that if I use an array as return type, I would be able to generate an array in my python script and output it from the python node directly instead of having to call it N times in a for loop within labview.
However when I do that I get an error (the script itself works. it outputs the array to console if I try it).
So I was wondering if the python node supports array types as return value.
Anybody tried to use the python node in this manner?
Solved! Go to Solution.
03-10-2020 08:26 AM
When you pass in the array, do you pass in an array initialized to the correct length? I have never used the python nodes but in using the CLF if you want to pass an array, it works if you pre-initialize it to the correct length.
03-10-2020 08:56 AM
As a return value, you can use an array according to the help explanation. What error did you get? One possibility I guess is that the array data from python does not fit the array used in LabVIEW. You can share the minimum code to reproduce the error if possible 🙂
03-10-2020 09:05 AM - edited 03-10-2020 09:21 AM
Are you sure you're returning an array? If you are returning a numpy array or something similar, you need to convert it to a Python list. I don't believe you need to initialize the return array to the correct size the way that you do when calling external code from the CLF node.
What error are you getting?
03-10-2020 11:09 AM
This is the block diagram for the VI I used when trying to return an array from the python node:
this is the Error msg I get:
Python Node in Equation_Interpreter.vi<APPEND>
Python returned the following error: <class 'SystemError'>
..\Objects\listobject.c:189: bad argument to internal function
As I mentioned already if I run 'get_datapoints("str",100)' in the console, it output all the datapoints as what I think is an array. I've attached the python code (this is mininum code version. gives the same outcome).
03-10-2020 12:33 PM
rtnarray = b.tolist()
Add this to your python code, and set the function to return rtnarray. I wasn't clear about this in my prior message, when you define the return type as an array, LabVIEW is expecting the return type to be a Python list.
03-11-2020 02:47 AM
@paul.r wrote:
rtnarray = b.tolist()Add this to your python code, and set the function to return rtnarray. I wasn't clear about this in my prior message, when you define the return type as an array, LabVIEW is expecting the return type to be a Python list.
Thanks, that did the trick! 🙂