diff --git a/Modbus.Net/Modbus.Net.Modbus/README.md b/Modbus.Net/Modbus.Net.Modbus/README.md index 4822119..56a21ac 100644 --- a/Modbus.Net/Modbus.Net.Modbus/README.md +++ b/Modbus.Net/Modbus.Net.Modbus/README.md @@ -4,4 +4,8 @@ Modbus.Net.Modbus Modbus Implementation of Modbus.Net -Doc has been moved to wiki. \ No newline at end of file +Doc has been moved to wiki. + +Important +------------------ +Currently protocols are not being tested except IMachineMethodDatas and IUtilityMethodDatas diff --git a/Modbus.Net/Modbus.Net.Opc/README.md b/Modbus.Net/Modbus.Net.Opc/README.md index 70560c8..913deec 100644 --- a/Modbus.Net/Modbus.Net.Opc/README.md +++ b/Modbus.Net/Modbus.Net.Opc/README.md @@ -1,6 +1,6 @@ Modbus.Net.OPC =================== -[![NuGet](https://img.shields.io/nuget/v/Modbus.Net.OPC.svg)](https://www.nuget.org/packages/Modbus.Net.OPC/) +[![NuGet](https://img.shields.io/nuget/v/Modbus.Net.Opc.svg)](https://www.nuget.org/packages/Modbus.Net.Opc/) OPC Implementation of Modbus.Net diff --git a/Modbus.Net/Modbus.Net/README.md b/Modbus.Net/Modbus.Net/README.md index 8ec7c83..17434dd 100644 --- a/Modbus.Net/Modbus.Net/README.md +++ b/Modbus.Net/Modbus.Net/README.md @@ -84,6 +84,7 @@ Combine duplicated addresses to organized addresses, each organized addresses co This platform has three level APIs that you could use: Low level API called "BaseUtility"; Middle level API called "BaseMachine" ### Utility + IUtilityProperty is a low level api, in this level you can get or set data only by byte array or object array. Here is an example. ```C# @@ -201,8 +202,8 @@ There are 4 AddressCombiners implemented in the platform. 3.Use GetDatas Api. ```C# -var result = machine.InvokeMachineMethods?.GetDatas(MachineDataType.CommunicationTag); -//var result = await machine.InvokeMachineMethods?.GetDatasAsync(MachineDataType.CommunicationTag); +var result = machine.InvokeMachineMethods?.GetDatas(MachineDataType.CommunicationTag); +//var result = await machine.InvokeMachineMethods?.GetDatasAsync(MachineDataType.CommunicationTag); ``` 4.Retrive data from result. @@ -227,6 +228,62 @@ machine.SetDatas has four types. It is referenced as the first parameter. 3. MachineDataType.Id: the key of the dictionary of the second paramenter is ID. 4. MachineDataType.Name: the key of the dictionary of the second paramenter is name. +### Job + +You can use MachineJobSchedulerCreator to create a job scheduler then write a job chain and run this chain. +```C# +var scheduler = await MachineJobSchedulerCreator.CreateScheduler(machine.Id, -1, 10); +var job = scheduler.From(machine.Id + ".From", machine, MachineDataType.Name).Result.Query(machine.Id + ".ConsoleQuery", QueryConsole).Result.To(machine.Id + ".To", machine).Result.Deal(machine.Id + ".Deal", OnSuccess, OnFailure).Result; +await job.Run(); +``` + +Also you can use MultipleMachinesJobScheduler to run multiple machines in a same chain. +```C# +MultipleMachinesJobScheduler.RunScheduler(machines, async (machine, scheduler) => +{ + await scheduler.From(machine.Id + ".From", machine, MachineDataType.Name).Result.Query(machine.Id + ".ConsoleQuery", QueryConsole).Result.To(machine.Id + ".To", machine).Result.Deal(machine.Id + ".Deal", OnSuccess, OnFailure).Result.Run(); +}, -1, 10) +``` + +### Read Machine Parameter from appsettings.json + +First writing C# Code to read machines. +```C# +var machines = MachineReader.ReadMachines(); +``` +Then writing json config in appsettings.json +```Json +"Machine": [ + { + "a:id": "ModbusMachine1", + "b:protocol": "Modbus", + "c:type": "Tcp", + "d:connectionString": "10.10.18.251", + "e:addressMap": "AddressMapModbus", + "f:keepConnect": true, + "g:slaveAddress": 1, + "h:masterAddress": 2, + "i:endian": "BigEndianLsb" + }, +... +] +"addressMap": { + "AddressMapModbus": [ + { + "Area": "4X", + "Address": 1, + "DataType": "Int16", + "Id": "1", + "Name": "Test1" + }, +... + ], +... +} +``` +For some reasons, you need to add e.g. "a:" "b:" to let property ordered in machine configuration, anything can be used here before ":". +But after ":", property should match constructor except protocol, which refer to class name. + ## Implementing Your Own Protocol The main target of Modbus.Net is building a high extensable hardware communication protocol, so we allow everyone to extend the protocol. @@ -327,7 +384,11 @@ public class ModbusTcpProtocolLinkerBytesExtend : ProtocolLinkerBytesExtend ``` For example modbus tcp has a 6 bytes head: 4 bytes 0 and 2 bytes length. And when you get the bytes, please remove the head to fit the ModbusProtocol Unformat function. -5.Implement BaseUtility.cs (ModbusUtility.cs) +5.Implement BaseController.cs (FIFOController.cs) +Implement message dispatching api like first in first out. +There are no rules for implementation, but you can refer IController and FIFOController to implement your own controller like RBTreeController. + +6.Implement BaseUtility.cs (ModbusUtility.cs) Implement low level api for Modbus. You need to implement three functions. ```C# @@ -345,7 +406,7 @@ public ModbusUtility(int connectionType, byte slaveAddress, byte masterAddress) } ``` -6.Implement BaseMachine.cs (ModbusMachine.cs) +7.Implement BaseMachine.cs (ModbusMachine.cs) Implement middle level api for Modbus. ```C# public ModbusMachine(ModbusType connectionType, string connectionString, @@ -360,7 +421,7 @@ public ModbusMachine(ModbusType connectionType, string connectionString, ``` Set BaseUtility, default AddressFormater, AddressCombiner and AddressCombinerSet. -7.Implement your own AddressFormater, AddressTranslator and AddressCombiner. (AddressFormaterModbus.cs, AddressTranslatorModbus.cs) (Optional) +8.Implement your own AddressFormater, AddressTranslator and AddressCombiner. (AddressFormaterModbus.cs, AddressTranslatorModbus.cs) (Optional) If some devices have its own address rule, you should implement your own address formating system. ```C# public class AddressFormaterModbus : AddressFormater @@ -415,3 +476,15 @@ type = typeof(byte) SubAddress 8 means it starts from the 8th bit in that short value. Remember subpos system cannot cross a byte in current version. If you want to cross a byte, you can change the function "GetValue" in ValueHelper.cs + +### For configurations + +You can replace any configuration in appsettings.default.json, and remember, you can change settings only for one connection or one physical port. +Like +```Json +{ + "Modbus.Net:TCP:192.168.1.100:502:FetchSleepTime": 50, + "Modbus.Net:TCP:192.168.1.101:FetchSleepTime": 50, + "Modbus.Net:COM:COM1:FetchSleepTime": 2000 +} +``` diff --git a/README.md b/README.md index 4a80335..bf2b7ae 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,10 @@ Modbus.Net is an open hardware communication platform. You can focus on the protocol itself and the platform can automatically create a full asynchronous or synchronous communication library. +Important +------------------- +You need to copy appsettings.default.json file in Modbus.Net to your own project, and don't forget to change settings of file to copy content and copy when newer, otherwise Modbus.Net will not work. + Why is it called Modbus.Net ------------------- Modbus.Net was open sourced two years ago when I graduated. The first target of this project was to implement remote PLC communication using Modbus TCP. Half a year later the company decide to use a IoT hardware, then a more universal architecture was required. The main platform changed to a universal communication platform. Despite all these changes the name "Modbus.Net" stuck. @@ -15,6 +19,7 @@ The real Modbus Implementation has been moved to [Modbus.Net.Modbus]( https://ww There is also [Modbus.Net.Siemens]( https://www.nuget.org/packages/Modbus.Net.Siemens) that can communicate with Siemens S7-200, S7-200 Smart, S7-300, S7-400, S7-1200 and S7-1500 using PPI or TCP/IP. +[Modbus.Net.Opc]( https://www.nuget.org/packages/Modbus.Net.Opc) Implements OPC DA and OPC UA protocol. Supported Platforms ------------------- @@ -25,4 +30,4 @@ Thanks ------------------- * Quartz - Job Scheduler * Serilog - Logging -* DotNetty - Network Transporting \ No newline at end of file +* DotNetty - Network Transporting