[go: up one dir, main page]

CN111722581A - The method of improving the communication transmission and data processing efficiency between PLC controller and upper computer - Google Patents

The method of improving the communication transmission and data processing efficiency between PLC controller and upper computer Download PDF

Info

Publication number
CN111722581A
CN111722581A CN202010466104.7A CN202010466104A CN111722581A CN 111722581 A CN111722581 A CN 111722581A CN 202010466104 A CN202010466104 A CN 202010466104A CN 111722581 A CN111722581 A CN 111722581A
Authority
CN
China
Prior art keywords
data packet
data
host computer
plc controller
flag
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010466104.7A
Other languages
Chinese (zh)
Other versions
CN111722581B (en
Inventor
李钢
郑作铿
曲小平
郝明明
张伟峰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Nanjing Nanrui Industrial Control Technology Co ltd
Nari Technology Co Ltd
Original Assignee
Nari Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nari Technology Co Ltd filed Critical Nari Technology Co Ltd
Priority to CN202010466104.7A priority Critical patent/CN111722581B/en
Publication of CN111722581A publication Critical patent/CN111722581A/en
Application granted granted Critical
Publication of CN111722581B publication Critical patent/CN111722581B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G05CONTROLLING; REGULATING
    • G05BCONTROL OR REGULATING SYSTEMS IN GENERAL; FUNCTIONAL ELEMENTS OF SUCH SYSTEMS; MONITORING OR TESTING ARRANGEMENTS FOR SUCH SYSTEMS OR ELEMENTS
    • G05B19/00Programme-control systems
    • G05B19/02Programme-control systems electric
    • G05B19/04Programme control other than numerical control, i.e. in sequence controllers or logic controllers
    • G05B19/05Programmable logic controllers, e.g. simulating logic interconnections of signals according to ladder diagrams or function charts
    • G05B19/054Input/output
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services
    • GPHYSICS
    • G05CONTROLLING; REGULATING
    • G05BCONTROL OR REGULATING SYSTEMS IN GENERAL; FUNCTIONAL ELEMENTS OF SUCH SYSTEMS; MONITORING OR TESTING ARRANGEMENTS FOR SUCH SYSTEMS OR ELEMENTS
    • G05B2219/00Program-control systems
    • G05B2219/10Plc systems
    • G05B2219/11Plc I-O input output
    • G05B2219/1101Remote I-O
    • GPHYSICS
    • G05CONTROLLING; REGULATING
    • G05BCONTROL OR REGULATING SYSTEMS IN GENERAL; FUNCTIONAL ELEMENTS OF SUCH SYSTEMS; MONITORING OR TESTING ARRANGEMENTS FOR SUCH SYSTEMS OR ELEMENTS
    • G05B2219/00Program-control systems
    • G05B2219/10Plc systems
    • G05B2219/15Plc structure of the system

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Automation & Control Theory (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)
  • Communication Control (AREA)

Abstract

本发明提供一种提高PLC控制器与上位机通讯传输和数据处理效率的方法,在PLC的监视的数据量大、数据变化少的应用场合,采用本发明,在第一个通讯数据包中,占用若干个数据寄存器作为状态寄存器,用于与上位机传递信息。在PLC控制器中,开辟空间,放置暂存数据包,暂存数据包中的暂存寄存器与当前数据包对应的寄存器进行比较,对于有变化数据的当前数据包对其状态位进行置位,达到对有变化数据的数据包进行重点读取,显著地提高了上位机对变化数据的读取速度和处理速度。另外,对数据包的存储和读取状态进行置位,保证了数据包与状态位的一致性。

Figure 202010466104

The invention provides a method for improving the efficiency of communication, transmission and data processing between a PLC controller and a host computer. In the application situation where the amount of data monitored by the PLC is large and the data changes are small, the invention is adopted. In the first communication data packet, Occupies several data registers as status registers, which are used to transmit information with the host computer. In the PLC controller, open up space, place the temporary data packet, compare the temporary storage register in the temporary data packet with the register corresponding to the current data packet, and set its status bit for the current data packet with changed data, The key reading of data packets with changed data is achieved, which significantly improves the reading speed and processing speed of the changed data by the host computer. In addition, the storage and reading states of the data packets are set to ensure the consistency of the data packets and the status bits.

Figure 202010466104

Description

提高PLC控制器与上位机通讯传输和数据处理效率的方法The method of improving the communication transmission and data processing efficiency between PLC controller and upper computer

技术领域technical field

本发明涉及一种提高PLC传输和处理效率的方法,属于PLC应用领域。The invention relates to a method for improving PLC transmission and processing efficiency, and belongs to the PLC application field.

背景技术Background technique

PLC存在一个很广泛的监视的数据量大、数据变化少的应用场合,例如地铁车站风水电系统,其对风水电的监视是基于BAS(Building Automation System,以下简称BAS)系统采用PLC(Programmable Logic Controller,以下简称PLC)进行监视。PLC has a wide range of applications with large amount of monitoring data and little data change, such as the wind and water power system of subway stations, its monitoring of wind and water power is based on BAS (Building Automation System, hereinafter referred to as BAS) system using PLC (Programmable Logic) Controller, hereinafter referred to as PLC) to monitor.

PLC监视的数据采用寄存器存储和传输,一个寄存器通常占用两个字节。PLC通讯通常基于MODBUS通讯协议,正常报文一包数据125个寄存器,即250个字节。一个地铁车站PLC监视的数字量输入数据通常有三包,模拟量输入数据通常有十几包,查询一包数据需要耗时300毫秒,目前PLC采用全数据上送,则所有数据的传输需要耗时超过3秒,导致轮询周期长,上位机系统中数据刷新慢。上位机还需要消时,进行变化数据的筛选。如果增加数据包包含的寄存器的数量,虽然能减少数据包的数量,相应减少建立通讯链接次数,减少链接的时间,但报文长度增加,导致通讯失败的可能性大幅度提高,致使需要重复通讯,浪费通讯时间。The data monitored by the PLC is stored and transmitted in registers, and a register usually occupies two bytes. PLC communication is usually based on the MODBUS communication protocol, and a normal packet of data contains 125 registers, that is, 250 bytes. The digital input data monitored by a PLC in a subway station usually has three packets, and the analog input data usually has more than ten packets. It takes 300 milliseconds to query one packet of data. At present, the PLC adopts full data upload, so the transmission of all data takes time. If it exceeds 3 seconds, the polling cycle is long and the data refresh in the upper computer system is slow. The host computer also needs to eliminate the time and filter the changed data. If the number of registers included in the data packet is increased, although the number of data packets can be reduced, the number of communication link establishments can be reduced correspondingly, and the link time can be reduced, but the length of the packet increases, which greatly increases the possibility of communication failure, resulting in the need for repeated communication. , wasting communication time.

传统方法上位机都对每个数据包,即使没有变化的数据,仍然依次读取,浪费时间,如果发生突发的变化数据,由于上位机轮询未必正好读到出现变化数据的数据包,最不利的情况下,上位机刚读完一个数据包,此数据包发生数据变化,则上位机需要轮询一圈数据包,才能读到此有变化数据是数据包,如果数据包有十几个个,则上位机反馈变化数据的时延是读取十几个数据包的时间,导致变化数据刷新慢。In the traditional method, the host computer reads each data packet in sequence, even if there is no changed data, which wastes time. In an unfavorable case, the host computer has just finished reading a data packet, and the data packet changes, then the host computer needs to poll a circle of data packets to read the changed data is a data packet, if there are more than a dozen data packets , then the delay for the host computer to feed back the changed data is the time it takes to read more than a dozen data packets, resulting in slow refresh of the changed data.

发明内容SUMMARY OF THE INVENTION

发明目的:本发明的目的是提供一种新的技术方案,用以提高上位机对变化数据的读取速度和处理速度。Purpose of the invention: The purpose of the present invention is to provide a new technical solution to improve the reading speed and processing speed of the changed data by the host computer.

技术方案:为解决上述技术问题,本发明提供一种提高PLC控制器与上位机通讯传输和数据处理效率的方法:Technical solution: In order to solve the above technical problems, the present invention provides a method for improving the communication transmission and data processing efficiency between the PLC controller and the upper computer:

将PLC总体分为两类,分别为PLC控制器和远程IO模块;The PLC is generally divided into two categories, namely PLC controller and remote IO module;

远程IO模块带有模拟量和数字量的输入和输出功能,用于测量和控制,远程IO模块还带有与子系统PLC进行通讯功能;The remote IO module has analog and digital input and output functions for measurement and control, and the remote IO module also has the function of communicating with the subsystem PLC;

PLC控制器带有通讯功能和数据处理功能;PLC controller with communication function and data processing function;

PLC控制器的通讯功能,用于完成各种通讯任务,包括与上位机通讯和与下位机通讯,与下位机通讯包括与远程IO模块通讯、与子系统PLC通讯、与子系统通讯模块通讯,这些通讯任务不受PLC控制器的用户程序控制,PLC通讯配置完成后,自主通讯,通讯的数据存取在PLC控制器中供通讯用的寄存器中;The communication function of the PLC controller is used to complete various communication tasks, including communication with the upper computer and communication with the lower computer. Communication with the lower computer includes communication with the remote IO module, communication with the subsystem PLC, and communication with the subsystem communication module. These communication tasks are not controlled by the user program of the PLC controller. After the PLC communication configuration is completed, it communicates autonomously, and the communication data is stored in the register for communication in the PLC controller;

PLC控制器的数据处理功能,由用户程序控制,对通讯功能读取到供通讯用的寄存器中的数据,进行逻辑判断,作出决策,再写入供通讯用的寄存器中,由PLC控制器的通讯功能进行通讯,以达到控制的目的;The data processing function of the PLC controller is controlled by the user program, and the data read into the register for communication by the communication function is logically judged, a decision is made, and then written into the register for communication. Communication function to communicate for the purpose of control;

前述PLC控制器的供通讯用的寄存器,按照与通讯对侧设备约定的点表进行填写,通讯对侧设备包括上位机和下位机,下位机包括远程IO模块、子系统PLC、子系统通讯模块;The register for communication of the above-mentioned PLC controller is filled in according to the point table agreed with the equipment on the opposite side of the communication. The equipment on the opposite side of the communication includes the upper computer and the lower computer, and the lower computer includes the remote IO module, the subsystem PLC, and the subsystem communication module. ;

