WO2022082950A1 - 一种提升设备串口通信效率的方法及终端 - Google Patents

一种提升设备串口通信效率的方法及终端 Download PDF

Info

Publication number
WO2022082950A1
WO2022082950A1 PCT/CN2020/134450 CN2020134450W WO2022082950A1 WO 2022082950 A1 WO2022082950 A1 WO 2022082950A1 CN 2020134450 W CN2020134450 W CN 2020134450W WO 2022082950 A1 WO2022082950 A1 WO 2022082950A1
Authority
WO
WIPO (PCT)
Prior art keywords
communication
continuous length
duration
total duration
data
Prior art date
Application number
PCT/CN2020/134450
Other languages
English (en)
French (fr)
Inventor
刘衍青
欧新木
黄继波
Original Assignee
福州富昌维控电子科技有限公司
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 福州富昌维控电子科技有限公司 filed Critical 福州富昌维控电子科技有限公司
Publication of WO2022082950A1 publication Critical patent/WO2022082950A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/42Bus transfer protocol, e.g. handshake; Synchronisation
    • G06F13/4282Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/40Bus structure
    • G06F13/4004Coupling between buses
    • G06F13/4027Coupling between buses using bus bridges
    • G06F13/404Coupling between buses using bus bridges with address mapping

Definitions

  • the invention relates to the technical field of computer communication, in particular to a method and a terminal for improving the efficiency of serial communication of equipment.
  • Serial communication is a communication method in which the serial port sends and receives byte data bit by bit.
  • Serial ports are divided into RS-485, RS-422 and RS-232 according to electrical standards and protocols.
  • Devices that use serial communication are very common, such as: PLC, microcontroller, inverter, sensor, instrument, printer and so on.
  • Serial communication has the advantages of long communication distance, strong anti-interference ability and low cost, so it is widely used.
  • monitoring devices with serial communication function are often connected to some monitoring devices.
  • This type of monitoring device is connected to the serial device (monitored device) through a serial cable, and uses a designated serial port protocol to communicate.
  • the monitoring device hopes to continuously and quickly obtain the specified data of the monitored device, so the communication speed is extremely important.
  • the classification of serial communication includes classification according to data transmission direction and communication mode, which are as follows:
  • Half Duplex Allows data to be transmitted in both directions. However, at a certain point, data is only allowed to travel in one direction, and it's actually a simplex communication that switches directions; it doesn't require separate receivers and senders, the two can be combined to use a single port.
  • Full Duplex Allows data to be transmitted in both directions at the same time. Therefore, full-duplex communication is a combination of two simplex communication modes, requiring independent receivers and transmitters.
  • Synchronous communication with clock synchronization signal transmission
  • Synchronous communication uses large frames to transmit data.
  • the commonly used HDLC (High-level Data Link Control) frame format each frame has a 1-byte start flag bit, a 2-byte transceiver address bit, and a 2-byte communication Status bits, data bits for multiple characters, and 2-byte cyclic redundancy check bits.
  • Asynchronous communication adopts small frame transmission, and there are 10 to 12 binary data bits in one frame.
  • Each frame consists of a start bit, 7 to 8 data bits, a parity bit (or none) and a stop bit (one bit or two bits).
  • the pause time of two adjacent characters of a group of data to be transmitted is inconsistent.
  • serial devices are often general-purpose products that provide more addresses (data)
  • monitoring devices often only need some of the addresses used. Therefore, it is not necessary to read all the addresses of the serial device.
  • the addresses used by serial devices are often not necessarily completely continuous, and there will be gaps due to the actual use.
  • the monitoring method of the address is carried out by reading the serial port data. The details are as follows: specify the serial port, specify the address type t, the address starting label n and the address length len, and read the address data corresponding to the slave address n ⁇ n+len .
  • the total length of the address of register type 4 can reach 100,000 or more (different devices may be different). If the 13 addresses with the labels: 0, 1, 3, 9, 20, 30, 99, 105, 200, 210, 220, 3000, 3099 are used, then:
  • the effective data is 4.2%, the efficiency is very low, and it takes a certain amount of time to read each byte of data, which is a huge waste of time.
  • the valid data can theoretically reach 100%, but in fact, in addition to the time for reading and writing valid data, the time for each serial communication interaction is included in each frame of data: Start bit, check bit and stop bit, as well as device response time, and additional time overhead such as program logic processing time, these overheads are not small, sometimes even larger, so the more the number of interactions, the extra time The more overhead, the less efficient the communication.
  • the technical problem to be solved by the present invention is to provide a method and a terminal for improving the communication efficiency of the serial port of the device, so as to improve the communication efficiency of the serial port of the device.
  • the technical scheme adopted in the present invention is:
  • a method for improving serial communication efficiency of a device comprising:
  • the beneficial effect of the present invention is that: the present invention collects the communication parameters of the device and calculates the continuous length of the target address that the device can integrate, so as to obtain the optimal address group with the shortest total duration of the requested communication, as the optimal integration scheme, the whole process Executed by a computer, it does not require users to set according to experience, and can effectively improve the communication efficiency of the serial port of the device.
  • FIG. 1 is a flowchart of a method for improving serial communication efficiency of a device according to an embodiment of the present invention
  • FIG. 2 is a specific flowchart of a method for improving the efficiency of serial communication of a device according to an embodiment of the present invention
  • FIG. 3 is a structural diagram of a terminal for improving serial communication efficiency of a device according to an embodiment of the present invention.
  • a terminal for improving the efficiency of serial communication of equipment 2. Processor; 3. Memory.
  • a method for improving the communication efficiency of a serial port of a device includes:
  • the beneficial effect of the present invention is: by collecting the communication parameters of the device, the continuous length of the target addresses that can be integrated by the device is calculated, so as to obtain the optimal address group with the shortest total duration of the requested communication as the optimal integration scheme , the whole process is carried out by the computer, does not require users to set according to experience, and can effectively improve the communication efficiency of the serial port of the device.
  • the preset communication parameters specifically include baud rate RB, communication start time t 1 , communication end time t 2 , and the number of bits m and data bits of stop bit + start bit + check bit of each character. number of digits n.
  • step S1 it also includes:
  • n bits are fixed values. Even if only 1 bit of data needs to be read, there are n bits of data bits in one frame read. Therefore, it cannot be said that if you want to read 1 bit of data, only 1 bit is passed, but n bits are passed.
  • a padding operation needs to be performed before the subsequent calculation to improve the accuracy of the subsequent calculation.
  • step S2 is specifically:
  • the first data amount b is calculated, and the first data amount
  • time t 4 Tt 3 for non-transmission of the final target data in one communication, that is to say, in addition to the time for transmitting the final data in each communication, an additional time of t 4 is required, which is irrespective of the transmission time. How much data is needed.
  • t 4 can be considered as a fixed value, and the size of t 4 , as well as RB, m, and n are known, then the amount of data b that can be transmitted by t 4 can be calculated.
  • step S3 is specifically:
  • the target address data set to be read is ⁇ a i ⁇ , where i ⁇ 1.
  • the final data is obtained after p times of interaction. Then: the total time T is always :
  • the first data amount b that is, the amount of data that can be transmitted in one communication without the time used to transmit the final target data. Then, it can also be said that if the interval between the two addresses an and a n +1 is greater than b, Then if these two addresses are integrated into one group, the time wasted in the interval between them is greater than the time required for dividing into two groups.
  • b is the maximum interval. That is, the maximum interval length.
  • the distance between two adjacent addresses cannot be greater than b.
  • the length of each group of address integration groups obtained by integration at an interval of b is relatively long, and the number of groups p is small, but the total length of all integration groups l 1 +l 2 +...+l p is relatively large. Therefore, it is not necessarily the optimal solution. Therefore, it has to gradually decrease from b to reintegrate. If the total duration is found to remain unchanged or become smaller, continue to reduce the interval length and reintegrate again until the total duration increases or b ⁇ 0, then take the minimum total duration integration plan. This solution is the optimal solution.
  • the present invention also provides a terminal for improving the efficiency of serial communication of equipment, including a processor, a memory and a computer program stored in the memory and running on the processor, the processor executing the computer program
  • a terminal for improving the efficiency of serial communication of equipment, including a processor, a memory and a computer program stored in the memory and running on the processor, the processor executing the computer program
  • the beneficial effect of the present invention is: by collecting the communication parameters of the device, the continuous length of the target addresses that can be integrated by the device is calculated, so as to obtain the optimal address group with the shortest total duration of the requested communication as the optimal integration scheme , the whole process is carried out by the computer, does not require users to set according to experience, and can effectively improve the communication efficiency of the serial port of the device.
  • the preset communication parameters specifically include baud rate RB, communication start time t 1 , communication end time t 2 , and the number of bits m and data bits of stop bit + start bit + check bit of each character. number of digits n.
  • step S1 it also includes:
  • n bits are fixed values. Even if only 1 bit of data needs to be read, there are n bits of data bits in one frame read. Therefore, it cannot be said that if you want to read 1 bit of data, only 1 bit is passed, but n bits are passed.
  • a padding operation needs to be performed before the subsequent calculation to improve the accuracy of the subsequent calculation.
  • step S2 is specifically:
  • the first data amount b is calculated, and the first data amount
  • the time t 4 Tt 3 for non-transmission of the final target data in one communication, that is to say, in addition to the time for transmitting the final data in each communication, an additional time of t 4 is required, which is irrespective of the transmission time. How much data is needed.
  • t 4 can be considered as a fixed value, and the size of t 4 , as well as RB, m, and n are known, then the amount of data b that can be transmitted by t 4 can be calculated.
  • the step S3 is specifically:
  • the target address data set to be read is ⁇ a i ⁇ , where i ⁇ 1.
  • the final data is obtained after p times of interaction. Then: the total time T is always :
  • the first data amount b that is, the amount of data that can be transmitted in one communication without the time used to transmit the final target data. Then, it can also be said that if the interval between the two addresses an and a n +1 is greater than b, Then if these two addresses are integrated into one group, the time wasted in the interval between them is greater than the time required for dividing into two groups.
  • b is the maximum interval. That is, the maximum interval length.
  • the distance between two adjacent addresses cannot be greater than b.
  • the length of each group of address integration groups obtained by integration at an interval of b is relatively long, and the number of groups p is small, but the total length of all integration groups l 1 +l 2 +...+l p is relatively large. Therefore, it is not necessarily the optimal solution. Therefore, it has to gradually decrease from b to reintegrate. If it is found that the total duration remains the same or becomes smaller, continue to reduce the interval length and reintegrate again until the total duration increases or b ⁇ 0, then take the minimum total duration integration plan. This solution is the optimal solution.
  • the first embodiment of the present invention is:
  • monitoring devices such as industrial touch screens
  • the monitoring device and the control device will collect data and control the device through serial communication.
  • these devices take the most common PLC as an example.
  • the operator controls the PLC connected to it through the touch screen, and controls the I/O points of the PLC, thereby realizing the control of the actual equipment.
  • the touch screen can also collect the data read back by the PLC from sensors and other devices, and present it to the user for viewing or recording.
  • the initial address integration group is obtained, so that the device can enter a normal and stable working state
  • the preset communication parameters specifically include the baud rate RB, the communication start time t 1 , the communication end time t 2 , the number m of stop bits + start bits + parity bits of each character, and data The number of bits n.
  • step S2 is specifically:
  • the first data amount b is calculated, and the first data amount
  • the target address data set to be read is ⁇ a i ⁇ , where i ⁇ 1. Assuming that this set of addresses is integrated into p groups, the final data is obtained after p times of interaction. Then: the total time T is always :
  • step S3 it can be seen from the formula that the finer the split, the smaller the l 1 +l 2 +...+l p , but the larger the p; the coarser the split, the l 1 +l 2 +...+l p is larger, but p is smaller. Therefore, it is necessary to take a suitable set of values so that the total time T is always minimized. Therefore, the operation of step S3 needs to be performed.
  • the step S3 is specifically:
  • the second embodiment of the present invention is:
  • a terminal 1 for improving the efficiency of serial communication of equipment comprising a processor 2, a memory 3 and a computer program stored on the memory 3 and running on the processor 2, the processor 2 realizes the above one when executing the computer program.
  • a method for improving the serial communication efficiency of a device comprising a processor 2, a memory 3 and a computer program stored on the memory 3 and running on the processor 2, the processor 2 realizes the above one when executing the computer program.
  • the present invention provides a method and terminal for improving the communication efficiency of a serial port of a device.
  • the continuous length of the target address that can be integrated by the device is calculated, so as to obtain the optimal request with the shortest total duration of communication.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Communication Control (AREA)

