-
Notifications
You must be signed in to change notification settings - Fork 136
4.2.Three API calling ways
luosheng edited this page Jun 7, 2023
·
2 revisions
At the beginning, before using Modbus.Net, Modbus.Net.dll is not the only framework that required but also at least a concrete protocol framework like Modbus.Net.Modbus.dll.
- Initialize an Utility, e.g.:
IUtilityProperty utility = new ModbusUtility(ModbusType.Tcp, "192.168.1.10", 2, 0, Endian.LittleEndian);
- Modbus.Net has three different Endians:
- Little endian: Endian.LittleEndian, least significant bit.
- Big endian: Endian.BigEndianLsb, least significant bit.
- Big endian Msb: Endian.BigEndianMsb, most significant bit.
- Call method in Utility, IUtilityProperty has a method that could load method group.
public TUtilityMethod GetUtilityMethods<TUtilityMethod>() where TUtilityMethod : class, IUtilityMethod
Use this function like:
utility.GetUtilityMethods<IUtilityMethodDatas>()?.GetDatasAsync(...);
GetUtilityMethods will return null when utility doesn't implement some IUtilityMethod type in template.
For BaseUtility:
- BaseUtility implement IUtilityMethodData as default, including GetDatasAsync and SetDatasAsync, they are used for read data and write data.
- Utility only has a string address, this address describe full messages for address, different protocol has different meaning with that due to the AddressTranslator.
- e.g. 11th bit of Modbus.Net.Mdobus 30005 address is "3X 5.10" using AddressTranslatorModbus. Bit should minus 1 because Modbus.Net use 0 as the 1st bit but Modbus standard is 1.
- Initialize a Machine instance, e.g.:
IMachineProperty machine = new ModbusMachine(ModbusType.Tcp, "192.168.1.10", new List<AddressUnit>(...), true, 2, 0, Endian.LittleEndian);
- Attention for AddressUnit:
- AddressUnit will be combined using area and address in BaseMachine, so whatever you want, please write one and only fake Area and Address even though protocol dosen't use it (For Modbus.Net.OPC users).
- Call method in Machine, IMachineProperty has a method that could load method group.
public TMachineMethod GetMachineMethods<TUtilityMethod>() where TMachineMethod : class, IMachineMethod
Use this function like:
machine.GetMachineMethods<IMachineMethodDatas>()?.GetDatasAsync(...);
GetMachineMethods will return null when machine doesn't implement some IMachineMethod type in template.
For BaseMachine:
- BaseMachine implement IMachineMethodData as default, including GetDatasAsync and SetDatasAsync, they are used for read data and write data.
- BaseMachine has four return keywords, Id returns Id of AddressUnit, Name returns Name of AddressUnit, CommunicationTag returns CommunicationTag of AddressUnit, Address return string format address of AddressUnit.
- CommunicationTag is used for block other keywords in AddressUnit, it is recommended in json for short the json length and block privacy messages. CommuncationTag must be only in a device like Id for AddressUnit.
MachineJobScheduler
- Initialize a machinejobscheduler.
var machineJobScheduler = await MachineJobSchedulerCreator.CreateScheduler("Trigger1", -1, 10);
- Add a job chain, e.g. aquire data from machine every 10 seconds.
var job = machineJobScheduler.From(machine.Id + ".From", machine, MachineDataType.Name).Result.Query(machine.Id + ".ConsoleQuery", QueryConsole).Result;
- Run job.
await job.Run();
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