前述PLC控制器与上位机进行通讯,数据存储在若干个通讯数据包中,数据包长度受限于与上位机通讯的报文长度的限制,通讯数据包分为三类,分别为数字量数据包、表示数字的模拟量数据包、纯模拟量数据包,数字量数据包放入数字量,表示数字的模拟量数据包放入表示数字的模拟量,纯模拟量数据包放入纯模拟量数据;每个通讯数据包的表示为数字量、表示数字的模拟量、纯模拟量三种数据包中的一种的设置变量保存在PLC控制器中和上位机中;The aforementioned PLC controller communicates with the upper computer, and the data is stored in several communication data packets. The length of the data packet is limited by the length of the message communicated with the upper computer. The communication data packets are divided into three types, which are digital data. Packets, analog data packets that represent digital, pure analog data packets, digital data packets are put into digital data, digital analog data packets are put into digital analog data, and pure analog data packets are put into pure analog data Data; the setting variables of each communication data packet are stored in the PLC controller and the host computer;

前述数字量,是指外部触点的开关量,有接通和断开两种状态,分别以0和1表示;The aforementioned digital quantity refers to the switching quantity of the external contact, which has two states of on and off, which are represented by 0 and 1 respectively;

前述表示数字的模拟量,是指用于计数的数据,表现为模拟量,但当作数字量进行处理;The aforementioned analog quantity representing digital refers to the data used for counting, which is represented as an analog quantity, but is treated as a digital quantity;

前述纯模拟量,是指测量的电压、电流、温度、湿度等会波动的数值;The aforementioned pure analog quantities refer to the measured values of voltage, current, temperature, humidity, etc. that will fluctuate;

前述数字量和表示数字的模拟量,合称为非纯模拟量;The aforementioned digital quantities and analog quantities representing digital are collectively referred to as non-pure analog quantities;

前述通讯数据包由若干个数据寄存器组成,称为通讯寄存器;The aforementioned communication data packet is composed of several data registers, which are called communication registers;

每个通讯数据包包括多个远程IO模块的输入数据、或者包括多个子系统的输入数据;Each communication data packet includes input data of multiple remote IO modules, or includes input data of multiple subsystems;

PLC控制器与上位机通讯的第一个通讯数据包,作为特殊数据包,依据数据包的总量,占用若干个数据寄存器作为状态寄存器,用于与上位机传递信息;The first communication data packet between the PLC controller and the host computer is used as a special data packet. According to the total amount of data packets, it occupies several data registers as status registers, which are used to transmit information with the host computer;

PLC控制器与上位机通讯的第一个通讯数据包以外的通讯数据包,称为后续数据包:The communication data packets other than the first communication data packet between the PLC controller and the upper computer are called subsequent data packets:

前述状态寄存器的各个位用于表示每个后续数据包的“PLC控制器数据包有变化数据标志位”、“PLC控制器正在存储数据包标志位”、“上位机正在读取数据包标志位”、“上位机数据包读取完成标志位”;Each bit of the aforementioned status register is used to indicate the "PLC controller data packet has changed data flag", "PLC controller is storing the data packet flag", "the host computer is reading the data packet flag" of each subsequent data packet. ”, “host computer data packet read completion flag”;

“PLC控制器数据包有变化数据标志位”的定义:为“1”分别对应表示其对应的PLC控制器存储的数据包中至少有一个数据发生变化;为“0”分别对应表示其对应的PLC控制器存储的数据包中没有一个数据发生变化;The definition of "the PLC controller data packet has changed data flag": "1" corresponds to at least one data change in the data packet stored by the corresponding PLC controller; "0" corresponds to its corresponding None of the data in the data package stored by the PLC controller has changed;

“PLC控制器正在存储数据包标志位”的定义:为“1”分别对应表示其对应的数据包PLC控制器正在存储;为“0”分别对应表示其对应的数据包PLC控制器未在存储;The definition of "the PLC controller is storing the data packet flag": "1" corresponds to the corresponding data packet PLC controller is storing; "0" corresponds to the corresponding data packet PLC controller is not in storage. ;

“上位机正在读取数据包标志位”的定义:为“1”分别对应表示其对应的数据包上位机正在读取;为“0”分别对应表示其对应的数据包上位机未正在读取;The definition of "the host computer is reading the data packet flag": "1" corresponds to that the corresponding data packet is being read by the host computer; "0" corresponds to the corresponding data packet that the host computer is not reading. ;

“上位机数据包读取完成标志位”的定义:为“1”分别对应表示其对应的数据包上位机读取完成;为“0”分别对应表示其对应的数据包上位机还未读取;The definition of "host computer data packet reading completion flag": "1" corresponds to the completion of the reading of the corresponding data packet by the host computer; "0" corresponds to the corresponding data packet that the host computer has not read. ;

在PLC控制器中开辟存储空间,用于存放后续数据包的暂存数据包,暂存数据包内部的数据寄存器称为暂存寄存器,暂存数据包中的每个暂存寄存器与前述用于与上位机通讯的通讯数据包中对应的通讯寄存器的定义完全一致,与暂存数据包对应的前述用于与上位机通讯的数据包称为对应的数据包;与暂存寄存器对应的前述用于与上位机通讯的数据包中的寄存器称为对应的数据寄存器;Open up storage space in the PLC controller to store the temporary data packets of subsequent data packets. The data registers inside the temporary data packets are called temporary storage registers. The definition of the corresponding communication register in the communication data packet communicated with the host computer is exactly the same, and the aforementioned data packet corresponding to the temporary storage data packet for communication with the host computer is called the corresponding data packet; the aforementioned data packet corresponding to the temporary storage register is used. The register in the data packet communicated with the host computer is called the corresponding data register;

PLC控制器初始化时,依次进行如下操作:所有后续数据包“上位机正在读取数据包标志位”置“0”,把所有后续数据包“PLC控制器正在存储数据包标志位”置“1”;把每个数据包对应的通讯获得的下位机的存储在寄存器中的数据,复制到每个数据包对应的数据寄存器中;所有后续数据包“PLC控制器数据包有变化数据标志位”置“1”;所有后续数据包“PLC控制器正在存储数据包标志位”置“0”;When the PLC controller is initialized, the following operations are performed in sequence: all subsequent data packets "the host computer is reading the data packet flag" is set to "0", and all subsequent data packets "the PLC controller is storing the data packet flag" is set to "1" ”; copy the data stored in the register of the lower computer obtained by the communication corresponding to each data packet to the data register corresponding to each data packet; all subsequent data packets “PLC controller data packets have changed data flags” Set to "1"; all subsequent data packets "PLC controller is storing data packet flag" set to "0";

PLC控制器开始正常处理流程时,先把第一个数据包对应的存储在寄存器中的通讯获得的下位机的存储在寄存器中的数据,复制到第一个数据包对应的数据寄存器中;再把后续数据包对应的存储在寄存器中的通讯获得的下位机的数据,复制到后续数据包对应的暂存数据包对应的数据寄存器中;When the PLC controller starts the normal processing process, it first copies the data stored in the register of the lower computer obtained by the communication stored in the register corresponding to the first data packet to the data register corresponding to the first data packet; Copy the data of the lower computer corresponding to the communication stored in the register corresponding to the subsequent data packet to the data register corresponding to the temporary data packet corresponding to the subsequent data packet;

“PLC控制器当前数据包处理编号”变量置“2”,此“PLC控制器当前数据包处理编号”变量设置在PLC控制器中,用于表示PLC控制器程序当前正在处理的数据包的编号;The "PLC controller current data packet processing number" variable is set to "2", and this "PLC controller current data packet processing number" variable is set in the PLC controller to indicate the number of the data packet currently being processed by the PLC controller program. ;

下面进入后续数据包的处理流程:“PLC控制器当前数据包寄存器处理编号”变量置“1”,此“PLC控制器当前数据包寄存器处理编号”变量设置在PLC控制器中,用于表示PLC控制器程序当前正在处理的数据包中的寄存器的编号;Now enter the processing flow of subsequent data packets: "PLC controller current data packet register processing number" variable is set to "1", and this "PLC controller current data packet register processing number" variable is set in the PLC controller to indicate PLC the number of the register in the packet that the controller program is currently processing;

PLC控制器依次对于后续数据包,分别按照纯模拟量数据包和非纯模拟量数据包分别逐个进行暂存数据包与对应的数据包有无变化数据的比较和处理;The PLC controller sequentially compares and processes the temporary data packets and the corresponding data packets with or without change data according to the pure analog data packets and the non-pure analog data packets one by one for the subsequent data packets;

当发现当前数据包有寄存器存在变化数据后,如果当前数据包“上位机正在读取数据包标志位”为“0”,并且“上位机数据包读取完成标志位”为“1”,则当前数据包“PLC控制器正在存储数据包标志位”置“1”,当前数据包“PLC控制器数据包有变化数据标志位”置“1”,当前数据包“上位机数据包读取完成标志位”置“0”,此数据包后续的数据不再比较,把当前暂存数据包中的所有数据,复制到当前数据包对应的数据寄存器,完成复制操作后,把当前数据包“PLC控制器正在存储数据包标志位”置“0”,把“PLC控制器当前数据包处理编号”加1,进入下一个循环,直到比较完成所有后续数据包的数据;如果前述当前数据包“上位机正在读取数据包标志位”为“1”,或者“上位机数据包读取完成标志位”为“0”,则放弃前述标志位设置和复制操作,也把“PLC控制器当前数据包处理编号”加1,进入下一个循环,直到比较完成所有后续数据包的数据;When it is found that there is changed data in the register in the current data packet, if the current data packet "the host computer is reading the data packet flag" is "0", and the "host computer data packet reading completion flag" is "1", then The current data packet "PLC controller is storing the data packet flag" is set to "1", the current data packet "PLC controller data packet has changed data flag" is set to "1", the current data packet "The host computer data packet read complete" The flag bit" is set to "0", the subsequent data of this data packet will not be compared, and all the data in the current temporary data packet will be copied to the data register corresponding to the current data packet. After the copy operation is completed, the current data packet "PLC" The controller is storing the data packet flag" and set it to "0", add 1 to the "current data packet processing number of the PLC controller", and enter the next cycle until the comparison of all subsequent data packets is completed; If the flag bit of the data packet is being read by the computer is "1", or the flag bit of "reading completion of the data packet of the upper computer" is "0", then the setting and copying operation of the aforementioned flag bit will be abandoned, and the "current data packet of the PLC controller" will be Add 1 to "processing number" and enter the next loop until the comparison of all subsequent data packets is completed;

当比较完成当前数据包,没有发现有变化的数据后,如果当前数据包“上位机正在读取数据包标志位”为“0”,并且当前数据包“上位机数据包读取完成标志位”为“1”,则把当前数据包“PLC控制器正在存储数据包标志位”置“1”,当前数据包“PLC控制器数据包有变化数据标志位”置“0”,当前数据包“上位机数据包读取完成标志位”置“0”;对于纯模拟量数据包,把当前暂存数据包中的所有数据复制到当前数据包对应的数据寄存器,对于非纯模拟量数据包,不进行此复制操作;再把当前数据包“PLC控制器正在存储数据包标志位”置“0”,把“PLC控制器当前数据包处理编号”加1,进入下一个循环,直到比较完成所有后续数据包的数据;When the current data packet is compared and no changed data is found, if the current data packet "host computer is reading the data packet flag" is "0", and the current data packet "host computer data packet reading completion flag" If it is "1", the current data packet "PLC controller is storing data packet flag" is set to "1", the current data packet "PLC controller data packet has changed data flag" is set to "0", the current data packet " The host computer data packet read completion flag is set to "0"; for pure analog data packets, copy all data in the current temporary data packet to the data register corresponding to the current data packet, for non-pure analog data packets, Do not perform this copy operation; then set the current data packet "PLC controller is storing the data packet flag" to "0", add 1 to the "PLC controller current data packet processing number", and enter the next cycle until the comparison is completed. data of subsequent packets;

