


高速数据采集要保证速度,也要保证时刻的准确性。
在windows系统里,时间稳定性是个很难的问题。如果PLC发送的数据里带有时间信息,则可以由PLC来保证采样周期的稳定性。
从V2.12版本开始,PLC-Recorder软件可以处理发送电文里的时间戳,有网友用0.24ms的速度外发,软件也能够稳定接收并jingque确定数据的时刻。


下面用S7-1200实现带有时间戳的高速数据采集,测试条件如下:
西门子 S7-1200 1214C,无其他通讯,通讯负载比例:50%。PLC IP地址:192.168.0.1
通过循环中断OB30执行循环发送。OB1里无程序。
通讯协议:UDP(只有该协议,在高速模式下才支持时间戳)。
编程软件和系统:TIA V16
微型工控机(Intel® Celeron J1900 2.0GHz四核低功耗处理器) 4核 4G内存,SSD硬盘,无风扇,WIN10系统,无其他大型软件。


如果PLC通讯负载较低,则很难保证4ms的周期发送,这里设置成50%。
如果用低于4ms的周期外发,实际周期只能做到4ms。相比来说,S7-1500可以做到2ms的实际周期。这也说明S7-1500的运算能力强于S7-1200。


在2ms的循环中断程序里进行发送,通过计数比较或者其他方法获得4ms的周期脉冲,触发发送指令。在通讯结束后进行计数,产生时间戳,并允许下一次发送。
由于S7-1200不支持长整型,时间戳的产生方法与S7-1500也不相同。
以下是发送的电文结构(仅发送前200字节):


以下是UDP类型的设置示例:
指定了接收端IP地址和端口号 192.168.0.100:5010


请用帕姆齐设备类型,目前,仅该类型支持时间戳功能。需要配置来源的IP地址及本机收听的端口号。并将本计算机的IP地址设置成192.168.0.100。


此处配置了采集周期,但在高速模式下不再使用该周期,以收到信息的时刻为准。此处配置了两个虚拟通道,用于高速采集后的解码,获取整型变量的位。


从后一个变量的起始地址和变量长度可以确定该通道的通讯电文的长度。对于TCP类型的连接,
电文长度需要通过后变量进行确定(下例子看出电文长度为200字节)。对于UDP类型的通讯,UDP是按照完整报文进行传输的,可以自动获取长度信息,不需要关注后变量。
变量配置时,不需要定义所有的变量,仅需要定义自己关注的变量即可。
起始地址为0的变量就是PLC里定义的时间戳。


左下角的Hi标志表明目前正处于高速状态。


这是用离线分析软件Ana打开的历史数据文件。从左侧的统计数据可以看出,平均采集周期是4ms。从右侧的波形和标尺可以看出,点距非常均匀。
下面一张图是网友的历史波形,实际采集周期基本是0.24ms。


时间戳是Uint32类型的数据,在西门子PLC里被称为UDint,需要从0到4_294_967_295之间递增,并自然翻转(自动归零)。时间戳的单位必须是微秒,是70分钟翻转一次。
在S7-1500能计算获得纳秒的时间差值,需要除1000,将单位转换成微秒。
在S7-1200里只能获得毫秒的时间差值,需要乘1000,将单位转换成微秒。
时间戳是个时间差值,PLC-Recorder在开始记录时,会将时间戳与计算机的当前时间进行比较(对时),后续就用相对时间进行计算,并自动处理翻转的问题。PLC不需要保证时钟的准确性,只要相对稳定即可。


采集的速度越快,需要的技术越复杂,代价也越大。
PLC-Recorder的主动采集模式,基本只需要在PLC-Recorder里配置变量,不需要在PLC做什么复杂工作,这种方式很便捷,速度也有限(快20ms)。高速模式,就需要在PLC里配置通讯,组织数据,调用通讯语句,才能够实现,对于PLC工程师的要求也是有一些了。
高速模式采用标准以太网通讯协议,这也是大部分PLC都具备的能力,可以被广泛使用来进行快速数据采集。