LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

using python Node in Labview

Solved!
Go to solution

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/)

 

Untitled.png

 

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?

0 Kudos
Message 1 of 7
(8,058 Views)

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.

0 Kudos
Message 2 of 7
(8,023 Views)

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 🙂

0 Kudos
Message 3 of 7
(8,016 Views)

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?

0 Kudos
Message 4 of 7
(8,013 Views)

This is the block diagram for the VI I used when trying to return an array from the python node:

Capture (3).PNG

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).

 

0 Kudos
Message 5 of 7
(7,989 Views)
Solution
Accepted by sherzaad
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. 

Message 6 of 7
(7,979 Views)

@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! 🙂

0 Kudos
Message 7 of 7
(7,948 Views)