前述对数据寄存器逐个比较,判断是否有变化,包括对纯模拟量数据包和非纯模拟量数据包的比较;The aforementioned data registers are compared one by one to determine whether there is a change, including the comparison of pure analog data packets and non-pure analog data packets;

前述对非纯模拟量的的比较,即对数字量或者表示数字的模拟量的比较是指,把暂存寄存器与对应的寄存器逐一比较,当不一致时,则认为当前的暂存寄存器是变化数据;The aforementioned comparison of non-pure analog quantities, that is, the comparison of digital quantities or analog quantities representing digital means, compares the temporary register with the corresponding register one by one, and when it is inconsistent, it is considered that the current temporary register is the change data. ;

前述对纯模拟量的比较是指,在PLC控制器中配置对应于纯模拟量的变量,用于设置各个纯模拟量对应的变化阖值和幅值阖值,对纯模拟量的暂存寄存器的数值与对应的幅值阖值逐一进行比较,当超过幅值阖值,则认为当前的暂存寄存器是变化数据;对纯模拟量的暂存寄存器的数值与对应的寄存器数值逐一进行相减比较,当超过变化阖值,则认为当前的暂存寄存器是变化数据;The aforementioned comparison of pure analog quantities refers to configuring variables corresponding to pure analog quantities in the PLC controller to set the change threshold and amplitude threshold corresponding to each pure analog quantity. Compare the value of the buffer with the corresponding amplitude threshold one by one. When the amplitude threshold is exceeded, the current temporary register is considered to be changed data; the value of the pure analog temporary register and the corresponding register value are subtracted one by one. Comparison, when the change threshold is exceeded, the current temporary register is considered to be the change data;

前述数据包“PLC控制器数据包有变化数据标志位”置“0”,意味着数据包没有变化数据,对于数字量数据包或者表示数字的模拟量数据包而言,是每个暂存寄存器与对应的寄存器数值相同,即没有变化;对于纯模拟量数据包而言,是每个暂存寄存器数值没有超过设定的变化阖值和幅值阖值;The aforementioned data packet "PLC controller data packet has changed data flag" is set to "0", which means that the data packet has no changed data. For digital data packets or analog data packets representing digital, it is each temporary register. It is the same as the corresponding register value, that is, there is no change; for pure analog data packets, the value of each temporary register does not exceed the set change threshold and amplitude threshold;

在上位机中,设置“上位机有变化数据包标志”变量,变量为“1”表示在上位机一轮数据包的处理中,存在“PLC控制器正在存储数据包标志位”为“0”,并且“PLC控制器数据包有变化数据标志位”为“1”的后续数据包,即上位机有需要处理的存在变化数据的后续数据包;In the host computer, set the variable of "the host computer has changed data packet flag", the variable is "1", it means that in one round of data packet processing by the host computer, there is "the PLC controller is storing the data packet flag" as "0" , and the subsequent data packets whose "PLC controller data packet has changed data flag bit" is "1", that is, the host computer has subsequent data packets with changed data that need to be processed;

在上位机中,设置各个后续数据包“上位机记录数据包读取有变化位”变量,变量为“1”表示此后续数据包有变化数据,用于标记有变化数据的后续数据包,用于上位机对有变化的数据包进行后续处理;当上位机处理完成此有变化的数据包后,把此数据包“上位机记录数据包读取有变化位”变量置“0”;In the host computer, set the variable of "the host computer records the data packet read with change bit" variable for each subsequent data packet. The variable is "1", indicating that the subsequent data packet has changed data, which is used to mark the subsequent data packets with changed data. Use The host computer performs subsequent processing on the changed data packet; when the host computer completes the processing of the changed data packet, set the variable of this data packet "the host computer records the data packet to read the changed bit" to "0";

前述每轮指上位机依次处理一遍所有数据包;The aforementioned each round refers to the upper computer processing all the data packets in turn;

在上位机中,设置“上位机当前数据包处理编号”变量,用于记录当前上位机处理的数据包的编号;In the host computer, set the variable "current data packet processing number of the host computer" to record the number of the data packet processed by the current host computer;

上位机初始化时,把“循环读取一个数据包编号”变量置“2”;When the host computer is initialized, set the variable of "cyclically read a data packet number" to "2";

上位机开始新的一轮处理数据时,先无条件读取第一个数据包数据,以便根据第一个数据包中的状态寄存器,依次对后续数据包分别进行处理操作;再把“上位机有变化数据包标志”置“0”、把所有后续数据包“上位机记录数据包读取有变化位”置“0”、“上位机当前数据包处理编号”置“2”;When the host computer starts a new round of data processing, it first unconditionally reads the data of the first data packet, so as to process the subsequent data packets in turn according to the status register in the first data packet; Change data packet flag" is set to "0", and all subsequent data packets are set to "0" for "the host computer records the data packet read change bit", and "the current data packet processing number of the host computer" is set to "2";

上位机对于“PLC控制器正在存储数据包标志位”为“1”的后续数据包,不作处理,“上位机当前数据包处理编号”加1,去处理下一个数据包;The host computer does not process the subsequent data packets whose "PLC controller is storing the data packet flag" is "1", and adds 1 to the "current data packet processing number of the host computer" to process the next data packet;

上位机对于“PLC控制器正在存储数据包标志位”为“0”并且“PLC控制器数据包有变化数据标志位”为“0”的后续数据包,把当前数据包“上位机正在读取数据包标志位”置“1”,当前数据包“上位机数据包读取完成标志位”置“1”,当前数据包“上位机正在读取数据包标志位”置“0”,“上位机当前数据包处理编号”加1,去处理下一个数据包;For the subsequent data packets whose "PLC controller is storing data packet flag" is "0" and "PLC controller data packet has changed data flag" is "0", the host computer puts the current data packet "The host computer is reading "Data packet flag" is set to "1", the current data packet "host computer data packet read completion flag" is set to "1", the current data packet "host computer is reading the data packet flag" is set to "0", "host computer is reading the data packet flag" Add 1 to the current data packet processing number of the machine to process the next data packet;

上位机对于“PLC控制器正在存储数据包标志位”为“0”并且“PLC控制器数据包有变化数据标志位”为“1”的后续数据包,依次进行如下操作:当前数据包“上位机正在读取数据包标志位”置“1”,读取当前数据包所有数据,当前数据包“上位机数据包读取完成标志位”置“1”,当前数据包“上位机正在读取数据包标志位”置“0”,“上位机有变化数据包标志”置“1”,当前数据包“上位机记录数据包读取有变化位”置“1”,“上位机当前数据包处理编号”加1,再去处理下一个数据包;The host computer performs the following operations in sequence for the subsequent data packets whose "PLC controller is storing data packet flag" is "0" and "PLC controller data packet has changed data flag" is "1": the current data packet "host" The computer is reading the data packet flag" is set to "1", read all the data of the current data packet, the current data packet "host computer data packet read completion flag" is set to "1", the current data packet "host computer is reading "Data packet flag bit" is set to "0", "the host computer has changed data packet flag" is set to "1", the current data packet "the host computer records the data packet read change bit" is set to "1", "the host computer current data packet" is set to "1" "Processing number" plus 1, and then go to process the next data packet;

上位机完成了所有后续数据包中的上述三种数据包的读取处理后,当“上位机有变化数据包标志”为“1”时,进入下一轮处理数据包的循环;当“上位机有变化数据包标志”为“0”时,进行循环读取一个数据包;After the host computer completes the reading processing of the above three data packets in all subsequent data packets, when the "host computer has changed data packet flag" is "1", it enters the next round of processing data packets; When the machine has changed data packet flag" is "0", read a data packet cyclically;

前述循环读取一个数据包,步骤依次如下:把“循环读取一个数据包一轮计数”置“2”,把“循环读取一个数据包编号”变量的数值赋给“上位机当前数据包处理编号”变量;The aforementioned loop reads a data packet, and the steps are as follows: set the "loop read a data packet round count" to "2", and assign the value of the "loop read a data packet number" variable to the "current data packet of the upper computer" handle number" variable;

当当前数据包“PLC控制器数据包有变化数据标志位”为“0”并且“PLC控制器正在存储数据包标志位”为“0”时,依次进行如下操作:把当前数据包“上位机正在读取数据包标志位”置“1”,读取当前数据包所有数据,当前数据包“上位机数据包读取完成标志位”置“1”,当前数据包“上位机正在读取数据包标志位”置“0”,“循环读取一个数据包编号”加1,当“循环读取一个数据包编号”大于数据包数量时,“循环读取一个数据包编号”置“2”,进入下一轮处理数据包的循环;当“循环读取一个数据包编号”不大于数据包数量时,进入下一轮处理数据包的循环;当当前数据包“PLC控制器数据包有变化数据标志位”为“1”或者“PLC控制器正在存储数据包标志位”为“1”时,依次进行如下操作:“上位机当前数据包处理编号”加1,当“上位机当前数据包处理编号”大于数据包数量时,把“上位机当前数据包处理编号”置“2”,把“循环读取一个数据包一轮计数”加1;当“上位机当前数据包处理编号”不大于数据包数量时,把“循环读取一个数据包一轮计数”加1;当“循环读取一个数据包一轮计数”不大于数据包数量时,对下一个数据包进行处理,直到“循环读取一个数据包一轮计数”大于数据包数量时,结束此次循环,进入下一轮处理数据包的循环;When the current data packet "PLC controller data packet has changed data flag" is "0" and "PLC controller is storing data packet flag" is "0", the following operations are performed in sequence: "Reading data packet flag" is set to "1", read all data of the current data packet, the current data packet "host computer data packet read completion flag" is set to "1", the current data packet "host computer is reading data" "Packet flag bit" is set to "0", "cyclically read a data packet number" is incremented by 1, when "cyclically read a data packet number" is greater than the number of data packets, "cyclically read a data packet number" is set to "2" , enter the next round of data packet processing cycle; when the "cycle read a data packet number" is not greater than the number of data packets, enter the next round of data packet processing cycle; when the current data packet "PLC controller data packet has changed When the "Data flag bit" is "1" or the "PLC controller is storing the data packet flag bit" is "1", the following operations are performed in sequence: "The current data packet processing number of the upper computer" is incremented by 1, when the "current data packet processing number of the upper computer" is "1" When the "processing number" is greater than the number of data packets, set the "current data packet processing number of the host computer" to "2", and add 1 to the "cycle reading a data packet round count"; when the "current data packet processing number of the host computer" is not When the number of data packets is greater than the number of data packets, add 1 to the "count of one round of reading a data packet cyclically"; when the "count of one round of reading a data packet circularly" is not greater than the number of data packets, process the next data packet until " When the cycle count of reading a data packet in a loop is greater than the number of data packets, the cycle ends and the next cycle of processing data packets is entered;

