案例|LabVIEW连接S7-1200PLC

5 篇文章 2 订阅
3 篇文章 1 订阅

附带:
写了好的参考文章:
通讯测试工具和博图仿真机的连接教程【内含图文完整过程+软件使用】

解决博图V15 V16 V17 V18等高版本和低版本在同款PLC上不兼容的问题


前言

以下默认读者已经有LabVIEW、PLC软件的基本使用基础
实现LabVIEW和S7-1200PLC之间的通讯功能。
具体:
1)查看是否成功连接(用灯泡显示
2)实现向PLC写入数据
3)实现从PLC读取数据


一、准备条件

  • 软件:
    S71200PLC软件
    LabVIEW2020
    HslCommunicationDemo软件
  • 硬件:
    PLC硬件

二、步骤

1. HslCommunicationDemo

Step1. 打开西门子的PLC项目,查看接口的IP地址【这里我是有实际PLC硬件,通过网线和笔记本连接,并将IP设定为192.168.0.1】,让HslCommunicationDemo中的IP地址相同。
在这里插入图片描述
Step2. 回到PLC,去连接机制中,勾选允许远程通讯访问。
在这里插入图片描述
Step3. 回Demoz中点击连接。提示连接成功就行。
在这里插入图片描述

问题1:连接失败?

在这里插入图片描述
上图的连接失败解决方案:

  • 看看是否是防火墙限定

问题2:CPU硬件和博图上的硬件不匹配?【2种方案

在这里插入图片描述

方法1

我去搜索了很多关于CPU上的程序版本和STEP 7项目的版本V16不兼容的问题。
这边文章对我有所启发:解决博图V15 V16 V17 V18等高版本和低版本在同款PLC上不兼容的问题。他说到博图V17依旧有一个小问题,他这个创建好了,但是固件版本依然是4.5版本的,所以我们需要重新更改一下,点击在线和诊断
对此,我按照步骤去做,虽然我发现了我和自己的PLC固件在线连接后,固件版本为V4.5,不是我用的4.2。但是我是V16版本,最高也只有4.4版。【如下图所示:

步骤:先进行在线连接,点击在线和诊断
在这里插入图片描述
最终,我在“在线和诊断”界面只执行了复位为出厂设置后,重新连接PLC并从设备上上传后,一路绿灯。
在这里插入图片描述

方式2:直接下载硬件包【还没验证】

硬件包下载地址
进去后找到你的博图PLC软件版本号,下载完整版。
在这里插入图片描述

下载后获得的V16包:
在这里插入图片描述

解压后是各种的ISP文件
在这里插入图片描述
在“工具”->"安装包“中安装【如下图所示】
在这里插入图片描述

1.LabVIEW

Step1. 实现与PLC的连接

后面板:
1)互连接口->.NET->构造器节点
在这里插入图片描述
2)构造器内部,去选择HslCommunication.dll文件。就能出现HslCommunication的配置项。
在这里插入图片描述
3)配置项中具体选项

  • HslCommunication.Profinet.Siemens->SiemensS7Net->SimensS7Net构造器
    在这里插入图片描述

4)最终的后面版配置
在这里插入图片描述
启动后,前面板效果为:
在这里插入图片描述

Step2. 向PLC写入数据,从PLC中读取数据

在这里插入图片描述

前面板运行效果:
在这里插入图片描述


2. 1200PLC无法从设备上传?

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

3. 用HslDemo测试工具来控制

前提:已经让HslDemo工具能连接上PLC
在这里插入图片描述

Step1. 在博图PLC中的Main中绘制简单的图

这里面的I0.1和Q0.1都是前面点击添加新设备选择CUP板自带的接口名称【不用管是否物理连接上)
在这里插入图片描述

对HslDemo测试工具的单数据写入测试中,写入Q0.2,和值为1,点击bool写入后,可以看到PLC中实时联通了。【证明测试成功】
在这里插入图片描述


4

在这里插入图片描述

更新时间

2024-07-10
2024-07-11 解决了硬件不匹配问题。
2024-07-12 更新了下载硬件包以解决硬件版本号不匹配的问题。【但是最后一步安装好重新建立项目的验证过程没做,可信性未知】

西门子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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值