Labview通过NIopc与施耐德plc通信

一、配置opc*

1、安装labview并且安装NIDSC工具包后从工具栏或者开始菜单打开opc工具。
在这里插入图片描述
2、单击CLIck to add a channel.进行配置
在这里插入图片描述
3、Channel name:名字是可以不用改的。
在这里插入图片描述
4、Device driver:设置plc或者设置通信方式,这里设置的modbus以太网通信方式。
在这里插入图片描述
5、后面一直下一步到完成。完成后单击Click to add a device.
在这里插入图片描述
6、cevice name:名字可以不改
在这里插入图片描述
7、设置为Modbus通信
在这里插入图片描述
8、输入施耐德plc的ip地址。然后一 直下一步到完成。
在这里插入图片描述
9单击这个进行配置通信变量地址
在这里插入图片描述
10、name设置名字。Address:设置地址。Plc的%QX一般可以用000001(000###)。Plc的%IX一般可用100001(1000##)plc的%MX一般用400000(400####)来表示。

例如40001在somchine平台上%MW0。 40051.0表示为%MX100.0.Data type:要改为boolean

Descniption:备注
Data type:选择boolean或者wofd。类型
Client access:选择READ/wnite
设置完成后点击确定
在这里插入图片描述
11、点击测试连接
在这里插入图片描述
12、打开channel1.device1后右边是刚才配置后的结果。Auality:good说明与plc连接正常。Value是配置地址的变量值。
在这里插入图片描述

二、在labview创建变量。

1、打开labview新建工程。
在这里插入图片描述
2、右击我的电脑新建I/O服务器。选择opc Client后确定
在这里插入图片描述
3、选择NIopc Servers。Update rate默认 是1000可以改小。设置完成后点击确定。
在这里插入图片描述
4、右击–>OPC1–>创建绑定变量
在这里插入图片描述
5、展开到channel1中x1是刚才在opc中设置的地址名称。选择后点击添加。
在这里插入图片描述
6、确定后会跳出一个界面继续确定。这个时候变量x1就被添加到项目中了。
在这里插入图片描述
7、双击变量x1后选择预警将后面选项全勾上,不勾的话会出现labview可以给变量写入值但是无法读取到变量的值。
在这里插入图片描述
8、将变量直接拖到labview编程后面板即可。添加后默认是读取状态如果需要对变量进行赋值就需要右击变量–>访问模式–>写入。更改完后就可以对变量进行写入值。
在这里插入图片描述

与西门子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、付费专栏及课程。

余额充值