打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
通过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也应该是学生版。




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


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
第7章 LabVIEW调用操作系统功能
第一讲VI的创建--LabVIEW编程的实用技巧系列第一讲——VI的创建
check dependency dll from exe file
Python调用Windows下的DLL
安装Python环境出现“api
使用LabVIEW如何生成应用程序(exe)和安装程序(installer)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服