前述在上位机中设置“循环读取一个数据包编号”变量,用于当上位机在处理完一轮数据包后,没有读到变化数据包时,则在每一轮中依次读取一个没有变化数据的数据包;前述循环读取,是指依次读取;The above-mentioned variable "cyclically read a data packet number" is set in the host computer, so that when the host computer does not read a changed data packet after processing a round of data packets, it will read one in each round in turn. Data packets of changing data; the aforementioned cyclic reading refers to sequential reading;

前述“循环读取一个数据包一轮计数”变量,在上位机中设置,用于保证循环读取所有后续数据包中的一个数据包。The aforesaid variable of "circularly read one data packet for one round" is set in the host computer to ensure that one data packet in all subsequent data packets is read cyclically.

进一步的,PLC控制器的第一个数据包中的数据寄存器存放变化频繁的纯模拟量数据,并且尽可能占满数据包。Further, the data register in the first data packet of the PLC controller stores frequently changing pure analog data, and fills the data packet as much as possible.

进一步的,PLC控制器的第一个数据包中设置的状态寄存器,根据被存储的数据容量,选择是两个寄存器、一个寄存器、或者三个寄存器,状态寄存器的放置位置在第一个数据包的开头或者第一个数据包的结尾。Further, the status register set in the first data packet of the PLC controller is selected to be two registers, one register, or three registers according to the stored data capacity, and the placement position of the status register is in the first data packet. or the end of the first packet.

进一步的,PLC控制器的第一个数据包只作为数据状态包,即只存放状态寄存器,不存储数据,这样原来的第一个数据包的数据,存储到第二个数据包,数据包总数增加一个,前述后续数据包则包括原来的第一个数据包。Further, the first data packet of the PLC controller is only used as a data status packet, that is, only the status register is stored, and no data is stored, so that the original data of the first data packet is stored in the second data packet, and the total number of data packets is Add one, and the aforementioned subsequent data packets include the original first data packet.

进一步的,PLC控制器用位表示的后续数据包状态,或者用寄存器来表示,即后续数据包的“PLC控制器数据包有变化数据标志位”、“PLC控制器正在存储数据包标志位”、“上位机正在读取数据包标志位”、“上位机数据包读取完成标志位”,或者用“PLC控制器数据包有变化数据标志寄存器”、“PLC控制器正在存储数据包标志寄存器”、“上位机正在读取数据包标志寄存器”、“上位机数据包读取完成标志寄存器”来表示。Further, the status of the subsequent data packets represented by the PLC controller in bits, or represented by registers, that is, "the PLC controller data packet has a changed data flag", "the PLC controller is storing the data packet flag", "The host computer is reading the data packet flag", "the host computer data packet reading completion flag", or use "PLC controller data packet has changed data flag register", "PLC controller is storing data packet flag register" , "the host computer is reading the data packet flag register", "the host computer data packet read complete flag register" to indicate.

进一步的,在PLC控制器中选择不设置当前数据包“上位机数据包读取完成标志位”,即PLC控制器不判断上位机读取完成,就更新存储,以提高PLC控制器存储速度。Further, choose not to set the current data packet "host computer data packet read completion flag" in the PLC controller, that is, the PLC controller will update the storage without judging that the host computer reading is completed, so as to improve the storage speed of the PLC controller.

以上提供的技术方案中,在PLC控制器中增加暂存数据包,分别逐个进行暂存数据包与对应的数据包有无变化数据的比较和处理,再通过在第一个数据包中设置的状态寄存器,与上位机传递信息,表示每个后续数据包的“PLC控制器数据包有变化数据标志位”、“PLC控制器正在存储数据包标志位”、“上位机正在读取数据包标志位”、“上位机数据包读取完成标志位”。从而避免传统方法在绝大多数情况下,进行无任何变化数据的数据包的无效传输,从而大大提高了PLC控制器与上位机通讯传输和数据处理效率。In the technical solutions provided above, the temporary storage data packets are added to the PLC controller, and the comparison and processing of the temporary storage data packets and the corresponding data packets with or without change data are carried out one by one, and then through the set in the first data packet. The status register transmits information with the host computer, indicating that the "PLC controller data packet has changed data flag", "the PLC controller is storing the data packet flag", "the host computer is reading the data packet flag" of each subsequent data packet bit", "host computer data packet read completion flag bit". Therefore, in most cases, the traditional method can avoid invalid transmission of data packets without any changed data, thereby greatly improving the communication transmission and data processing efficiency between the PLC controller and the upper computer.

PLC控制器在进行某个后续数据包的变化数据比较过程中,一旦发现有变化数据,则不再进行数据比较,标注此数据包为有变化数据的数据包,以便与上位机通讯传输,目的是减少PLC控制器的CPU开销,调高数据处理速率。In the process of comparing the changed data of a subsequent data packet, once the PLC controller finds that there is changed data, it will no longer compare the data, and mark the data packet as a data packet with changed data, so as to communicate and transmit with the host computer. It is to reduce the CPU overhead of the PLC controller and increase the data processing rate.

PLC控制器的第一个数据包中的数据寄存器,存放变化频繁的纯模拟量数据,并且尽可能占满数据包。因为第一个数据包是特殊数据包,每一轮都需要传输,而纯模拟量即使都没有超过阖值,也可能出现低于阖值的波动,上位机中最好能及时反映。The data register in the first data packet of the PLC controller stores frequently changing pure analog data, and fills the data packet as much as possible. Because the first data packet is a special data packet, it needs to be transmitted every round, and even if the pure analog quantity does not exceed the threshold value, there may be fluctuations below the threshold value, and it is best to reflect it in the host computer in time.

把传统按照数字量和模拟量进行区分的数据,改为按照数字量、表示数字的模拟量、纯模拟量进行区分,即把模拟量分为表示数字的模拟量和纯模拟量,并把表示数字的模拟量,例如风机启动次数、风机故障次数,看作数字量进行比较和处理,当前后两次的数据相同,则认为次数相同;当数据不同,则认为次数发生变化,从而简化了表示数字的模拟量的比较和处理。The data that is traditionally distinguished by digital and analog is changed to be distinguished by digital, analog representing digital, and pure analog, that is, dividing analog into digital analog and pure analog, and expressing Digital analog quantities, such as the number of fan starts and the number of fan failures, are regarded as digital quantities for comparison and processing. If the current and last two data are the same, the number of times is considered to be the same; when the data are different, the number of times is considered to have changed, which simplifies the representation. Comparison and processing of digital and analog quantities.

上位机在绝大多数情况下,不存在有变化数据的后续数据包需要通讯,因此在上位机中设置“循环读取一个数据包编号”变量,用于当上位机在处理完一轮数据包后,没有处理到变化数据包时,则在每一轮中依次读取一个没有变化数据的数据包。对于数字量、表示数字的模拟量的数据包的读取,虽然数据没有变化,但读取是用于刷新数据,以免上位机中数据由于内存泄漏等原因导致被篡改;对于纯模拟量数据包的读取,虽然没有纯模拟量超过阖值,但纯模拟量在阖值以下仍然会有小幅波动,读取的目的是更新数据。这种情况,还有一个好处是即使上位机没有变化的后续数据包需要读取,但仍然读取一个后续数据包。In the vast majority of cases, the host computer does not have subsequent data packets with changed data that need to be communicated. Therefore, the variable "Read a data packet number cyclically" is set in the host computer, which is used when the host computer finishes processing a round of data packets. Afterwards, when no change data packet is processed, a data packet with no change data is sequentially read in each round. For the reading of digital and analog data packets representing digital, although the data does not change, the reading is used to refresh the data, so as to prevent the data in the host computer from being tampered with due to memory leaks and other reasons; for pure analog data packets Although no pure analog quantity exceeds the threshold value, the pure analog quantity will still fluctuate slightly below the threshold value, and the purpose of reading is to update the data. In this case, another advantage is that even if the subsequent data packets that have not changed in the upper computer need to be read, a subsequent data packet is still read.

在上位机中设置“循环读取一个数据包一轮计数”变量,用于计数,去寻找读取一个无变化数据并且没在存储数据包,当此计数大于数据包数量时,即PLC控制器不存在前述这种数据包,则不再去寻找这种数据包,进入新一轮数据包的判断和处理。In the host computer, set the variable of "cycle reading a data packet for one round count", which is used for counting, to find and read an unchanged data and no data packet is being stored. When the count is greater than the number of data packets, that is, the PLC controller If there is no such data packet as described above, then it will no longer search for such data packet, and enter into a new round of data packet judgment and processing.

在PLC控制器的第一个数据包中设置状态寄存器,提高了数据传输和处理的效率。此状态寄存器占用数据包中几个原来用于存放数据的寄存器,由于一包有125个或者更多寄存器,因此对数据的存储量的影响微小。Setting the status register in the first data packet of the PLC controller improves the efficiency of data transmission and processing. This status register occupies several registers in the data packet that were originally used to store data. Since there are 125 or more registers in a packet, the impact on the storage capacity of data is small.

有益效果beneficial effect

相对于现有技术,本发明提供的技术方案可以具有以下有益效果:Compared with the prior art, the technical solution provided by the present invention can have the following beneficial effects:

采用本发明,在第一个通讯数据包中,占用若干个数据寄存器作为状态寄存器,用于与上位机传递信息。在PLC控制器中,开辟空间,放置暂存数据包,暂存数据包中的暂存寄存器与当前数据包对应的寄存器进行比较,对于有变化数据的当前数据包对其状态位进行置位,达到对有变化数据的数据包进行重点读取,显著地提高了上位机对变化数据的读取速度和处理速度。另外,对数据包的存储和读取状态进行置位,保证了数据包与状态位的一致性。By adopting the present invention, in the first communication data packet, several data registers are occupied as status registers for transmitting information with the upper computer. In the PLC controller, open up space, place the temporary data packet, compare the temporary storage register in the temporary data packet with the register corresponding to the current data packet, and set its status bit for the current data packet with changed data, The key reading of data packets with changed data is achieved, which significantly improves the reading speed and processing speed of the changed data by the host computer. In addition, the storage and reading states of the data packets are set to ensure the consistency of the data packets and the status bits.

附图说明Description of drawings

图1为PLC控制器数据处理逻辑图。Fig. 1 is the logic diagram of PLC controller data processing.