Abstract

本发明公开了一种提升设备串口通信效率的方法,包括:按照初始连续长度进行一次请求通信,以采集预设通讯参数;根据所述预设通讯参数,计算一次通信中非传输最终目标数据所用时长所能传输的第一数据量;根据所述第一数据量缩小所述初始连续长度,得到请求通信的总时长最短的最优地址组,按照所述最优地址组进行串口通信;本发明通过采集设备的通讯参数,计算设备可以整合的目标地址的连续长度,以得到请求通信的总时长最短的最优地址组,作为最优的整合方案,整个过程由计算机执行,不需要使用者根据经验进行设置,且能够有效地提升设备串口的通信效率。

Description

一种提升设备串口通信效率的方法及终端 技术领域
本发明涉及计算机通信技术领域,特别涉及一种提升设备串口通信效率的方法及终端。
背景技术
串口通信就是串口按位发送和接收字节数据的通信方式。串口按电气标准及协议划分为:RS-485、RS-422和RS-232。采用串口通信的设备非常普遍,如:PLC、单片机、变频器、传感器、仪表、打印机等等。串口通信具有通讯距离远、抗干扰能力强和成本低这几个优点,因此被广泛使用。
与这些具备串口通信功能的设备相连的往往是一些监控设备,这类型监控设备通过串口线与串口设备(被监控设备)进行连接,并采用指定的串口协议进行通信。在很多的使用场景中,监控设备希望能不断地并快速获取被监控设备的指定数据,所以通讯速度就显得异常重要了。
其中,关于串口通信的分类包括按数据传输方向分和按通信方式分,其具体如下:
1.按数据传输方向分:
单工:数据传输只支持数据在一个方向上传输;
半双工:允许数据在两个方向上传输。但是,在某一时刻,只允许数据在一个方向上传输,它实际上是一种切换方向的单工通信;它不需要独立的接收端和发送端,两者可以合并一起使用一个端口。
全双工:允许数据同时在两个方向上传输。因此,全双工通信是两个单工通信方式的结合,需要独立的接收端和发送端。
2.按通信方式分:
a.同步通信:带时钟同步信号传输
在串行通信中,数据是以帧为单位传输的,帧有大帧和小帧之分,小帧包含一个字符,大帧含多个字符。
同步通信采用大帧传输数据。同步通信的多种格式中,常用的为HDLC(高级数据链路控制)帧格式,每一帧中有1字节的起始标志位、2字节的收发方地址位、2字节的通信状态位、多个字符的数据位和2字节的循环冗余校验位。
b.异步通信:不带时钟同步信号传输
异步通信采用小帧传输,一帧中有10~12个二进制数据位。每一帧有一个起始位、7~8个数据位、1个奇偶校验位(可以没有)和停止位(一位或两位)组成。被传送的一组数据相邻两个字符停顿时间不一致。
因为串口设备(被监控设备)往往是一些通用产品,提供的地址(数据)比较多,而监控设备往往只需要部分使用到的地址。所以并不需要将串口设备的地址全部读取。但是,串口设备使用的地址往往也不一定是完全连续的,会受实际使用的影响而产生间隔。而地址的监控方式是以读串口数据的方式进行的,具体如下:指定串口,给定地址类型t、地址起始标号n和地址长度len,读取从地址n~n+len对应的地址数据。
当前常见的方法是:
a.约定或设定地址连读长度(最大可连续读多长)MaxLen。
b.根据MaxLen进行地址的整合分组,得到多个整合组。
c.一个一个整合组进行地址的读取。
以非常常见的Modbus协议为例。寄存器类型为4的地址总长度可以达到10万个甚至更多(不同的设备可能不一样)。若使用了其中标号为:0、1、3、9、20、30、99、105、200、210、220、3000、3099这13个地址,那么:
a.Modbus的连读长度MaxLen往往设为100:
b.根据MaxLen进行地址整合,得到地址整合组,区间分别为:[0,99]、[105,200]、[210,220]、[3000、3099],这4组。
c.按整合组进行地址数据的读取。
以所举例子进行分析,所需要监控的地址总共为13个地址。而4个整合组的区间总长度TotalLen=100+96+11+100=307。也就是说,为了获取这13个地址的数据,实际上监控设备读取了307个地址的数据。有效数据为4.2%,效率是非常低的,读取每一个字节的数据都需要一定的时间,这是非常巨大的时间浪 费。
当然,按使用的地址一个一个读取,有效数据在理论上可以达到100%,但实际上,每一次串口通讯交互的时间除了读写有效数据的时间外,还有每帧数据中附带的:起始位、校验位和停止位,还有设备响应时间,还有程序逻辑处理时间等额外的时间开销,这些开销并不小,有时甚至会比较大,所以交互次数越多,这种额外开销就越多,通信效率也就更低。
这些额外的开销即使用相同的通信协议在不同的设备上也可能不一样,这也正是串口通信难以实现高效通信的原因之一,使用者往往会按具体设备、按经验设定一个连读长度,以得到一个相对较优的效率,无法准确地设置最优的方案。
发明内容
本发明所要解决的技术问题是:提供一种提升设备串口通信效率的方法及终端,以提高设备串口的通信效率。
为了解决上述技术问题,本发明采用的技术方案为:
一种提升设备串口通信效率的方法,包括:
S1、按照初始连续长度进行一次请求通信,以采集预设通讯参数;
S2、根据所述预设通讯参数,计算一次通信中非传输最终目标数据所用时长所能传输的第一数据量;
S3、根据所述第一数据量缩小所述初始连续长度,得到请求通信的总时长最短的最优地址组,按照所述最优地址组进行串口通信。
本发明的有益效果在于:本发明通过采集设备的通讯参数,计算设备可以整合的目标地址的连续长度,以得到请求通信的总时长最短的最优地址组,作为最优的整合方案,整个过程由计算机执行,不需要使用者根据经验进行设置,且能够有效地提升设备串口的通信效率。
附图说明
图1为本发明实施例的一种提升设备串口通信效率的方法的流程图;
图2为本发明实施例的一种提升设备串口通信效率的方法的具体流程图;
图3为本发明实施例的一种提升设备串口通信效率的终端的结构图。
标号说明:
1、一种提升设备串口通信效率的终端;2、处理器;3、存储器。
具体实施方式
为详细说明本发明的技术内容、所实现目的及效果,以下结合实施方式并配合附图予以说明。
请参照图1和图2,一种提升设备串口通信效率的方法,包括:
S1、按照初始连续长度进行一次请求通信,以采集预设通讯参数;
S2、根据所述预设通讯参数,计算一次通信中非传输最终目标数据所用时长所能传输的第一数据量;
S3、根据所述第一数据量缩小所述初始连续长度,得到请求通信的总时长最短的最优地址组,按照所述最优地址组进行串口通信。
从上述描述可知,本发明的有益效果在于:通过采集设备的通讯参数,计算设备可以整合的目标地址的连续长度,以得到请求通信的总时长最短的最优地址组,作为最优的整合方案,整个过程由计算机执行,不需要使用者根据经验进行设置,且能够有效地提升设备串口的通信效率。
进一步的,所述预设通讯参数具体包括波特率RB、通信起始时间t 1、通信结束时间t 2以及每个字符的停止位+起始位+校验位的位数m和数据位位数n。
由上述描述可知,将以上数据作为通讯参数,便于后续的计算,且准确度较高。
进一步的,所述步骤S1和步骤S2之间,还包括:
S11、对目标数据长度l进行一次补齐运算,将补齐运算后的结果作为新的目标数据长度l,补齐运算:
Figure PCTCN2020134450-appb-000001
由上述描述可知,需要对目标数据长度进行一次补齐运算
Figure PCTCN2020134450-appb-000002
也就是
Figure PCTCN2020134450-appb-000003
先取整,然后再与n相乘。接收和发送的数据都是以字符或者说帧 为单位,每一帧都包含:起始位+数据位+校验位+停止位。其中数据位n位是固定值。即使只需要读取1位的数据,读取的一帧中,数据位也有n位。所以不能说想读1位数据就只传1位,而是会传n位。而计算时间的时候,也需要计算n位数据的传输时间。因此,在后续计算前需要进行一次补齐运算,提高后续计算的精确度。
进一步的,所述步骤S2具体为:
根据所述预设通讯参数,计算一次通信的总时长T和一次通信中传输最终目标数据所用时长t 3,所述总时长T=t 2-t 1,所述传输最终目标数据所用时长
Figure PCTCN2020134450-appb-000004
根据一次通信的总时长T和一次通信中传输最终目标数据所用时长t 3,计算一次通信中非传输最终目标数据所用时长t 4,所述非传输最终目标数据所用时长t 4=T-t 3
根据一次通信中所述非传输最终目标数据所用时长t 4,计算第一数据量b,所述第一数据量
Figure PCTCN2020134450-appb-000005
由上述描述可知,一次通信中非传输最终目标数据所用时长t 4=T-t 3,也就是说,每次通信,除了传输最终数据的时间外,需要额外花销t 4的时间,这是不管传多少数据都需要的。在固定的整套设备环境下,可认为t 4是固定值,已知t 4的大小,以及RB、m、n,那么就可以计算出t 4可以传输的数据量b。
进一步的,所述步骤S3具体为:
S31、以所述第一数据量为起始,将所述第一数据量作为第一连续长度,根据所述第一连续长度重新整合所有目标地址,得到第一地址组,并计算按照所述第一地址组进行一次请求通信的总时长,作为第一通信总时长;
S32、按照预设缩小量缩小所述第一连续长度,并将缩小后的所述第一连续长度作为第二连续长度,重新整合所有目标地址,得到第二地址组,并计算按照所述第二地址组进行一次请求通信的总时长,作为第二通信总时长;
S33、将所述第二通信总时长与所述第一通信总时长进行对比,若所述第二通信总时长大于所述第一通信总时长或所述第二连续长度等于0,则以所述第一连续长度作为最优连续长度,根据所述最优连续长度整合所有目标地址,得到最优地址组,否则将所述第二连续长度作为新的所述第一连续长度,将所述第二通信总时长作为新的第一通信总时长,并返回步骤S32;
S34、按照所述最优地址组进行串口通信。
由上述描述可知,假定需要读取目标地址数据集合为{a i},其中i≥1。假设此集合地址被整合成了p组,进行了p次的交互得到最终数据。那么:总时间T 为:
Figure PCTCN2020134450-appb-000006
由算式可以看出,拆分得越细则l 1+l 2+...+l p越小,但p越大;拆分得越粗则l 1+l 2+...+l p越大,但p越小。所以需要取一组合适的值,使得总时间T 最小。以上我们计算出了第一数据量b即一次通信中非传输最终目标数据所用时长所能传输的数据量,那么,也可以说,如果两个地址a n与a n+1的间隔大于b,那么这两个地址要是整合到一组的话,它们之间的间隔所浪费的时间大于分成2组所需要的时间。换句话说,b是最大间隔。也就是最大间隔长度。相邻两个地址间的距离不能大于b。以b为间隔进行整合所得到的地址整合组每组长度是比较长的,组数p少,但所有整合组的总长度l 1+l 2+...+l p比较大。所以,并不一定是最优解。所以得从b开始逐渐减小,去重新整合,若发现总时长不变或变小,则继续减小间隔长度,再次重新整合,直到总时长增大或b≤0,则取最小总时长的整合方案。此方案即为最优方案。
如图3所示,本发明还提供一种提升设备串口通信效率的终端,包括处理器、存储器及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现以下步骤:
S1、按照初始连续长度进行一次请求通信,以采集预设通讯参数;
S2、根据所述预设通讯参数,计算一次通信中非传输最终目标数据所用时长所能传输的第一数据量;
S3、根据所述第一数据量缩小所述初始连续长度,得到请求通信的总时长最短的最优地址组,按照所述最优地址组进行串口通信。
从上述描述可知,本发明的有益效果在于:通过采集设备的通讯参数,计算设备可以整合的目标地址的连续长度,以得到请求通信的总时长最短的最优地址组,作为最优的整合方案,整个过程由计算机执行,不需要使用者根据经验进行设置,且能够有效地提升设备串口的通信效率。
进一步的,所述预设通讯参数具体包括波特率RB、通信起始时间t 1、通信结束时间t 2以及每个字符的停止位+起始位+校验位的位数m和数据位位数n。
由上述描述可知,将以上数据作为通讯参数,便于后续的计算,且准确度较高。
进一步的,所述步骤S1和步骤S2之间,还包括:
S11、对目标数据长度l进行一次补齐运算,将补齐运算后的结果作为新的目标数据长度l,补齐运算:
Figure PCTCN2020134450-appb-000007
由上述描述可知,需要对目标数据长度进行一次补齐运算
Figure PCTCN2020134450-appb-000008
也就是
Figure PCTCN2020134450-appb-000009
先取整,然后再与n相乘。接收和发送的数据都是以字符或者说帧为单位,每一帧都包含:起始位+数据位+校验位+停止位。其中数据位n位是固定值。即使只需要读取1位的数据,读取的一帧中,数据位也有n位。所以不能说想读1位数据就只传1位,而是会传n位。而计算时间的时候,也需要计算n位数据的传输时间。因此,在后续计算前需要进行一次补齐运算,提高后续计算的精确度。
进一步的,所述步骤S2具体为:
根据所述预设通讯参数,计算一次通信的总时长T和一次通信中传输最终目标数据所用时长t 3,所述总时长T=t 2-t 1,所述传输最终目标数据所用时长
Figure PCTCN2020134450-appb-000010
根据一次通信的总时长T和一次通信中传输最终目标数据所用时长t 3,计算一次通信中非传输最终目标数据所用时长t 4,所述非传输最终目标数据所用时长t 4=T-t 3
根据一次通信中所述非传输最终目标数据所用时长t 4,计算第一数据量b,所述第一数据量
Figure PCTCN2020134450-appb-000011
由上述描述可知,一次通信中非传输最终目标数据所用时长t 4=T-t 3,也就是说,每次通信,除了传输最终数据的时间外,需要额外花销t 4的时间,这是不管传多少数据都需要的。在固定的整套设备环境下,可认为t 4是固定值,已知t 4的大小,以及RB、m、n,那么就可以计算出t 4可以传输的数据量b。进一步的,所述步骤S3具体为:
S31、以所述第一数据量为起始,将所述第一数据量作为第一连续长度,根据所述第一连续长度重新整合所有目标地址,得到第一地址组,并计算按照所述第一地址组进行一次请求通信的总时长,作为第一通信总时长;
S32、按照预设缩小量缩小所述第一连续长度,并将缩小后的所述第一连续长度作为第二连续长度,重新整合所有目标地址,得到第二地址组,并计算按照所述第二地址组进行一次请求通信的总时长,作为第二通信总时长;
S33、将所述第二通信总时长与所述第一通信总时长进行对比,若所述第二通信总时长大于所述第一通信总时长或所述第二连续长度等于0,则以所述第一连续长度作为最优连续长度,根据所述最优连续长度整合所有目标地址,得到最优地址组,否则将所述第二连续长度作为新的所述第一连续长度,将所述第二通信总时长作为新的第一通信总时长,并返回步骤S32;
S34、按照所述最优地址组进行串口通信。
由上述描述可知,假定需要读取目标地址数据集合为{a i},其中i≥1。假设 此集合地址被整合成了p组,进行了p次的交互得到最终数据。那么:总时间T 为:
Figure PCTCN2020134450-appb-000012
由算式可以看出,拆分得越细则l 1+l 2+...+l p越小,但p越大;拆分得越粗则l 1+l 2+...+l p越大,但p越小。所以需要取一组合适的值,使得总时间T 最小。以上我们计算出了第一数据量b即一次通信中非传输最终目标数据所用时长所能传输的数据量,那么,也可以说,如果两个地址a n与a n+1的间隔大于b,那么这两个地址要是整合到一组的话,它们之间的间隔所浪费的时间大于分成2组所需要的时间。换句话说,b是最大间隔。也就是最大间隔长度。相邻两个地址间的距离不能大于b。以b为间隔进行整合所得到的地址整合组每组长度是比较长的,组数p少,但所有整合组的总长度l 1+l 2+...+l p比较大。所以,并不一定是最优解。所以得从b开始逐渐减小,去重新整合,若发现总时长不变或变小,则继续减小间隔长度,再次重新整合,直到总时长增大或b≤0,则取最小总时长的整合方案。此方案即为最优方案。
请参照图1和图2,本发明的实施例一为:
在工业控制领域,为了实现自动化,会在很多的设备,很多的场合中使用一些监控设备,如工业触摸屏等,将监控设备与控制设备通过串口通信的方式进行数据的采集与设备的控制。这些设备的种类很多,就拿最常见的PLC来举例。操作者通过触摸屏来控制与之连接的PLC,控制PLC的I/O点,从而实现对实际设备的控制,触摸屏还可以采集PLC从传感器等设备读回的数据,呈现给使用者查看或者记录。
越复杂的应用,需要监控的数据越多,而串口的速度是有限的,如何能高效地利用有限的串口资源就成了一个很有意义的事。越高的效率,越能帮助监控设备精准监控。
而要提升设备串口的通信效率,就需要一种比较优秀的方案与算法来支撑,由此,在本实施例中,为了提升设备串口的通信效率,提供了一种提升设备串口通信效率的方法,包括:
运行整套设备;
按初始连读长度和整合地址,得到初始的地址整合组,让设备进入正常的稳定的工作状态;
判断是否以进行过优化,若没有则进行如下操作:
S1、按照初始连续长度进行一次请求通信,以采集预设通讯参数;
在本实施例中,预设通讯参数具体包括波特率RB、通信起始时间t 1、通信结束时间t 2以及每个字符的停止位+起始位+校验位的位数m和数据位位数n。
S11、对目标数据长度l进行一次补齐运算,将补齐运算后的结果作为新的目标数据长度l,补齐运算:
Figure PCTCN2020134450-appb-000013
S2、根据所述预设通讯参数,计算一次通信中非传输最终目标数据所用时长所能传输的第一数据量;
在本实施例中,所述步骤S2具体为:
根据所述预设通讯参数,计算一次通信的总时长T和一次通信中传输最终目标数据所用时长t 3,所述总时长T=t 2-t 1,所述传输最终目标数据所用时长
Figure PCTCN2020134450-appb-000014
根据一次通信的总时长T和一次通信中传输最终目标数据所用时长t 3,计算一次通信中非传输最终目标数据所用时长t 4,所述非传输最终目标数据所用时长t 4=T-t 3
根据一次通信中所述非传输最终目标数据所用时长t 4,计算第一数据量b,所述第一数据量
Figure PCTCN2020134450-appb-000015
假定需要读取目标地址数据集合为{a i},其中i≥1。假设此集合地址被整合成了p组,进行了p次的交互得到最终数据。那么:总时间T 为:
Figure PCTCN2020134450-appb-000016
由算式可以看出,拆分得越细则l 1+l 2+...+l p越小,但p越大;拆分得越粗则则l 1+l 2+...+l p越大,但p越小。所以需要取一组合适的值,使得总时间T 最小。因此,需要进行步骤S3的操作。
S3、根据所述第一数据量缩小所述初始连续长度,得到请求通信的总时长最短的最优地址组,按照所述最优地址组进行串口通信。
所述步骤S3具体为:
S31、以所述第一数据量为起始,将所述第一数据量作为第一连续长度,根据所述第一连续长度重新整合所有目标地址,得到第一地址组,并计算按照所述第一地址组进行一次请求通信的总时长,作为第一通信总时长;
S32、按照预设缩小量缩小所述第一连续长度,并将缩小后的所述第一连续长度作为第二连续长度,重新整合所有目标地址,得到第二地址组,并计算按照所述第二地址组进行一次请求通信的总时长,作为第二通信总时长;
S33、将所述第二通信总时长与所述第一通信总时长进行对比,若所述第二通信总时长大于所述第一通信总时长或所述第二连续长度等于0,则以所述第一连续长度作为最优连续长度,根据所述最优连续长度整合所有目标地址,得到最优地址组,否则将所述第二连续长度作为新的所述第一连续长度,将所述第二通信总时长作为新的第一通信总时长,并返回步骤S32;
S34、按照所述最优地址组进行串口通信。
请参照图3,本发明的实施例二为:
一种提升设备串口通信效率的终端1,包括处理器2、存储器3及存储在存储器3上并可在处理器2上运行的计算机程序,所述处理器2执行所述计算机程序时实现以上一种提升设备串口通信效率的方法。
综上所述,本发明提供的一种提升设备串口通信效率的方法和终端,通过采集设备的通讯参数,计算设备可以整合的目标地址的连续长度,以得到请求 通信的总时长最短的最优地址组,作为最优的整合方案,整个过程由计算机执行,计算结果更加精确,不需要使用者根据经验进行设置,在更方便的同时,设置也更加准确,且能够有效地提升设备串口的通信效率。
以上所述仅为本发明的实施例,并非因此限制本发明的专利范围,凡是利用本发明说明书及附图内容所作的等同变换,或直接或间接运用在相关的技术领域,均同理包括在本发明的专利保护范围内。

