labview与PLC通过OPC通讯

本文详细介绍了如何在LabVIEW中利用OPC服务器与三菱FX3U PLC进行通信。首先,需要下载并安装OPC服务器和数据记录与监控模块。接着,配置OPC服务器,添加新通道并设置通信参数。然后,在LabVIEW中创建I/O服务器,选择OPCClient,并绑定变量。最后,通过新建VI直接在程序框图中操作软元件实现读写PLC数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

LabVIEW使用OPC与PLC通信是十分便捷的,下面讲一下LabVIEW与PLC之间如何通过OPC通信。
1.软件的准备,对于初次安装的LabVIEW,需要在NI Pacage Manger中另外下载OPC服务器(图1)和数据记录与监控模块,数据记录与监控模块需要与所在电脑的labVIEW版本一致,我这里使用的是32 位的LabVIEW2020(如图 2)。
图1 OPC服务器模块在这里插入图片描述
图1 OPC服务器模块
在这里插入图片描述
图2 数据记录与监控模块

2.在所有软件中找到OPC Serves Configuration(图3),打开后的软件如图4所示
在这里插入图片描述
图3 OPC Serves Configuration位置
在这里插入图片描述
图4 软件界面

3.添加一个新的通道,修改通道名称后,点击下一步,如图5所示
在这里插入图片描述
图5 添加一个新通道

4.选择对应的设备(图6),我选用的是三菱FX3U的PLC,所以选择Mitsubishi FX 选项,点击下一步,修改通信参数,然后一直点击下一步,直至完成。
在这里插入图片描述
图6 选择对应的设备
在这里插入图片描述
图7 修改通信参数

5.至此一个新的通道就建好了(图7),
在这里插入图片描述
图7 新建通道

6.点击click to add a device,然后弹出对话框如图8所示;点击下一步,选择对应的PLC型号,如图9所示;一直点击下一步,直至完成。

在这里插入图片描述

图8 弹出对话框
在这里插入图片描述
图9 选择对应PLC型号

7.双击Click to add static tag,添加需要用到的软元件(图10)。
在这里插入图片描述
在这里插入图片描述
图10 添加需要用到的软元件

8.点击第二行最后一个图标Quick Client,监控PLC数据。
在这里插入图片描述
图11 监控PLC数据

9.打开LabVIEW,新建一个空白项目,在我的电脑选项新建一个I/O服务器,在弹出的窗口选择OPC Client选项,点击继续。
在这里插入图片描述
在这里插入图片描述
图12 添加OPC Client

10.在弹出窗口中,选择National Instruments.NIOPCServers.v5选项,点击OK,添加完成
在这里插入图片描述
在这里插入图片描述
图13 选择National Instruments.NIOPCServers.v5

11.右击OPC1,选择创建绑定变量,添加对应的软元件,点击确定。要是没有在OPC Serve中配置的设备,重复第9步和第10步,在第10步中选择与上次不同的选项。
在这里插入图片描述
在这里插入图片描述
图14 绑定变量

12.至此准备工作全部完成,在项目栏中可看到显示的软元件
在这里插入图片描述
图15 显示的软元件
13.新建一个VI,对需要用到的软元件可以直接从项目栏中拖进程序框图,通过改变访问模式对软元件进行读写操作。
在这里插入图片描述
在这里插入图片描述
图16 将软元件加入程序中

西门子PLC通讯Labview库,还不错。 以下是英文声明: Warning, the attached files are experimental VIs provided for educational purposes only. No warrantee is expressed or implied. You should test your code and completely understand the implications of writing to or reading from an operating PLC. PLCs are often used to control hazardous processes and/or equipment. Writing to or reading from a PLC in active control of equipment or process can result in the disruption of the PLC program or data areas, potentially causing economic loss, property damage, generation or release of hazardous substances and/or personal injury up to and including death. Test your software in a controlled environment and qualify it before using it on active equipment or processes. To my knowledge, Siemens has never released the details of the S7 protocol. Much of what is publicly available on S7 is based on observations of the protocol by others. There is an open source S7 data exchange package available at http://libnodave.sourceforge.net/ that documents many S7 features. These VIs were based upon the example posted at http://decibel.ni.com/content/docs/DOC-5467. They were modified by observing and mimicking a S7 data exchange between a protocol converter and a S7-300 series PLC. The observations were accomplished with the wireshark network protocol analyzer, available at http://www.wireshark.org/ and the Wireshark Plugin f黵 S7-Protokoll, available at http://sps-forum.de/showthread.php?p=202763. The Address Area parameter determines which PLC memory area is the target for the reads and writes. I have only tested reads and writes to the Data Block (DB) Area. Your application should read and write to separate read and write DBs dedicated for transfer only. By confining reads and writes to dedicated Data Blocks, the risk of unintended overwrites may be reduced. The data type: S7Com_Transport_Size.ctl is a ring variable that contains the parameter for the size or type of the transfer. I have only had success with the BYTE, INT and DINT transport sizes on an S7-300 series PLC. The other sizes remain in the ring variable for testing on other PLCs. I do not know if the bytes of a multiple-byte variable are read or written atomically. The example contains two top-level VIs: S7Com_Once.vi and S7Com_W+R_Loop.vi. S7Com_Once.vi performs one read or write per execution. It writes to the target PLC from an array of I32, it reads from the target PLC into an array of I32. The number of bytes written is proportional to the number of elements in the array to be written and the transport size parameter. S7Com_W+R_Loop.vi regularly writes to and reads from a pair of DBs in the target PLC. In order to use it, your Step7 PLC project should provide two Data Blocks, DB11 and DB12. See the screen capture image db11&12.PNG for their layout. After downloading the DBs to your PLC, monitor and change DB VAlues with a VAT. As can be seen in the VI, the transfer size is DWORD. Included are example VIs (S7Com_to_PLC(SubVI).vi and S7Com_from_PLC(SubVI).vi) to map variables between Labview and the S7 PLC DBs. In the example, they use the same cluster type definition (S7Com_PLC_Data.ctl) but that is not a requirement. When you change the mappings, you must calculate the size of the variables to be read from the PLC in order to use the correct Read Length parameter. The read length parameter is in transport size units. The write length parameter is taken from the size of the write data array, so if the write data array is larger than you anticipate, data may be overwritten. The hex byte and hex byte array type definitions were created to format the internal data structures to show hex values so that they could be easily compared to the wireshark packet dumps. These VIs have been minimally tested on a NI 9072 cRIO. This is not finished. Needed are better error checking, cleaner S7 Response decoding, and stress testing with malformed data.
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值