图2为上位机数据处理逻辑图。Fig. 2 is the logic diagram of the data processing of the upper computer.

具体实施方式Detailed ways

结合图1及图2所示,本发明提供了一种提高PLC控制器与上位机通讯传输和数据处理效率的方法,包括图1所示的PLC控制器数据处理逻辑,如图2所示的上位机数据处理初始化逻辑。1 and 2, the present invention provides a method for improving the communication transmission and data processing efficiency between the PLC controller and the host computer, including the PLC controller data processing logic shown in FIG. 1, as shown in FIG. 2 . The upper computer data processing initialization logic.

在PLC的监视的数据量大、数据变化少的应用场合,例如地铁车站风水电系统,采用本发明,宜采用短数据包,例如一个数据包125个寄存器,而不宜采用长数据包例如一个数据包2000个寄存器,因为增加一个数据包包含的寄存器数量,虽然能减少数据包的数量,但如果长数据包中存在一个超过阖值的模拟量,或者有一个变化的数字量,则为了这一个数据,整个数据包必须发送,导致效率低下,因此采用长数据包不如采用短数据包。In the applications where the amount of data monitored by the PLC is large and the data changes are small, such as the wind, water and power system of the subway station, using the present invention, it is appropriate to use a short data packet, such as 125 registers in a data packet, rather than a long data packet such as a data packet. Pack 2000 registers, because increasing the number of registers contained in a data packet can reduce the number of data packets, but if there is an analog quantity exceeding the threshold value in the long data packet, or there is a changing digital quantity, then for this one Data, the entire packet must be sent, resulting in inefficiency, so using long packets is not as good as using short packets.

在PLC控制器中,开辟空间,放置暂存数据包,暂存数据包中的暂存寄存器与当前数据包对应的寄存器进行比较,对于有变化数据的当前数据包标注“PLC控制器数据包有变化数据标志位”。In the PLC controller, open up space, place the temporary data packet, compare the temporary storage register in the temporary data packet with the register corresponding to the current data packet, and mark the current data packet with changed data "PLC controller data packet has Change data flags".

另外对各个后续数据包设置“PLC控制器正在存储数据包标志位”、“上位机正在读取数据包标志位”、“上位机数据包读取完成标志位”标志位,用于对PLC控制器进行数据包的存储数据和对上位机读取数据包进行限制,以免上位机读取的一个数据包中一部分是旧数据,另一部分是新数据,更避免可能出现的数据包与状态位的不一致。In addition, for each subsequent data packet, set the "PLC controller is storing the data packet flag", "the host computer is reading the data packet flag", "the host computer data packet reading complete flag" flag, which is used to control the PLC. The controller stores data in data packets and restricts the data packets read by the host computer, so that part of a data packet read by the host computer is old data and the other part is new data, so as to avoid possible data packets and status bits. inconsistent.

在有些追求提高PLC控制器存储速度,不追求上位机对每一次数据都进行读取的场合,可以不在PLC控制器中设置当前数据包“上位机数据包读取完成标志位”,即PLC控制器不判断上位机读取完成,就更新存储。In some occasions that seek to improve the storage speed of the PLC controller and do not pursue the host computer to read every data, it is not necessary to set the current data packet "host computer data packet read completion flag" in the PLC controller, that is, the PLC control If the controller does not judge that the reading of the upper computer is completed, it will update the storage.

传统方法,即没有采用本发明的传统的上位机对PLC控制器的读取的方法,无论数据包是否有变化数据,上位机都对每个数据包依次读取,浪费时间,如果发生突发的变化数据,由于上位机轮询未必正好读到出现变化数据的数据包,最不利的情况下,上位机刚读完一个数据包,此数据包发生数据变化,则上位机需要轮询一遍数据包,才能读到此有变化数据的数据包,如果数据包总数为十几个,则上位机反馈变化数据的时延是读取十几个数据包的时间,导致变化数据更新缓慢。但如果采用本发明的方法:The traditional method, that is, the method of reading the PLC controller by the traditional host computer of the present invention is not adopted. Regardless of whether the data packet has changed data, the host computer reads each data packet in turn, which wastes time. Since the host computer polling may not read the data packets with changed data exactly, in the worst case, the host computer has just read a data packet, and the data packet changes, then the host computer needs to poll the data again. If the total number of data packets is more than a dozen, the time delay for the host computer to feed back the changed data is the time it takes to read more than a dozen data packets, resulting in slow update of the changed data. But if the method of the present invention is adopted:

在绝大多数情况下,不存在有变化数据的后续数据包需要读取,上位机在每一轮中依次读取只一个没有变化数据的数据包。如果在轮询一遍读取一个没有变化数据的数据包的过程中,出现一个变化数据,则上位机在下一轮数据包的处理中,就可以立即读取此变化数据对应的数据包,时延是读取一个数据包的时间,读取速度远高于传统方法。In most cases, there is no subsequent data packet with changed data that needs to be read, and the host computer sequentially reads only one data packet with no changed data in each round. If a change data appears in the process of polling to read a data packet with no changed data, the host computer can immediately read the data packet corresponding to the changed data in the next round of data packet processing, and the delay is the time to read one packet, which is much faster than traditional methods.

当存在一个有变化数据的后续数据包需要读取,上位机立即读取此数据包。如果在读取此有变化数据的数据包的过程中,出现另外一个有变化数据的数据包,则在下一轮数据包的处理中,就可以立即读取此有变化数据的数据包,时延是读取一个数据包的时间,读取速度远高于传统方法。When there is a subsequent data packet with changed data that needs to be read, the host computer immediately reads the data packet. If another data packet with changed data appears in the process of reading this data packet with changed data, in the next round of data packet processing, the data packet with changed data can be read immediately, and the delay is the time to read one packet, which is much faster than traditional methods.

当存在一个有变化数据的后续数据包需要读取,上位机立即读取此数据包。如果在读取此有变化数据的数据包的过程中,出现另外多个有变化数据的数据包,则在下一轮数据包的处理中,就可以立即读取这几个有变化数据的数据包,时延是读取一个数据包的时间,读取速度远高于传统方法。When there is a subsequent data packet with changed data that needs to be read, the host computer immediately reads the data packet. If during the process of reading this data packet with changed data, there are several other data packets with changed data, then in the next round of data packet processing, these data packets with changed data can be read immediately , the latency is the time to read a data packet, and the reading speed is much higher than the traditional method.

当存在一个有变化数据的后续数据包需要读取,上位机立即读取此数据包。如果在读取此有变化数据的数据包的过程中,发生极端情况,即每个数据包都出现变化数据,则在下一轮数据包的处理中,依次读取每个数据包,读取速度与传统方法相同。When there is a subsequent data packet with changed data that needs to be read, the host computer immediately reads the data packet. If an extreme situation occurs in the process of reading this data packet with changed data, that is, each data packet has changed data, then in the next round of data packet processing, each data packet is read in turn, and the reading speed Same as traditional method.

另外传统方法,上位机在每一轮的数据包的读取过程中,要找到变化的数据进行后续的处理非常耗时,而采用本发明的方法,在上位机中,设置各个后续数据包“上位机记录数据包读取有变化位”变量,变量为“1”表示此后续数据包有变化数据,用于标记有变化数据的后续数据包,便于对上位机对有变化的数据包进行后续处理。In addition to the traditional method, it is very time-consuming for the host computer to find the changed data for subsequent processing during the reading process of each round of data packets, but using the method of the present invention, in the host computer, each subsequent data packet is set. The host computer records the data packet read with a changed bit" variable, the variable is "1", indicating that the subsequent data packet has changed data, which is used to mark the subsequent data packets with changed data, which is convenient for the host computer to follow up on the changed data packets. deal with.

Claims (6)

