通过LabPython将Python引入到LabVIEW中

本文介绍如何使用OpenG中的LabPython模块来将Python引入到LabVIEW中,可以加快LabVIEW的编程。


一、安装环境
通过VIPM安装OpenG后,即可使用LabPython模块。
本机运行环境为Win64,Python为2.7.9。
安装的LabPython模块为4.0.0.4,需要的支持环境为【 This package was tested with  Python 2.5  on both Windows 7 x86 and Windows XP x86】

可以继续使用,只是需要设置一下。



二、编写写程序,运行报错


程序在PYTHON New Session_ogtk.vi时就报错:
  error code is the 1046 " LabVIEW cannot initialize the script server.  Ensure the server software is installed. "
表明未安装Python服务。

解决方法如下:
新建一个VI,重新设置Python的服务路径:

注: 在64位的Windows下,python会将32位python27.dll放在C:\Windows\SysWOW64,而不是C:\Windows\System32。

设置完成后,重新运行上一段代码:


以下是LabPython作者关于1046错误的解释:

LabPython version 4.0.0.4 seems only to work with Python2.7.3/32bit, on Win7/64bit and LabVIEW2011 32bit.


and not with Python3.2.3/32bit. Those are the most recent releases. The 64 bit versions of Python does not work with labVIEW32bit.

 

The error code is the 1046 "LabVIEW cannot initialize the script server.  Ensure the server software is installed."

 

And a few comments on the vi "PYTHON set Server Path_ogtk.vi": It has a string input which according to the front panel (its missing a help string!) is

possible values : PythonServer
                  ArrayModule

Why use a string to select between two possible values? A properly crafted enum would be much simpler and less error prone for the user.

 

The quick help window labels the values for this input as "token (empty: PythonServer)". This is non standard and consequently - misleading syntax. The Empty keeword is implicty (default), so a standard syntax would be

token ("PythonServer")

 

By the way, the standard python27.dll location seems to be "C:\Windows\SysWOW64\python27.dll" and not C:\Windows\System32\python27.dll. At least in my installation.



三、关于打包生成应用程序时,LabPython怎么打包?
只是使用Python自带的函数和模块,只需要打包:Pythonxx.dll即可
最好的办法是在目标机器上安装Python和需要使用的工具包,然后在LabVIEW.ini文件中设置;

增加一行 "PythonServer=C:\WINDOWS\system32\python27.dll" 到LabVIEW.ini

通过以上方法基本可以实现调用Python的功能,实现Python在LabVIEW中的内嵌运行。

四、使用Python ScriptNode在程序中直接编写Python语句
借用官方的例程,运行成功!


五、其他工具包

Python Integration Toolkit 

该工具包是收费的,比较好用,兼容Python2.x和3.x,功能比LabPython强大不少。有Home版可以用,但LabVIEW也应该是学生版。




(以上均源自个人研究结果,不当之处,请加以指正。转载请注明出处,谢谢!)


  • 5
    点赞
  • 41
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值