This commit is contained in:
parallelbgls
2017-12-26 16:31:29 +08:00
parent 038d0fde13
commit cfc2c489ff
10 changed files with 34 additions and 34 deletions

View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net45</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Modbus.Net.Modbus\Modbus.Net.Modbus.csproj" />
<ProjectReference Include="..\Modbus.Net.Siemens\Modbus.Net.Siemens.csproj" />
<ProjectReference Include="..\Modbus.Net\Modbus.Net.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,147 @@
using System;
using System.Collections.Generic;
using System.Threading;
using Modbus.Net.Modbus;
using Serilog;
namespace Modbus.Net.PersistedTests
{
class Program
{
static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration().MinimumLevel.Verbose().WriteTo.Console().CreateLogger();
IMachineProperty<int> machine = new ModbusMachine<int, string>(1, ModbusType.Rtu, "COM1",
new List<AddressUnit>()
{
new AddressUnit()
{
Id = "1",
Area = "4X",
Address = 1,
Name = "test 1",
DataType = typeof(ushort)
},
new AddressUnit()
{
Id = "2",
Area = "4X",
Address = 2,
Name = "test 2",
DataType = typeof(ushort)
},
new AddressUnit()
{
Id = "3",
Area = "4X",
Address = 3,
Name = "test 3",
DataType = typeof(ushort)
},
}, true, 2, 1);
IMachineProperty<int> machine2 = new ModbusMachine<int, string>(2, ModbusType.Rtu, "COM1",
new List<AddressUnit>()
{
new AddressUnit()
{
Id = "1",
Area = "4X",
Address = 11,
Name = "test 1",
DataType = typeof(ushort)
},
new AddressUnit()
{
Id = "2",
Area = "4X",
Address = 12,
Name = "test 2",
DataType = typeof(ushort)
},
new AddressUnit()
{
Id = "3",
Area = "4X",
Address = 13,
Name = "test 3",
DataType = typeof(ushort)
},
}, true, 3, 1);
IMachineProperty<int> machine3 = new ModbusMachine<int, string>(3, ModbusType.Rtu, "COM1",
new List<AddressUnit>()
{
new AddressUnit()
{
Id = "1",
Area = "4X",
Address = 21,
Name = "test 1",
DataType = typeof(ushort)
},
new AddressUnit()
{
Id = "2",
Area = "4X",
Address = 22,
Name = "test 2",
DataType = typeof(ushort)
},
new AddressUnit()
{
Id = "3",
Area = "4X",
Address = 23,
Name = "test 3",
DataType = typeof(ushort)
},
}, true, 4, 1);
TaskManager<int> manager = new TaskManager<int>(20, true);
manager.AddMachines<string>(new List<IMachineProperty<int>>{machine, machine2, machine3});
Random r = new Random();
manager.InvokeTimerAll(new TaskItemSetData(()=>new Dictionary<string, double>
{
{
"4X 1.0", r.Next()%65536
},
{
"4X 2.0", r.Next()%65536
},
{
"4X 3.0", r.Next()%65536
},
{
"4X 11.0", r.Next()%65536
},
{
"4X 12.0", r.Next()%65536
},
{
"4X 13.0", r.Next()%65536
},
{
"4X 21.0", r.Next()%65536
},
{
"4X 22.0", r.Next()%65536
},
{
"4X 23.0", r.Next()%65536
},
}, MachineSetDataType.Address, 10000, 10000));
Thread.Sleep(5000);
manager.InvokeTimerAll(new TaskItemGetData(data =>
{
foreach (var dataInner in data.ReturnValues)
{
Console.WriteLine(dataInner.Key + " " + dataInner.Value.PlcValue);
}
}, MachineGetDataType.Address, 10000, 10000));
Console.Read();
Console.Read();
}
}
}