1.一种提高PLC控制器与上位机通讯传输和数据处理效率的方法,其特征在于,1. a method for improving PLC controller and host computer communication transmission and data processing efficiency, is characterized in that, 将PLC总体分为两类,分别为PLC控制器和远程IO模块;The PLC is generally divided into two categories, namely PLC controller and remote IO module; 远程IO模块带有模拟量和数字量的输入和输出功能,用于测量和控制,远程IO模块还带有与子系统PLC进行通讯功能;The remote IO module has analog and digital input and output functions for measurement and control, and the remote IO module also has the function of communicating with the subsystem PLC; PLC控制器带有通讯功能和数据处理功能;PLC controller with communication function and data processing function; PLC控制器的通讯功能,用于完成各种通讯任务,包括与上位机通讯和与下位机通讯,与下位机通讯包括与远程IO模块通讯、与子系统PLC通讯、与子系统通讯模块通讯,这些通讯任务不受PLC控制器的用户程序控制,PLC通讯配置完成后,自主通讯,通讯的数据存取在PLC控制器中供通讯用的寄存器中;The communication function of the PLC controller is used to complete various communication tasks, including communication with the upper computer and communication with the lower computer. Communication with the lower computer includes communication with the remote IO module, communication with the subsystem PLC, and communication with the subsystem communication module. These communication tasks are not controlled by the user program of the PLC controller. After the PLC communication configuration is completed, it communicates autonomously, and the communication data is stored in the register for communication in the PLC controller; PLC控制器的数据处理功能,由用户程序控制,对通讯功能读取到供通讯用的寄存器中的数据,进行逻辑判断,作出决策,再写入供通讯用的寄存器中,由PLC控制器的通讯功能进行通讯,以达到控制的目的;The data processing function of the PLC controller is controlled by the user program, and the data read into the register for communication by the communication function is logically judged, a decision is made, and then written into the register for communication. Communication function to communicate for the purpose of control; 前述PLC控制器的供通讯用的寄存器,按照与通讯对侧设备约定的点表进行填写,通讯对侧设备包括上位机和下位机,下位机包括远程IO模块、子系统PLC、子系统通讯模块;The register for communication of the above-mentioned PLC controller is filled in according to the point table agreed with the equipment on the opposite side of the communication. The equipment on the opposite side of the communication includes the upper computer and the lower computer, and the lower computer includes the remote IO module, the subsystem PLC, and the subsystem communication module. ; 前述PLC控制器与上位机进行通讯,数据存储在若干个通讯数据包中,数据包长度受限于与上位机通讯的报文长度的限制,通讯数据包分为三类,分别为数字量数据包、表示数字的模拟量数据包、纯模拟量数据包,数字量数据包放入数字量,表示数字的模拟量数据包放入表示数字的模拟量,纯模拟量数据包放入纯模拟量数据;每个通讯数据包的表示为数字量、表示数字的模拟量、纯模拟量三种数据包中的一种的设置变量保存在PLC控制器中和上位机中;The aforementioned PLC controller communicates with the upper computer, and the data is stored in several communication data packets. The length of the data packet is limited by the length of the message communicated with the upper computer. The communication data packets are divided into three types, which are digital data. Packets, analog data packets that represent digital, pure analog data packets, digital data packets are put into digital data, digital analog data packets are put into digital analog data, and pure analog data packets are put into pure analog data Data; the setting variables of each communication data packet are stored in the PLC controller and the host computer; 前述数字量,是指外部触点的开关量,有接通和断开两种状态,分别以0和1表示;The aforementioned digital quantity refers to the switching quantity of the external contact, which has two states of on and off, which are represented by 0 and 1 respectively; 前述表示数字的模拟量,是指用于计数的数据,表现为模拟量,但当作数字量进行处理;The aforementioned analog quantity representing digital refers to the data used for counting, which is represented as an analog quantity, but is treated as a digital quantity; 前述纯模拟量,是指测量的电压、电流、温度、湿度等会波动的数值;The aforementioned pure analog quantities refer to the measured values of voltage, current, temperature, humidity, etc. that will fluctuate; 前述数字量和表示数字的模拟量,合称为非纯模拟量;The aforementioned digital quantities and analog quantities representing digital are collectively referred to as non-pure analog quantities; 前述通讯数据包由若干个数据寄存器组成,称为通讯寄存器;The aforementioned communication data packet is composed of several data registers, which are called communication registers; 每个通讯数据包包括多个远程IO模块的输入数据、或者包括多个子系统的输入数据;Each communication data packet includes input data of multiple remote IO modules, or includes input data of multiple subsystems; PLC控制器与上位机通讯的第一个通讯数据包,作为特殊数据包,依据数据包的总量,占用若干个数据寄存器作为状态寄存器,用于与上位机传递信息;The first communication data packet between the PLC controller and the host computer is used as a special data packet. According to the total amount of data packets, it occupies several data registers as status registers, which are used to transmit information with the host computer; PLC控制器与上位机通讯的第一个通讯数据包以外的通讯数据包,称为后续数据包:The communication data packets other than the first communication data packet between the PLC controller and the upper computer are called subsequent data packets: 前述状态寄存器的各个位用于表示每个后续数据包的“PLC控制器数据包有变化数据标志位”、“PLC控制器正在存储数据包标志位”、“上位机正在读取数据包标志位”、“上位机数据包读取完成标志位”;Each bit of the aforementioned status register is used to indicate the "PLC controller data packet has changed data flag", "PLC controller is storing the data packet flag", "the host computer is reading the data packet flag" of each subsequent data packet. ”, “host computer data packet read completion flag”; “PLC控制器数据包有变化数据标志位”的定义:为“1”分别对应表示其对应的PLC控制器存储的数据包中至少有一个数据发生变化;为“0”分别对应表示其对应的PLC控制器存储的数据包中没有一个数据发生变化;The definition of "the PLC controller data packet has changed data flag": "1" corresponds to at least one data change in the data packet stored by the corresponding PLC controller; "0" corresponds to its corresponding None of the data in the data package stored by the PLC controller has changed; “PLC控制器正在存储数据包标志位”的定义:为“1”分别对应表示其对应的数据包PLC控制器正在存储;为“0”分别对应表示其对应的数据包PLC控制器未在存储;The definition of "the PLC controller is storing the data packet flag": "1" corresponds to the corresponding data packet PLC controller is storing; "0" corresponds to the corresponding data packet PLC controller is not in storage. ; “上位机正在读取数据包标志位”的定义:为“1”分别对应表示其对应的数据包上位机正在读取;为“0”分别对应表示其对应的数据包上位机未正在读取;The definition of "the host computer is reading the data packet flag": "1" corresponds to that the corresponding data packet is being read by the host computer; "0" corresponds to the corresponding data packet that the host computer is not reading. ; “上位机数据包读取完成标志位”的定义:为“1”分别对应表示其对应的数据包上位机读取完成;为“0”分别对应表示其对应的数据包上位机还未读取;The definition of "host computer data packet reading completion flag": "1" corresponds to the completion of the reading of the corresponding data packet by the host computer; "0" corresponds to the corresponding data packet that the host computer has not read. ; 在PLC控制器中开辟存储空间,用于存放后续数据包的暂存数据包,暂存数据包内部的数据寄存器称为暂存寄存器,暂存数据包中的每个暂存寄存器与前述用于与上位机通讯的通讯数据包中对应的通讯寄存器的定义完全一致,与暂存数据包对应的前述用于与上位机通讯的数据包称为对应的数据包;与暂存寄存器对应的前述用于与上位机通讯的数据包中的寄存器称为对应的数据寄存器;Open up storage space in the PLC controller to store the temporary data packets of subsequent data packets. The data registers inside the temporary data packets are called temporary storage registers. The definition of the corresponding communication register in the communication data packet communicated with the host computer is exactly the same, and the aforementioned data packet corresponding to the temporary storage data packet for communication with the host computer is called the corresponding data packet; the aforementioned data packet corresponding to the temporary storage register is used. The register in the data packet communicated with the host computer is called the corresponding data register; PLC控制器初始化时,依次进行如下操作:所有后续数据包“上位机正在读取数据包标志位”置“0”,把所有后续数据包“PLC控制器正在存储数据包标志位”置“1”;把每个数据包对应的通讯获得的下位机的存储在寄存器中的数据,复制到每个数据包对应的数据寄存器中;所有后续数据包“PLC控制器数据包有变化数据标志位”置“1”;所有后续数据包“PLC控制器正在存储数据包标志位”置“0”;When the PLC controller is initialized, the following operations are performed in sequence: all subsequent data packets "the host computer is reading the data packet flag" is set to "0", and all subsequent data packets "the PLC controller is storing the data packet flag" is set to "1" ”; copy the data stored in the register of the lower computer obtained by the communication corresponding to each data packet to the data register corresponding to each data packet; all subsequent data packets “PLC controller data packets have changed data flags” Set to "1"; all subsequent data packets "PLC controller is storing data packet flag" set to "0"; PLC控制器开始正常处理流程时,先把第一个数据包对应的存储在寄存器中的通讯获得的下位机的存储在寄存器中的数据,复制到第一个数据包对应的数据寄存器中;再把后续数据包对应的存储在寄存器中的通讯获得的下位机的数据,复制到后续数据包对应的暂存数据包对应的数据寄存器中;When the PLC controller starts the normal processing process, it first copies the data stored in the register of the lower computer obtained by the communication stored in the register corresponding to the first data packet to the data register corresponding to the first data packet; Copy the data of the lower computer corresponding to the communication stored in the register corresponding to the subsequent data packet to the data register corresponding to the temporary data packet corresponding to the subsequent data packet; “PLC控制器当前数据包处理编号”变量置“2”,此“PLC控制器当前数据包处理编号”变量设置在PLC控制器中,用于表示PLC控制器程序当前正在处理的数据包的编号;The "PLC controller current data packet processing number" variable is set to "2", and this "PLC controller current data packet processing number" variable is set in the PLC controller to indicate the number of the data packet currently being processed by the PLC controller program. ; 下面进入后续数据包的处理流程:“PLC控制器当前数据包寄存器处理编号”变量置“1”,此“PLC控制器当前数据包寄存器处理编号”变量设置在PLC控制器中,用于表示PLC控制器程序当前正在处理的数据包中的寄存器的编号;Now enter the processing flow of subsequent data packets: "PLC controller current data packet register processing number" variable is set to "1", and this "PLC controller current data packet register processing number" variable is set in the PLC controller to indicate PLC the number of the register in the packet that the controller program is currently processing; PLC控制器依次对于后续数据包,分别按照纯模拟量数据包和非纯模拟量数据包分别逐个进行暂存数据包与对应的数据包有无变化数据的比较和处理;The PLC controller sequentially compares and processes the temporary data packets and the corresponding data packets with or without change data according to the pure analog data packets and the non-pure analog data packets one by one for the subsequent data packets; 当发现当前数据包有寄存器存在变化数据后,如果当前数据包“上位机正在读取数据包标志位”为“0”,并且“上位机数据包读取完成标志位”为“1”,则当前数据包“PLC控制器正在存储数据包标志位”置“1”,当前数据包“PLC控制器数据包有变化数据标志位”置“1”,当前数据包“上位机数据包读取完成标志位”置“0”,此数据包后续的数据不再比较,把当前暂存数据包中的所有数据,复制到当前数据包对应的数据寄存器,完成复制操作后,把当前数据包“PLC控制器正在存储数据包标志位”置“0”,把“PLC控制器当前数据包处理编号”加1,进入下一个循环,直到比较完成所有后续数据包的数据;如果前述当前数据包“上位机正在读取数据包标志位”为“1”,或者“上位机数据包读取完成标志位”为“0”,则放弃前述标志位设置和复制操作,也把“PLC控制器当前数据包处理编号”加1,进入下一个循环,直到比较完成所有后续数据包的数据;When it is found that there is changed data in the register in the current data packet, if the current data packet "the host computer is reading the data packet flag" is "0", and the "host computer data packet reading completion flag" is "1", then The current data packet "PLC controller is storing the data packet flag" is set to "1", the current data packet "PLC controller data packet has changed data flag" is set to "1", the current data packet "The host computer data packet read complete" The flag bit" is set to "0", the subsequent data of this data packet will not be compared, and all the data in the current temporary data packet will be copied to the data register corresponding to the current data packet. After the copy operation is completed, the current data packet "PLC" The controller is storing the data packet flag" and set it to "0", add 1 to the "current data packet processing number of the PLC controller", and enter the next cycle until the comparison of all subsequent data packets is completed; If the flag bit of the data packet is being read by the computer is "1", or the flag bit of "reading completion of the data packet of the upper computer" is "0", then the setting and copying operation of the aforementioned flag bit will be abandoned, and the "current data packet of the PLC controller" will be Add 1 to "processing number" and enter the next loop until the comparison of all subsequent data packets is completed; 当比较完成当前数据包,没有发现有变化的数据后,如果当前数据包“上位机正在读取数据包标志位”为“0”,并且当前数据包“上位机数据包读取完成标志位”为“1”,则把当前数据包“PLC控制器正在存储数据包标志位”置“1”,当前数据包“PLC控制器数据包有变化数据标志位”置“0”,当前数据包“上位机数据包读取完成标志位”置“0”;对于纯模拟量数据包,把当前暂存数据包中的所有数据复制到当前数据包对应的数据寄存器,对于非纯模拟量数据包,不进行此复制操作;再把当前数据包“PLC控制器正在存储数据包标志位”置“0”,把“PLC控制器当前数据包处理编号”加1,进入下一个循环,直到比较完成所有后续数据包的数据;When the current data packet is compared and no changed data is found, if the current data packet "host computer is reading the data packet flag" is "0", and the current data packet "host computer data packet reading completion flag" If it is "1", the current data packet "PLC controller is storing data packet flag" is set to "1", the current data packet "PLC controller data packet has changed data flag" is set to "0", the current data packet " The host computer data packet read completion flag is set to "0"; for pure analog data packets, copy all data in the current temporary data packet to the data register corresponding to the current data packet, for non-pure analog data packets, Do not perform this copy operation; then set the current data packet "PLC controller is storing the data packet flag" to "0", add 1 to the "PLC controller current data packet processing number", and enter the next cycle until the comparison is completed. data of subsequent packets; 前述对数据寄存器逐个比较,判断是否有变化,包括对纯模拟量数据包和非纯模拟量数据包的比较;The aforementioned data registers are compared one by one to determine whether there is a change, including the comparison of pure analog data packets and non-pure analog data packets; 前述对非纯模拟量的的比较,即对数字量或者表示数字的模拟量的比较是指,把暂存寄存器与对应的寄存器逐一比较,当不一致时,则认为当前的暂存寄存器是变化数据;The aforementioned comparison of non-pure analog quantities, that is, the comparison of digital quantities or analog quantities representing digital means, compares the temporary register with the corresponding register one by one, and when it is inconsistent, it is considered that the current temporary register is the change data. ; 前述对纯模拟量的比较是指,在PLC控制器中配置对应于纯模拟量的变量,用于设置各个纯模拟量对应的变化阖值和幅值阖值,对纯模拟量的暂存寄存器的数值与对应的幅值阖值逐一进行比较,当超过幅值阖值,则认为当前的暂存寄存器是变化数据;对纯模拟量的暂存寄存器的数值与对应的寄存器数值逐一进行相减比较,当超过变化阖值,则认为当前的暂存寄存器是变化数据;The aforementioned comparison of pure analog quantities refers to configuring variables corresponding to pure analog quantities in the PLC controller to set the change threshold and amplitude threshold corresponding to each pure analog quantity. Compare the value of the buffer with the corresponding amplitude threshold one by one. When the amplitude threshold is exceeded, the current temporary register is considered to be changed data; the value of the pure analog temporary register and the corresponding register value are subtracted one by one. Comparison, when the change threshold is exceeded, the current temporary register is considered to be the change data; 前述数据包“PLC控制器数据包有变化数据标志位”置“0”,意味着数据包没有变化数据,对于数字量数据包或者表示数字的模拟量数据包而言,是每个暂存寄存器与对应的寄存器数值相同,即没有变化;对于纯模拟量数据包而言,是每个暂存寄存器数值没有超过设定的变化阖值和幅值阖值;The aforementioned data packet "PLC controller data packet has changed data flag" is set to "0", which means that the data packet has no changed data. For digital data packets or analog data packets representing digital, it is each temporary register. It is the same as the corresponding register value, that is, there is no change; for pure analog data packets, the value of each temporary register does not exceed the set change threshold and amplitude threshold; 在上位机中,设置“上位机有变化数据包标志”变量,变量为“1”表示在上位机一轮数据包的处理中,存在“PLC控制器正在存储数据包标志位”为“0”,并且“PLC控制器数据包有变化数据标志位”为“1”的后续数据包,即上位机有需要处理的存在变化数据的后续数据包;In the host computer, set the variable of "the host computer has changed data packet flag", the variable is "1", it means that in one round of data packet processing by the host computer, there is "the PLC controller is storing the data packet flag" as "0" , and the subsequent data packets whose "PLC controller data packet has changed data flag bit" is "1", that is, the host computer has subsequent data packets with changed data that need to be processed; 在上位机中,设置各个后续数据包“上位机记录数据包读取有变化位”变量,变量为“1”表示此后续数据包有变化数据,用于标记有变化数据的后续数据包,用于上位机对有变化的数据包进行后续处理;当上位机处理完成此有变化的数据包后,把此数据包“上位机记录数据包读取有变化位”变量置“0”;In the host computer, set the variable of "the host computer records the data packet read with change bit" variable for each subsequent data packet. The variable is "1", indicating that the subsequent data packet has changed data, which is used to mark the subsequent data packets with changed data. Use The host computer performs subsequent processing on the changed data packet; when the host computer completes the processing of the changed data packet, set the variable of this data packet "the host computer records the data packet to read the changed bit" to "0"; 前述每轮指上位机依次处理一遍所有数据包;The aforementioned each round refers to the upper computer processing all the data packets in turn; 在上位机中,设置“上位机当前数据包处理编号”变量,用于记录当前上位机处理的数据包的编号;In the host computer, set the variable "current data packet processing number of the host computer" to record the number of the data packet processed by the current host computer; 上位机初始化时,把“循环读取一个数据包编号”变量置“2”;When the host computer is initialized, set the variable of "cyclically read a data packet number" to "2"; 上位机开始新的一轮处理数据时,先无条件读取第一个数据包数据,以便根据第一个数据包中的状态寄存器,依次对后续数据包分别进行处理操作;再把“上位机有变化数据包标志”置“0”、把所有后续数据包“上位机记录数据包读取有变化位”置“0”、“上位机当前数据包处理编号”置“2”;When the host computer starts a new round of data processing, it first unconditionally reads the data of the first data packet, so as to process the subsequent data packets in turn according to the status register in the first data packet; Change data packet flag" is set to "0", and all subsequent data packets are set to "0" for "the host computer records the data packet read change bit", and "the current data packet processing number of the host computer" is set to "2"; 上位机对于“PLC控制器正在存储数据包标志位”为“1”的后续数据包,不作处理,“上位机当前数据包处理编号”加1,去处理下一个数据包;The host computer does not process the subsequent data packets whose "PLC controller is storing the data packet flag" is "1", and adds 1 to the "current data packet processing number of the host computer" to process the next data packet; 上位机对于“PLC控制器正在存储数据包标志位”为“0”并且“PLC控制器数据包有变化数据标志位”为“0”的后续数据包,把当前数据包“上位机正在读取数据包标志位”置“1”,当前数据包“上位机数据包读取完成标志位”置“1”,当前数据包“上位机正在读取数据包标志位”置“0”,“上位机当前数据包处理编号”加1,去处理下一个数据包;For the subsequent data packets whose "PLC controller is storing data packet flag" is "0" and "PLC controller data packet has changed data flag" is "0", the host computer puts the current data packet "The host computer is reading "Data packet flag" is set to "1", the current data packet "host computer data packet read completion flag" is set to "1", the current data packet "host computer is reading the data packet flag" is set to "0", "host computer is reading the data packet flag" Add 1 to the current data packet processing number of the machine to process the next data packet; 上位机对于“PLC控制器正在存储数据包标志位”为“0”并且“PLC控制器数据包有变化数据标志位”为“1”的后续数据包,依次进行如下操作:当前数据包“上位机正在读取数据包标志位”置“1”,读取当前数据包所有数据,当前数据包“上位机数据包读取完成标志位”置“1”,当前数据包“上位机正在读取数据包标志位”置“0”,“上位机有变化数据包标志”置“1”,当前数据包“上位机记录数据包读取有变化位”置“1”,“上位机当前数据包处理编号”加1,再去处理下一个数据包;The host computer performs the following operations in sequence for the subsequent data packets whose "PLC controller is storing data packet flag" is "0" and "PLC controller data packet has changed data flag" is "1": the current data packet "host" The computer is reading the data packet flag" is set to "1", read all the data of the current data packet, the current data packet "host computer data packet read completion flag" is set to "1", the current data packet "host computer is reading "Data packet flag bit" is set to "0", "the host computer has changed data packet flag" is set to "1", the current data packet "the host computer records the data packet read change bit" is set to "1", "the host computer current data packet" is set to "1" "Processing number" plus 1, and then go to process the next data packet; 上位机完成了所有后续数据包中的上述三种数据包的读取处理后,当“上位机有变化数据包标志”为“1”时,进入下一轮处理数据包的循环;当“上位机有变化数据包标志”为“0”时,进行循环读取一个数据包;After the host computer completes the reading processing of the above three data packets in all subsequent data packets, when the "host computer has changed data packet flag" is "1", it enters the next round of processing data packets; When the machine has changed data packet flag" is "0", read a data packet cyclically; 前述循环读取一个数据包,步骤依次如下:把“循环读取一个数据包一轮计数”置“2”,把“循环读取一个数据包编号”变量的数值赋给“上位机当前数据包处理编号”变量;The aforementioned loop reads a data packet, and the steps are as follows: set the "loop read a data packet round count" to "2", and assign the value of the "loop read a data packet number" variable to the "current data packet of the upper computer" handle_number" variable; 当当前数据包“PLC控制器数据包有变化数据标志位”为“0”并且“PLC控制器正在存储数据包标志位”为“0”时,依次进行如下操作:把当前数据包“上位机正在读取数据包标志位”置“1”,读取当前数据包所有数据,当前数据包“上位机数据包读取完成标志位”置“1”,当前数据包“上位机正在读取数据包标志位”置“0”,“循环读取一个数据包编号”加1,当“循环读取一个数据包编号”大于数据包数量时,“循环读取一个数据包编号”置“2”,进入下一轮处理数据包的循环;当“循环读取一个数据包编号”不大于数据包数量时,进入下一轮处理数据包的循环;当当前数据包“PLC控制器数据包有变化数据标志位”为“1”或者“PLC控制器正在存储数据包标志位”为“1”时,依次进行如下操作:“上位机当前数据包处理编号”加1,当“上位机当前数据包处理编号”大于数据包数量时,把“上位机当前数据包处理编号”置“2”,把“循环读取一个数据包一轮计数”加1;当“上位机当前数据包处理编号”不大于数据包数量时,把“循环读取一个数据包一轮计数”加1;当“循环读取一个数据包一轮计数”不大于数据包数量时,对下一个数据包进行处理,直到“循环读取一个数据包一轮计数”大于数据包数量时,结束此次循环,进入下一轮处理数据包的循环;When the current data packet "PLC controller data packet has changed data flag" is "0" and "PLC controller is storing data packet flag" is "0", the following operations are performed in sequence: "Reading data packet flag" is set to "1", read all data of the current data packet, the current data packet "host computer data packet read completion flag" is set to "1", the current data packet "host computer is reading data" "Packet flag bit" is set to "0", "cyclically read a data packet number" is added 1, when "cyclically read a data packet number" is greater than the number of data packets, "cyclically read a data packet number" is set to "2" , enter the next round of data packet processing cycle; when the "cycle read a data packet number" is not greater than the number of data packets, enter the next round of data packet processing cycle; when the current data packet "PLC controller data packet has changed When the "Data flag bit" is "1" or the "PLC controller is storing the data packet flag bit" is "1", the following operations are performed in sequence: "The current data packet processing number of the upper computer" is incremented by 1. When the "processing number" is greater than the number of data packets, set the "current data packet processing number of the host computer" to "2", and add 1 to the "cycle reading a data packet round count"; when the "current data packet processing number of the host computer" is not When the number of data packets is greater than the number of data packets, add 1 to the "count of one round of reading a data packet in a loop"; when the "count of one round of reading a data packet in a loop" is not greater than the number of data packets, process the next data packet until " When the cycle count of reading a data packet in a loop is greater than the number of data packets, the cycle ends and the next cycle of processing data packets is entered; 前述在上位机中设置“循环读取一个数据包编号”变量,用于当上位机在处理完一轮数据包后,没有读到变化数据包时,则在每一轮中依次读取一个没有变化数据的数据包;前述循环读取,是指依次读取;The above-mentioned variable "cyclically read a data packet number" is set in the host computer, so that when the host computer does not read a changed data packet after processing a round of data packets, it will read one in each round in turn. Data packets of changing data; the aforementioned cyclic reading refers to sequential reading; 前述“循环读取一个数据包一轮计数”变量,在上位机中设置,用于保证循环读取所有后续数据包中的一个数据包。The aforesaid variable of "circularly read one data packet for one round" is set in the host computer to ensure that one data packet in all subsequent data packets is read cyclically. 2.如权利要求1所述的提高PLC控制器与上位机通讯传输和数据处理效率的方法,其特征在于,PLC控制器的第一个数据包中的数据寄存器存放变化频繁的纯模拟量数据,并且尽可能占满数据包。2. the method for improving PLC controller and host computer communication transmission and data processing efficiency as claimed in claim 1 is characterized in that, the data register in the first data packet of PLC controller stores the pure analog data that changes frequently , and fill as many packets as possible. 3.如权利要求1所述的提高PLC控制器与上位机通讯传输和数据处理效率的方法,其特征在于,PLC控制器的第一个数据包中设置的状态寄存器,根据被存储的数据容量,选择是两个寄存器、一个寄存器、或者三个寄存器,状态寄存器的放置位置在第一个数据包的开头或者第一个数据包的结尾。3. the method for improving PLC controller and host computer communication transmission and data processing efficiency as claimed in claim 1, it is characterized in that, the status register that is set in the first data packet of PLC controller, according to the stored data capacity , the choice is two registers, one register, or three registers, and the status register is placed at the beginning of the first packet or at the end of the first packet. 4.如权利要求1所述的提高PLC控制器与上位机通讯传输和数据处理效率的方法,其特征在于,PLC控制器的第一个数据包只作为数据状态包,即只存放状态寄存器,不存储数据,这样原来的第一个数据包的数据,存储到第二个数据包,数据包总数增加一个,前述后续数据包则包括原来的第一个数据包。4. the method for improving PLC controller and host computer communication transmission and data processing efficiency as claimed in claim 1, is characterized in that, the first data packet of PLC controller is only as data status packet, namely only stores status register, No data is stored, so that the data of the original first data packet is stored in the second data packet, and the total number of data packets is increased by one, and the aforementioned subsequent data packets include the original first data packet. 5.如权利要求1所述的提高PLC控制器与上位机通讯传输和数据处理效率的方法,其特征在于,PLC控制器用位表示的后续数据包状态,或者用寄存器来表示,即后续数据包的“PLC控制器数据包有变化数据标志位”、“PLC控制器正在存储数据包标志位”、“上位机正在读取数据包标志位”、“上位机数据包读取完成标志位”,或者用“PLC控制器数据包有变化数据标志寄存器”、“PLC控制器正在存储数据包标志寄存器”、“上位机正在读取数据包标志寄存器”、“上位机数据包读取完成标志寄存器”来表示。5. the method for improving PLC controller and upper computer communication transmission and data processing efficiency as claimed in claim 1, it is characterized in that, PLC controller uses the subsequent data packet state of bit representation, or represents with register, i.e. subsequent data packet "PLC controller data packet has changed data flag", "PLC controller is storing data packet flag", "host computer is reading data packet flag", "host computer data packet read completion flag", Or use "PLC controller data packet has changed data flag register", "PLC controller is storing data packet flag register", "host computer is reading data packet flag register", "host computer data packet read completion flag register" To represent. 6.如权利要求1所述的提高PLC控制器与上位机通讯传输和数据处理效率的方法,其特征在于,在PLC控制器中选择不设置当前数据包“上位机数据包读取完成标志位”,即PLC控制器不判断上位机读取完成,就更新存储,以提高PLC控制器存储速度。6. the method for improving PLC controller and host computer communication transmission and data processing efficiency as claimed in claim 1, is characterized in that, in PLC controller, choose not to set current data packet " host computer data packet read completion flag position ”, that is, the PLC controller will update the storage without judging that the reading of the upper computer is completed, so as to improve the storage speed of the PLC controller.
CN202010466104.7A 2020-05-28 2020-05-28 The method of improving the communication transmission and data processing efficiency between PLC controller and upper computer Active CN111722581B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010466104.7A CN111722581B (en) 2020-05-28 2020-05-28 The method of improving the communication transmission and data processing efficiency between PLC controller and upper computer

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010466104.7A CN111722581B (en) 2020-05-28 2020-05-28 The method of improving the communication transmission and data processing efficiency between PLC controller and upper computer

