Serialization | Iot framework serversuperio tutorial-9. protocol filter to solve multiple packet-related, sticky packet, and redundant data

Source: Internet
Author: User

Thank you for sharing your comments.
Original address:
Http://www.cnblogs.com/lsjwq/

Contents

9. protocol filter to solve multiple packets, stick packets, and redundant data... 2

9.1 overview... 2

9.2 actual problems... 2

9.3 5 filters and secondary development... 5

9.4 precautions for device driver development

9.5 host program service instance configuration considerations... 6

9. Protocol filters are used to solve multiple packets of redundant data.
9.1 Overview

The concept of data packets in communication is a form of data in communication protocols. The content is simple and complex. We need to systematically consider the problem comprehensively and implement it using code.

There are also extreme cases in the industrial field. During the communication in the early years, packet header, packet end, data length, and data check bit were all correct, but the parsed data was incorrect, this situation may not occur frequently, but it may occur frequently in a special application environment. After analysis, it is concluded that it may be caused by geological electromagnetic interference. However, there are also technical design flaws. For example, if the data check bit is accumulated and changed to CRC, this problem will not occur. In addition, there should be a mechanism for sending incremental data.

9.2 actual problems

Reference Protocol: serialization | Iot framework serversuperio tutorial-4. For example, develop a device driver and support both serial and network communication

  1. 1.More than one package and Solutions

Multi-packet data transmission is a situation or a problem in the application environment, which is not the actual application, it means that data sent by the client can be fully received only after receiving data multiple times during the receiving process. This may be caused by the network environment or the data sending end, as shown in the following figure:

 

For example, the complete package of real-time data is 55 AA 00 61 43 7A 00 00 43 B4 15 0d. Then, when receiving data, the first received: 55 AA 00 61 43 7A 00 00 43 B4 15, and the second received: 0d. Based on the communication protocol, the received data is automatically spliced to form complete data and be parsed.

Serversuperio sets the protocol filter to solve this problem, such:

  1. 2.Stick package and Solution

I didn't know the concept of sticking a package. I learned it only after reading the article on the Internet. It is also a common problem in the field of communication. That is to say, if multiple packets of data are received at one time, it is necessary to split the package reasonably. Another case is that the half-packet data is received at one time. The half-packet data is combined with "1. One packet is sent multiple times and solved" to solve this problem, as shown in the following figure:

 

Serversuperio sets the protocol filter to solve this problem, such:

  1. 3.Emergence and solution of redundant data

This situation is very likely to occur in the industrial field due to electromagnetic interference of cables or environments and virtual connection of connectors. If the interference redundant data is mixed in the middle of a protocol package, it is difficult to verify valid data. If the interference redundant data is mixed in the middle of two protocol packets, you can use protocol filtering to identify useful data. Example:

 

Serversuperio sets the protocol filter to solve this problem, such:

9.3 5 filters and secondary development
12345 Fixedendreceivefliter: Fixed protocol filter.Fixedheadandendreceivefliter: a protocol filter that specifies the beginning and end.Fixedheadandlengthreceivefliter: protocol filter with Fixed start and length.Fixedheadreceivefliter: Fixed protocol filter.Fixedlengthreceivefliter: fixed-length protocol filter.

These five filters are inherited from the ireceivefilter interface. You can also inherit this interface for secondary development and customize your own protocol filters. Code engineering example:

 

9.4 precautions for device driver development

For device drivers, you can add the protocol filter of the driver during initialization. The Code is as follows:

12345 public override void Initialize(string devid){            this.Protocol.InitDriver(this.GetType(),new FixedHeadAndEndReceiveFliter(new byte[] {0x55,0xaa},new byte[] {0x0d} ));……}
9.5 host program service instance configuration considerations

In the configuration parameters, you must configure startreceivedatafliter = true to apply the Protocol filter. The Code is as follows:

12345678910111213141516171819202122232425262728293031323334353637383940 static void Main(string[] args){            DeviceSelfDriver dev2 = new DeviceSelfDriver();            dev2.DeviceParameter.DeviceName = "Network device";            dev2.DeviceParameter.DeviceAddr = 1;            dev2.DeviceParameter.DeviceID = "1";            dev2.DeviceDynamic.DeviceID = "1";            dev2.DeviceParameter.DeviceCode = "1";            dev2.DeviceParameter.NET.RemoteIP = "127.0.0.1";            dev2.DeviceParameter.NET.RemotePort = 9600;            dev2.CommunicateType = CommunicateType.NET;            dev2.Initialize("1");             IServer server = new ServerManager().CreateServer(new ServerConfig()            {                ServerName = "Service 1",                ComReadTimeout = 1000,                ComWriteTimeout = 1000,                NetReceiveTimeout = 1000,                NetSendTimeout = 1000,                ControlMode = ControlMode.Self,                SocketMode = SocketMode.Tcp,                StartReceiveDataFliter = true,                ClearSocketSession = false,                StartCheckPackageLength = false,                CheckSameSocketSession = false,                DeliveryMode = DeliveryMode.DeviceIP,            });             server.AddDeviceCompleted += server_AddDeviceCompleted;            server.DeleteDeviceCompleted+=server_DeleteDeviceCompleted;            server.Start();              server.AddDevice(dev2);             while ("exit" == Console.ReadLine())            {                server.Stop();            }}

Serialization | Iot framework serversuperio tutorial-9. protocol filter to solve multiple packet-related, sticky packet, and redundant data

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.