Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send data from LabView to Python and get back

Tags:

python

labview

How do I send data from LabView to Python and get a result back?

like image 676
Yuri Avatar asked Jul 06 '11 13:07

Yuri


1 Answers

One other solution is using the smart messaging library ZeroMQ, which comes with a lot of bindings, almost for all major languages.

For the Python/Labview case there is a nice demo project on sourceforge:

Python-LabVIEW Communication

Client-side ~LabVIEW
enter image description here +
Server-side part (example)

#-----------------------------------------# INFRASTRUCTURE for communication
context = zmq.Context()                   # I/O-DAEMON CONTEXT
socket  = context.socket(zmq.REP)         # ARCHETYPE for a Smart Messaging 
socket.bind( "tcp://127.0.0.1:5555" )     # PORT ready for LabView to .connect()
#-----------------------------------------# TRANSPORT-CLASS-es {ipc|tcp|+..}

while True:                               # LOOP & WAIT FOR REQ-calls
    #                                     # Wait for request from client
    message = socket.recv()
    print("Received request: %s" % message )

    try:
        r = eval( message )
        print(r )

        socket.send(bytearray(str( r ),
                             'utf-8' ))    # send returned value as bytearry to client
    except NameError:
        socket.send( b"Unknown command" )

    except:
        socket.send( b"Unknown error" )
like image 145
user_na Avatar answered Sep 22 '22 03:09

user_na