Publications (2)

Publication Number Publication Date
CN111722581A true CN111722581A (en) 2020-09-29
CN111722581B CN111722581B (en) 2021-10-22

Family

ID=72565252

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010466104.7A Active CN111722581B (en) 2020-05-28 2020-05-28 The method of improving the communication transmission and data processing efficiency between PLC controller and upper computer

Country Status (1)

Country Link
CN (1) CN111722581B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113325798A (en) * 2021-07-08 2021-08-31 宜科(天津)电子有限公司 Sensor data processing system

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1133534A (en) * 1994-03-24 1996-10-16 Dva公司 Detector for initial code
US20020188663A1 (en) * 2001-04-24 2002-12-12 Islam Farhad Fuad Multi-agent system for digital home/office
US20040223010A1 (en) * 2002-12-02 2004-11-11 Plunkett Richard Thomas Data rate equalisation to account for relatively different printhead widths
CN1781069A (en) * 2003-05-02 2006-05-31 先进微装置公司 Computer system including bus bridge for connection to secure service processor
CN1973279A (en) * 2004-06-22 2007-05-30 横河电机株式会社 Mutual access method of data and mutual access system of data
US20150293796A1 (en) * 2012-12-19 2015-10-15 Schneider Electric Industries Sas Programmable logic controller and event-driven programming method thereof
CN109960242A (en) * 2017-12-25 2019-07-02 欧姆龙株式会社 Control system and control device

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1133534A (en) * 1994-03-24 1996-10-16 Dva公司 Detector for initial code
US20020188663A1 (en) * 2001-04-24 2002-12-12 Islam Farhad Fuad Multi-agent system for digital home/office
US20040223010A1 (en) * 2002-12-02 2004-11-11 Plunkett Richard Thomas Data rate equalisation to account for relatively different printhead widths
CN1781069A (en) * 2003-05-02 2006-05-31 先进微装置公司 Computer system including bus bridge for connection to secure service processor
CN1973279A (en) * 2004-06-22 2007-05-30 横河电机株式会社 Mutual access method of data and mutual access system of data
US20150293796A1 (en) * 2012-12-19 2015-10-15 Schneider Electric Industries Sas Programmable logic controller and event-driven programming method thereof
CN109960242A (en) * 2017-12-25 2019-07-02 欧姆龙株式会社 Control system and control device

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
ALAN JAY SMITH: "《Optimization of I/O systems by cache disks and file migration: A summary》", 《PERFORMANCE EVALUATION》 *
QUAN BAI: "《Design of Force Loading Monitor and Control System Based on LabVIEW》", 《2013 FOURTH INTERNATIONAL CONFERENCE ON DIGITAL MANUFACTURING & AUTOMATION》 *
焦振宇: "《S7-200PLC模拟量采集的经济实现》", 《测控技术》 *
缪泽宇: "《基于 PLC 的多工位刷光线加工机床控制系统设计》", 《组合机床与自动化加工技术》 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113325798A (en) * 2021-07-08 2021-08-31 宜科(天津)电子有限公司 Sensor data processing system

