annulla
Visualizzazione dei risultati per 
Cerca invece 
Intendevi dire: 

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
Messaggio 1 di 11
933Visualizzazioni

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

 

Messaggio 2 di 11
914Visualizzazioni

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

 

0 Kudos
Messaggio 3 di 11
902Visualizzazioni

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
Messaggio 4 di 11
897Visualizzazioni

Thank you for your help, I have completed it

Sly_Nguyen_0-1750320745252.png

Sly_Nguyen_1-1750320763738.png

 

 

0 Kudos
Messaggio 5 di 11
875Visualizzazioni

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
Messaggio 6 di 11
632Visualizzazioni

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.

Messaggio 7 di 11
625Visualizzazioni

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

Messaggio 8 di 11
621Visualizzazioni

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
Messaggio 9 di 11
607Visualizzazioni

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
Messaggio 10 di 11
579Visualizzazioni