-
Notifications
You must be signed in to change notification settings - Fork 136
2.5 Abstract Protocol Layer Protocol
Abstract Protocol Layer is a common core for one type of protocol, and the entrypoint of Concrete Protocol Layer.
IProtocol is the Abstract Protocol Layer of Modbus.Net, included a great number of ProtocolUnit.
Every ProtocolUnit is an abstract protocol, it is not the real protocol but common part of it.
I'll give an example from modbus.
RTU Procol is slave-protocol No.-Address-Data-CRC16
ASCII is slave-protocol no.-Address-Data-LRC
TCP is 0000-Slave-Protocol No.-Address-Data.
So the common part of them is slave-Protocol No.-Address-Data.
BaseProtocol implemented a lazy loading ProtocolUnit dictionary, to use this dictionary, only point type of ProtocolUnit to it and it will load the ProtocolUnit for users.
-
ProtocolUnit
ProtocolUnit inherits from IProtocolFormatting and has two methods: Format and Unformat.
public abstract TParamIn Format(IInputStruct message); public abstract IOutputStruct Unformat(TParamOut messageBytes, ref int pos);
Format change IInputStruct to input parameter, and Unformat change output parameter to IOutputStruct.
You can reference ModbusProtocol.cs in Modbus.Net.Modbus to implement your own ProtocolUnit.
-
BaseProtocol
BaseProtocol implement a lazy loading dictionary.
public ProtocolUnit this[Type type]
This dicionary uses type of ProtocolUnit for parameters. ProtocolUnit will be automaticlly loaded into dictionary when ProtocolUnit instance doesn't exist, otherwise directly loaded memory cache.
When BaseProtocol wants to send and receive data, it directly call Format and Unformat to create and read protocol content.
If you want to implement your own loading methods, inherit IProtocol rather than ProtocolUnit.
When created IProtocol, it requires to add an IProtocolLinker, this linker meads how to send and receive IProtocol to IConnector.
IProtocol only has one main method called SendReceive(Async), when IUtilityMethod sends SendReceive(Async) to pass a message, IProtocol will change Protocol to input parameter(original byte[]), and send SendReceive messsage to IProtocolLinker.
Modbus.Net Hangzhou Delian Science Technology Co.,Ltd. © 2023
-
2 Specification of Modbus.Net main framework
- 2.1 Modbus.Net Architecture
- 2.2 Transmission Control Layer Controller
- 2.3 Transmission Link Layer Connector
- 2.4 Concrete Protocol Layer ProtocolLinker
- 2.5 Abstract Protocol Layer Protocol
- 2.6 Protocol Presentation Layer Utility
- 2.7 Device Application Layer Machine
- 2.8 Task Application Layer MachineJob
-
3 Using Modbus.Net to implement a protocol
- 3.1 Global Tools
- 3.2 Extends Protocol and ProtocolUnit according to protocol specification
- 3.3 Extends Connector to create a link method
- 3.4 Extends Machine and Utility, creating two apis
- 3.5 Extends API methods to Machine and Utility
- 3.6 Extends Formater, Translator and Combiner, Creating Encoding,Decoding,Combining methods for address
- 3.7 Extends Controller, to control message