Claims (10)

  1. 一种提升设备串口通信效率的方法,其特征在于,包括:
    S1、按照初始连续长度进行一次请求通信,以采集预设通讯参数;
    S2、根据所述预设通讯参数,计算一次通信中非传输最终目标数据所用时长所能传输的第一数据量;
    S3、根据所述第一数据量缩小所述初始连续长度,得到请求通信的总时长最短的最优地址组,按照所述最优地址组进行串口通信。
  2. 根据权利要求1所述的一种提升设备串口通信效率的方法,其特征在于,所述预设通讯参数具体包括波特率RB、通信起始时间t 1、通信结束时间t 2以及每个字符的停止位+起始位+校验位的位数m和数据位位数n。
  3. 根据权利要求2所述的一种提升设备串口通信效率的方法,其特征在于,所述步骤S1和步骤S2之间,还包括:
    S11、对目标数据长度l进行一次补齐运算
    Figure PCTCN2020134450-appb-100001
    将补齐运算后的结果l’作为新的目标数据长度l,用于后续的所有计算。
  4. 根据权利要求3所述的一种提升设备串口通信效率的方法,其特征在于,所述步骤S2具体为:
    根据所述预设通讯参数,计算一次通信的总时长T和一次通信中传输最终目标数据所用时长t 3,所述总时长T=t 2-t 1,所述传输最终目标数据所用时长
    Figure PCTCN2020134450-appb-100002
    根据一次通信的总时长T和一次通信中传输最终目标数据所用时长t 3,计算一次通信中非传输最终目标数据所用时长t 4,所述非传输最终目标数据所用时长t 4=T-t 3
    根据一次通信中所述非传输最终目标数据所用时长t 4,计算第一数据量b,所述第一数据量
    Figure PCTCN2020134450-appb-100003
  5. 根据权利要求1所述的一种提升设备串口通信效率的方法,其特征在于,所述步骤S3具体为:
    S31、以所述第一数据量为起始,将所述第一数据量作为第一连续长度,根 据所述第一连续长度重新整合所有目标地址,得到第一地址组,并计算按照所述第一地址组进行一次请求通信的总时长,作为第一通信总时长;
    S32、按照预设缩小量缩小所述第一连续长度,并将缩小后的所述第一连续长度作为第二连续长度,重新整合所有目标地址,得到第二地址组,并计算按照所述第二地址组进行一次请求通信的总时长,作为第二通信总时长;
    S33、将所述第二通信总时长与所述第一通信总时长进行对比,若所述第二通信总时长大于所述第一通信总时长或所述第二连续长度等于0,则以所述第一连续长度作为最优连续长度,根据所述最优连续长度整合所有目标地址,得到最优地址组,否则将所述第二连续长度作为新的所述第一连续长度,将所述第二通信总时长作为新的第一通信总时长,并返回步骤S32;
    S34、按照所述最优地址组进行串口通信。
  6. 一种提升设备串口通信效率的终端,包括处理器、存储器及存储在存储器上并可在处理器上运行的计算机程序,其特征在于,所述处理器执行所述计算机程序时实现以下步骤:
    S1、按照初始连续长度进行一次请求通信,以采集预设通讯参数;
    S2、根据所述预设通讯参数,计算一次通信中非传输最终目标数据所用时长所能传输的第一数据量;
    S3、根据所述第一数据量缩小所述初始连续长度,得到请求通信的总时长最短的最优地址组,按照所述最优地址组进行串口通信。
  7. 根据权利要求6所述的一种提升设备串口通信效率的终端,其特征在于,所述预设通讯参数具体包括波特率RB、通信起始时间t 1、通信结束时间t 2以及每个字符的停止位+起始位+校验位的位数m和数据位位数n。
  8. 根据权利要求6所述的一种提升设备串口通信效率的终端,其特征在于,所述步骤S1和步骤S2之间,还包括:
    S11、对目标数据长度l进行一次补齐运算,将补齐运算后的结果作为新的目标数据长度l,补齐运算:
    Figure PCTCN2020134450-appb-100004
  9. 根据权利要求8所述的一种提升设备串口通信效率的终端,其特征在于, 所述步骤S2具体为:
    根据所述预设通讯参数,计算一次通信的总时长T和一次通信中传输最终目标数据所用时长t 3,所述总时长T=t 2-t 1,所述传输最终目标数据所用时长
    Figure PCTCN2020134450-appb-100005
    根据一次通信的总时长T和一次通信中传输最终目标数据所用时长t 3,计算一次通信中非传输最终目标数据所用时长t 4,所述非传输最终目标数据所用时长t 4=T-t 3
    根据一次通信中所述非传输最终目标数据所用时长t 4,计算第一数据量b,所述第一数据量
    Figure PCTCN2020134450-appb-100006
  10. 根据权利要求6所述的一种提升设备串口通信效率的终端,其特征在于,所述步骤S3具体为:
    S31、以所述第一数据量为起始,将所述第一数据量作为第一连续长度,根据所述第一连续长度重新整合所有目标地址,得到第一地址组,并计算按照所述第一地址组进行一次请求通信的总时长,作为第一通信总时长;
    S32、按照预设缩小量缩小所述第一连续长度,并将缩小后的所述第一连续长度作为第二连续长度,重新整合所有目标地址,得到第二地址组,并计算按照所述第二地址组进行一次请求通信的总时长,作为第二通信总时长;
    S33、将所述第二通信总时长与所述第一通信总时长进行对比,若所述第二通信总时长大于所述第一通信总时长或所述第二连续长度等于0,则以所述第一连续长度作为最优连续长度,根据所述最优连续长度整合所有目标地址,得到最优地址组,否则将所述第二连续长度作为新的所述第一连续长度,将所述第二通信总时长作为新的第一通信总时长,并返回步骤S32;
    S34、按照所述最优地址组进行串口通信。
