From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW 2018 Python Node preserving state between calls

I'm working on porting a large code-base from LabVIEW 2012 and the OpenG LabPython toolkit to LabVIEW 2018 and the native Python Node. One issue I've hit is how to preserve state on the Python side between calls to the Python Node? I naively assumed that it would work like the LabPython toolkit did - each session refnum was an instance of the interpreter and once objects were created in the interpreter they hung around until the refnum was closed - but it seems that I'm mistaken!

Is there a way to instantiate a Python object of soem sort in one function call and then get at it in a subsequent call without the overhead of passing things between Python and LabVIEW on every call?

--
Gavin Burnell
Condensed Matter Physics Group, University of Leeds, UK
http://www.stoner.leeds.ac.uk/
0 Kudos
Message 1 of 6
(3,316 Views)

Hi Gavin,

 

My name is Ashley and I am an Applications Engineer at National Instruments.  

 

From what I understand you are able to achieve this with the LabPython toolkit. Are you able to provide an example of this? 

It would be useful to see what you are trying to do using the new 2018 Python integration nodes.

 

From what I have seen, this isn't possible with the native LabVIEW python nodes - on each call to the python code you need to define all of the inputs.

 

Thanks,

Ash

Ashley Nunn | MEng (Hons) | CLA | CTD
Senior Technical Support Engineer, NI
0 Kudos
Message 2 of 6
(3,248 Views)

I have the same question... I would like to write a python module to connect to a database. Ideally the module would contain several functions like: OpenDatabase(), ReadFromDatabase() and CloseDatabase(). For this to work, the python module would need to persist its connection to the database between calls from LabVIEW. It seems this was possible in the LabPython toolkit, but I can't see a way to do it using Python nodes in LabVIEW2018.

 

Thanks in advance.

0 Kudos
Message 3 of 6
(3,088 Views)

@hollowhorse wrote:

I have the same question... I would like to write a python module to connect to a database. Ideally the module would contain several functions like: OpenDatabase(), ReadFromDatabase() and CloseDatabase(). For this to work, the python module would need to persist its connection to the database between calls from LabVIEW. It seems this was possible in the LabPython toolkit, but I can't see a way to do it using Python nodes in LabVIEW2018.

 

Thanks in advance.


+ 1

 

Any new developments on this?

 

Was just the searching for the same thing: how to preserve Python node state between calls.

 

This would be usefull for using Python as a means to connect to databases or equipment which require an Open and Close method.

0 Kudos
Message 4 of 6
(2,959 Views)

+1

 

Intended to create a LV DLL passing the Python session between the functions as a global variable to save overhead introduced by running an Init and shutdown at the beginning and end of each function, but this seems impossible.

Regards,
Eirikur Runarsson
0 Kudos
Message 5 of 6
(2,911 Views)

Hi all,

 

Please post in the LabVIEW Idea Exchange if you would like this functionality to be added:

https://forums.ni.com/t5/LabVIEW-Idea-Exchange/idb-p/labviewideas

 

This will help bring this to the attention of R&D.

 

Thanks,

Ash

Ashley Nunn | MEng (Hons) | CLA | CTD
Senior Technical Support Engineer, NI
0 Kudos
Message 6 of 6
(2,907 Views)