将数据从LabView发送到Python并取回 [英] send data from LabView to Python and get back

查看:553
本文介绍了将数据从LabView发送到Python并取回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将数据从LabView发送到Python并返回结果?

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

推荐答案

另一个解决方案是使用智能消息传递库 ZeroMQ ,它具有很多绑定,几乎适用于所有主要语言.

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

对于Python/Labview案例,在sourceforge上有一个不错的演示项目:

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

Python-LabVIEW通信

客户端〜LabVIEW
+
服务器端部分(示例)

Client-side ~LabVIEW
+
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" )

这篇关于将数据从LabView发送到Python并取回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