PCT/CN2020/134450 2020-10-23 2020-12-08 一种提升设备串口通信效率的方法及终端 WO2022082950A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202011144705.2A CN112256617B (zh) 2020-10-23 2020-10-23 一种提升设备串口通信效率的方法及终端
CN202011144705.2 2020-10-23

Publications (1)

Publication Number Publication Date
WO2022082950A1 true WO2022082950A1 (zh) 2022-04-28

Family

ID=74263548

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/134450 WO2022082950A1 (zh) 2020-10-23 2020-12-08 一种提升设备串口通信效率的方法及终端

Country Status (2)

Country Link
CN (1) CN112256617B (zh)
WO (1) WO2022082950A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113194038B (zh) * 2021-04-06 2022-10-21 重庆芯力源科技有限公司 一种智能边缘网关的数据转发方法

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN201060411Y (zh) * 2007-03-21 2008-05-14 山东省计算中心 多协议视频终端解码器
US20090019235A1 (en) * 2007-07-13 2009-01-15 Nobuyuki Harada Apparatus and method for caching data in a computer memory
CN101753394A (zh) * 2009-12-09 2010-06-23 艾默生网络能源有限公司 一种单串口接入多个智能设备的通信方法以及一种单串口
CN110737480A (zh) * 2019-09-18 2020-01-31 福州瑞芯微电子股份有限公司 一种串口驱动程序复用方法和装置
CN110908940A (zh) * 2019-10-14 2020-03-24 百富计算机技术(深圳)有限公司 串口通讯参数调整的方法及终端设备
WO2020062227A1 (en) * 2018-09-30 2020-04-02 Siemens Aktiengesellschaft Method and device for recognizing apparatus and computer readable storage medium and program
CN111372314A (zh) * 2020-03-12 2020-07-03 湖南大学 基于移动边缘计算场景下的任务卸载方法及任务卸载装置

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102638451A (zh) * 2012-03-14 2012-08-15 江苏斯菲尔电气股份有限公司 Modbus通讯协议的寄存器列表数据的动态重组方法
CN105527881B (zh) * 2014-09-30 2019-02-22 上海安川电动机器有限公司 一种指令处理方法及装置
CN106326157A (zh) * 2015-06-30 2017-01-11 深圳市科陆电子科技股份有限公司 一种接收串口不定长数据的方法及装置
CN105278918B (zh) * 2015-10-15 2017-12-08 珠海格力电器股份有限公司 寄存器的读取方法和采用该读取方法的寄存器
CN111221756B (zh) * 2019-11-13 2023-06-30 北京中航通用科技有限公司 一种上位机高效下行数据传输的方法

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN201060411Y (zh) * 2007-03-21 2008-05-14 山东省计算中心 多协议视频终端解码器
US20090019235A1 (en) * 2007-07-13 2009-01-15 Nobuyuki Harada Apparatus and method for caching data in a computer memory
CN101753394A (zh) * 2009-12-09 2010-06-23 艾默生网络能源有限公司 一种单串口接入多个智能设备的通信方法以及一种单串口
WO2020062227A1 (en) * 2018-09-30 2020-04-02 Siemens Aktiengesellschaft Method and device for recognizing apparatus and computer readable storage medium and program
CN110737480A (zh) * 2019-09-18 2020-01-31 福州瑞芯微电子股份有限公司 一种串口驱动程序复用方法和装置
CN110908940A (zh) * 2019-10-14 2020-03-24 百富计算机技术(深圳)有限公司 串口通讯参数调整的方法及终端设备
CN111372314A (zh) * 2020-03-12 2020-07-03 湖南大学 基于移动边缘计算场景下的任务卸载方法及任务卸载装置