Also Published As

Publication number Publication date
CN111722581B (en) 2021-10-22

Similar Documents

Publication Publication Date Title
CN102866971A (en) Data transmission device, system and method
CN105353715A (en) Realization method of logic control of VB/VC (Microsoft Visual Basic 6.0/Microsoft Visual C++) and PLC (Programmable Logic Controller) on the basis of serial communication
CN109511275A (en) A kind of numerical control system and its data transmission method based on field programmable gate array
CN111045703A (en) A method and system for upgrading battery management unit software
CN109246210A (en) Internet of Things communication means and device
CN111722581A (en) The method of improving the communication transmission and data processing efficiency between PLC controller and upper computer
CN103545933B (en) I0 interface communication method in intelligent substation on-line monitoring system station
CN111665778B (en) A method for fast communication transmission and data processing between PLC controller and host computer
CN106951352A (en) A kind of server log memory management method
WO2021207972A1 (en) Data transmission method, data transmission device, electronic device and storage medium
CN200997073Y (en) Universal digital-controlled system based on digital ring bus
JPH0366879B2 (en)
CN102681970B (en) Signal processor and configuration method thereof
CN213122961U (en) Industrial control system and electronic equipment
CN113849355A (en) I2C rate adaptive adjustment method, system, terminal and storage medium
CN112445508A (en) ARM application program online upgrading method based on CAN bus
CN105701060A (en) FPGA-based high-speed real-time data recording system
CN115473761B (en) Communication method, system, equipment and medium of CAN bus based on DCS system
WO2022142173A1 (en) Data check method and related device
CN116206659B (en) OTP memory
CN211579696U (en) Protection measurement and control device
CN113934671B (en) Interface control chip and network equipment
CN115203116B (en) AXI bus transmission method, system and chip
Youyu et al. Design and Implementation of Bootloader Based on CCP Protocol
CN115809124A (en) Method, device and home appliance for task scheduling under limited resources

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right

Effective date of registration: 20221129

Address after: No. 19, Jiangning District, Jiangning District, Nanjing, Jiangsu

Patentee after: NARI TECHNOLOGY Co.,Ltd.

Patentee after: NARI Rail Transit Technology Co.,Ltd.

Address before: No. 19, Jiangning District, Jiangning District, Nanjing, Jiangsu

Patentee before: NARI TECHNOLOGY Co.,Ltd.

TR01 Transfer of patent right
CP03 Change of name, title or address

Address after: No. 19, Jiangning District, Jiangning District, Nanjing, Jiangsu

Patentee after: NARI TECHNOLOGY Co.,Ltd.

Country or region after: China

Patentee after: Nanjing Nanrui Industrial Control Technology Co.,Ltd.

Address before: No. 19, Jiangning District, Jiangning District, Nanjing, Jiangsu

Patentee before: NARI TECHNOLOGY Co.,Ltd.

Country or region before: China

Patentee before: NARI Rail Transit Technology Co.,Ltd.

CP03 Change of name, title or address