Serialization | Iot framework ServerSuperIO tutorial-9. protocol filter, which solves multiple packets, sticks to packets, and redundant data. What does redundancy mean?
1. C # Introduction to cross-platform Iot communication framework ServerSuperIO (SSIO)
Serialization | Iot framework ServerSuperIO tutorial 1.4 communication modes and mechanisms.
Serialization | Iot framework ServerSuperIO tutorial 2. service instance configuration parameters
Serialization | Iot framework ServerSuperIO tutorial-3. Device Driver Introduction
Serialization | Iot framework ServerSuperIO tutorial-4. For example, you can develop a device driver that supports both serial and network communication.
Serialization | Iot framework ServerSuperIO tutorial-5. Polling communication mode development and precautions.
Serialization | Iot framework ServerSuperIO tutorial-6. concurrent communication mode development and precautions
Serialization | Iot framework ServerSuperIO tutorial-7. Self-control communication mode development and precautions
Serialization | Iot framework ServerSuperIO tutorial-8. single-instance communication mode development and precautions
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
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:
ServerSuperIO sets the protocol filter to solve this problem, such:
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:
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:
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 ();
}
}
1. [serialization] C # communication (Serial Port and network) Framework Design and Implementation
2. [Open Source] C # cross-platform Iot communication framework ServerSuperIO (SSIO) Introduction
2. Overall system construction solution using SuperIO and open-source cross-platform Iot framework ServerSuperIO
3. C # technical route of industrial IoT and integrated system solutions (data sources, , data upload and receiving, ActiveMQ, Mongodb, WebApi, and mobile App)
5. ServerSuperIO Open Source Address: https://github.com/wxzz/ServerSuperIO
Internet of Things & integrated technology (. NET) QQ Group:54256083