LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW 2020 and Python Compatibility

Solved!
Go to solution

Hi,

I need to create a software that interfaces with instruments using traditional RS-232 and then also interface with a MES using OPC UA. Basically, the software acts as a gateway between instrument (and operator inputted data) and MES.

 

LabVIEW do have OPC UA toolkit but to download the toolkit compatible with LabVIEW 2020, I need to have active service license with NI. Since, the LabVIEW at work is under perpetual license and there is not active service license, I cannot download OPC UA toolkit.

 

Since my application might need user scanning bar code to for manual input data, I would like to stick with LabVIEW because of ease of building UI. However, for OPC UA Server/Client, I am thinking of using Python. However, I am not familiar with integrating Python and LabVIEW therefore I am seeking help from the community.

LabVIEW 2020 I am using is a 32-bit version and I assume I need to install 32 bit Python, and with LabVIEW 2020 it looks like it is compatible with 3.6 Python version only. Is 32 bit Python installation required only if I integrate *.py file with LabVIEW, or do I still need 32 bit Python install even if I plan on using executable compiled from the Python code.

If I use executable compiled from the Python code, can I compile with 64 bit Python installation? or I have to still compile with 32 bit Python?

I need a way to update the data in OPC UA Server (built in Python) from LabVIEW. I am thinking of passing it as function parameters (with *.py integration, and Python node) or command line parameter (with executable implementation). If you can suggest a better architecture for the data exchange then I would highly appreciate it.

0 Kudos
Message 1 of 3
(724 Views)
Solution
Accepted by topic author SB_123

I'll vote for a TCP connection between a Python script and LabVIEW. So, your resident Python's script will have an OPC UA connection on one side and a TCP connection on the other side, like a "data pump". Then, implement simple commands like GetVariable, SetVariable, GetStatus, etc.

Advantages — It will work with any Python version, regardless of bitness (then the OPC UA implementation will dictate you which Python version needs to be used). This will also work across the network, so your Python script and LabVIEW app can be placed on different PCs.

Disadvantage - there is a small time penalty for the communication.

Something like this as starting point:

Python side:

 

 

# echo-server.py

import socket

HOST = "127.0.0.1"  # Standard loopback interface address (localhost)
PORT = 65432  # Port to listen on (non-privileged ports are > 1023)

while True:
    print(f"Waiting for connection from port {PORT}...")
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.bind((HOST, PORT))
        s.listen()
        conn, addr = s.accept()
        with conn:
            print(f"Connected by {addr}")
            while True:
                data = conn.recv(1024)
                # Your command parser and OPC UA comm
                print(f"Received {data}")
                if not data:
                    break
                conn.sendall(data)

 

 

 

LabVIEW side:

Echo.png

 

Message 2 of 3
(684 Views)

@Andrey_Dmitriev

Thank you for your suggestion. Interfacing between LabVIEW and Python, and running two different protocols (multithreading) in a single Python program was a new and great learning experience for me.

I have a working POC code now and can proceed with my work. 

0 Kudos
Message 3 of 3
(584 Views)