LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview + Python

How can I configure the return value of a Python Node in LabVIEW to output two values?

My python code is very simple

def calculate_sum_difference(num1, num2😞
    sum_result = num1 + num2
    difference = num1 - num2
    return sum_result, difference

Sly_Nguyen_0-1750314863887.png

 

0 Kudos
Message 1 of 11
(611 Views)

Your python script returns a tuple: 

return sum_result, difference

The LabVIEW code should reflect this by wiring a cluster to represent the python tuple type:

Basjong53_2-1750317967419.png

 

Message 2 of 11
(592 Views)

Could you please show me where to find these two blocks?Sly_Nguyen_0-1750318605184.png

 

0 Kudos
Message 3 of 11
(580 Views)

It is a cluster of 2 numeric constants

Please read this carefully before proceeding: 

https://www.ni.com/en/support/documentation/supplemental/08/labview-arrays-and-clusters-explained.ht...

0 Kudos
Message 4 of 11
(575 Views)

Thank you for your help, I have completed it

Sly_Nguyen_0-1750320745252.png

Sly_Nguyen_1-1750320763738.png

 

 

0 Kudos
Message 5 of 11
(553 Views)

I added code to be able to log every time it runs. When using LabVIEW, an error occurs; can you please take a look to help me?

Sly_Nguyen_0-1757491181605.pngSly_Nguyen_1-1757491202842.png

 

0 Kudos
Message 6 of 11
(310 Views)

Well, your python function returns a list... Which I don't think you want, since error_code is a number and result a string (shouldn't this be a boolean?)

Remove the [ ] from the return line. Then make sure that the order of you LabVIEW cluster is the same as your python tuple.

Message 7 of 11
(303 Views)

Looks like your python code returns number, string and the LabVIEW code expects string, number. Order needs to match.

Message 8 of 11
(299 Views)

Thanks for the help, I got it running. But only when running python log appears. What do I need to install for labview to be able to have log when changing reference values

0 Kudos
Message 9 of 11
(285 Views)

The file is probably being created just not where you expect. Because you didn't specify a full path python is treating "log.txt" as a path relative to the working directory. Try an absolute path like "c:/log.txt" assuming Windows. Don't forget to escape the /, put "c://log.txt"

 

No idea where the working directory is in a python node...

0 Kudos
Message 10 of 11
(257 Views)