Also Published As

Publication number Publication date
CN112256617A (zh) 2021-01-22
CN112256617B (zh) 2021-04-20

Similar Documents

Publication Publication Date Title
KR940008104B1 (ko) 데이타 표시 및 프로토콜
KR101064101B1 (ko) 컨텐츠-종결 dma
EP3014852A2 (en) Methods for dynamically binding header field identifiers in a network control protocol
CN113872967B (zh) 车辆信息的传输方法、装置、电子设备及存储介质
WO2022082950A1 (zh) 一种提升设备串口通信效率的方法及终端
JP2013214050A (ja) ランダム値生成方法およびシステム
WO2022161244A1 (zh) 多主机仲裁方法、装置和可读存储介质
CN108388372B (zh) 一种自适应触摸数据的方法、装置、设备及存储介质
CN110688333A (zh) 一种基于pcie的dma数据传输系统及方法
CN110413558A (zh) 一种实现低功耗串口模块动态分频方法
US8199648B2 (en) Flow control in a variable latency system
CN104144212B (zh) 一种虚拟桌面图像传输方法、装置及系统
CN113992600A (zh) 基于缓存队列的多速率模式数据发送控制方法及装置
CN111026694B (zh) 数据接收方法、设备,图像形成装置、系统和电子设备
US7272194B1 (en) Method to transmit bits of data over a bus
CN114020741A (zh) 车辆里程信息的存储方法、装置、车辆电子系统及车辆
CN108536636B (zh) 一种基于peci总线的主从协商时序机
US11947480B2 (en) Universal serial bus scheduling using real time data
KR100202170B1 (ko) 시리얼 인터페이스를 위한 데이터 수신 방법 및 그 장치
US11620251B2 (en) Partitioned UFP for displayport repeater
WO2021139225A1 (zh) 用于存储系统的流量控制方法、装置、介质及电子设备
CN101087280A (zh) 数据传送系统与数据处理装置
CN103034598B (zh) 保存dma下行数据时写使能信号的处理方法及系统
Sah et al. Implementation of Serial Communication between PC and DSP Processor Using Modbus Protocol
CN116527392A (zh) 一种基于fpga的sha256高效数字加密方法及系统

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20958525

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20958525

Country of ref document: EP

Kind code of ref document: A1