Calling Python Class Methods Using LabVIEW Python Node

Updated Sep 5, 2018

Reported In

Software

  • LabVIEW 2018

Operating System

  • Windows

Programming Language

  • Python

Other

Python 2.7

Issue Details

How can I call python class methods defined in my python script using the LabVIEW python node?

Solution

Unfortunately, there is no direct way to call python class methods using the LabVIEW 2018 python node. However, you can implement a wrapper function in your python script which then can be called using the python node. An example of such a wrapper functionality could look like this:
 
  • Python script
#define class
class myClass(object):
    def __init__(self, parameter):
        self.__Parameter = parameter
    def GetValue(self):
        return self.__Parameter

#define wrapper for LabVIEW Python node        
def getClassData():
    newClassObject = myClass(4882)
    return newClassObject.GetValue() 
 
  • LabVIEW 2018 block diagram to call the wrapper function


Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.
 

WAS THIS ARTICLE HELPFUL?

Not Helpful