Remove TaskManager

This commit is contained in:
luosheng
2023-02-11 10:53:12 +08:00
parent 86e084f814
commit f8b016ac4a
9 changed files with 8 additions and 1541 deletions

View File

@@ -18,11 +18,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{D8DD32FC
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Modbus.Net.Tests", "..\Tests\Modbus.Net.Tests\Modbus.Net.Tests.csproj", "{3BB01E98-3D45-454A-A1BD-49D7B2C83B74}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Modbus.Net.PersistedTests", "..\Tests\Modbus.Net.PersistedTests\Modbus.Net.PersistedTests.csproj", "{EC184EF4-81C4-4A4B-8763-79AC4150E613}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{3597B5C5-45B9-4ECB-92A3-D0FFBE47920A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Modbus.Net.Modbus.Test", "Modbus.Net.Modbus.Test\Modbus.Net.Modbus.Test.csproj", "{3615E574-1A98-4BBC-8C08-01FE95AD40AF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Modbus.Net.Modbus.Test", "..\Samples\Modbus.Net.Modbus.Test\Modbus.Net.Modbus.Test.csproj", "{22A35CA8-CDCF-416D-BA84-08C933B4A3DE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -46,22 +44,17 @@ Global
{3BB01E98-3D45-454A-A1BD-49D7B2C83B74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3BB01E98-3D45-454A-A1BD-49D7B2C83B74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3BB01E98-3D45-454A-A1BD-49D7B2C83B74}.Release|Any CPU.Build.0 = Release|Any CPU
{EC184EF4-81C4-4A4B-8763-79AC4150E613}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EC184EF4-81C4-4A4B-8763-79AC4150E613}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC184EF4-81C4-4A4B-8763-79AC4150E613}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC184EF4-81C4-4A4B-8763-79AC4150E613}.Release|Any CPU.Build.0 = Release|Any CPU
{3615E574-1A98-4BBC-8C08-01FE95AD40AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3615E574-1A98-4BBC-8C08-01FE95AD40AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3615E574-1A98-4BBC-8C08-01FE95AD40AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3615E574-1A98-4BBC-8C08-01FE95AD40AF}.Release|Any CPU.Build.0 = Release|Any CPU
{22A35CA8-CDCF-416D-BA84-08C933B4A3DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{22A35CA8-CDCF-416D-BA84-08C933B4A3DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{22A35CA8-CDCF-416D-BA84-08C933B4A3DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{22A35CA8-CDCF-416D-BA84-08C933B4A3DE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{3BB01E98-3D45-454A-A1BD-49D7B2C83B74} = {D8DD32FC-CF39-4A1A-8FBF-9E82C5278C34}
{EC184EF4-81C4-4A4B-8763-79AC4150E613} = {D8DD32FC-CF39-4A1A-8FBF-9E82C5278C34}
{3615E574-1A98-4BBC-8C08-01FE95AD40AF} = {3597B5C5-45B9-4ECB-92A3-D0FFBE47920A}
{22A35CA8-CDCF-416D-BA84-08C933B4A3DE} = {3597B5C5-45B9-4ECB-92A3-D0FFBE47920A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AF00D64E-3C70-474A-8A81-E9E48017C4B5}

File diff suppressed because it is too large Load Diff

View File

@@ -12,8 +12,8 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Modbus.Net.Modbus\Modbus.Net.Modbus.csproj" />
<ProjectReference Include="..\Modbus.Net\Modbus.Net.csproj" />
<ProjectReference Include="..\..\Modbus.Net\Modbus.Net.Modbus\Modbus.Net.Modbus.csproj" />
<ProjectReference Include="..\..\Modbus.Net\Modbus.Net\Modbus.Net.csproj" />
</ItemGroup>
</Project>

View File

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

View File

@@ -1,156 +0,0 @@
using System;
using System.Collections.Generic;
using System.Threading;
using Modbus.Net.Modbus;
using Modbus.Net.Interface;
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.InvokeTimerForMachine(1, new TaskItemSetData(() => new Dictionary<string, double>
{
{
"4X 1.0", r.Next() % 65536
},
{
"4X 2.0", r.Next() % 65536
},
{
"4X 3.0", r.Next() % 65536
},
}, MachineSetDataType.Address, 10000, 10000));
manager.InvokeTimerForMachine(2, new TaskItemSetData(() => new Dictionary<string, double>
{
{
"4X 11.0", r.Next() % 65536
},
{
"4X 12.0", r.Next() % 65536
},
{
"4X 13.0", r.Next() % 65536
},
}, MachineSetDataType.Address, 10000, 10000));
manager.InvokeTimerForMachine(3, new TaskItemSetData(() => new Dictionary<string, double>
{
{
"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 =>
{
if (data?.ReturnValues != null)
{
foreach (var dataInner in data.ReturnValues)
{
Console.WriteLine(dataInner.Key + " " + dataInner.Value.PlcValue);
}
}
}, MachineGetDataType.Address, 10000, 10000));
Console.Read();
Console.Read();
}
}
}

View File

@@ -1,8 +0,0 @@
{
"profiles": {
"WSL": {
"commandName": "WSL2",
"distributionName": ""
}
}
}

View File

@@ -12,10 +12,6 @@ namespace Modbus.Net.Tests
{
private List<AddressUnit<int>> _addressUnits;
private TaskManager<int> _taskManager;
private BaseMachine<int, int> _baseMachine;
private BaseMachine<int, int> _baseMachine2;
[TestInitialize]
@@ -129,11 +125,6 @@ namespace Modbus.Net.Tests
},
};
_baseMachine = new ModbusMachine<int, int>(1, ModbusType.Tcp, "192.168.1.1", _addressUnits, true, 2, 0)
{
ProjectName = "Project 1",
MachineName = "Test 1"
};
_baseMachine2 = new SiemensMachine<int, int>(2, SiemensType.Tcp, "192.168.3.10", SiemensMachineModel.S7_1200, _addressUnits, true, 2, 0)
{
ProjectName = "Project 1",
@@ -141,11 +132,6 @@ namespace Modbus.Net.Tests
};
_baseMachine2.ConnectAsync().Wait();
_taskManager = new TaskManager<int>(10, true);
_taskManager.AddMachine(_baseMachine);
_taskManager.AddMachine(_baseMachine2);
}
[TestMethod]
@@ -307,24 +293,6 @@ namespace Modbus.Net.Tests
Assert.AreEqual(combinedAddresses[4].GetCount, 8);
}
[TestMethod]
public void TaskManagerGetMachineTest()
{
var machine = _taskManager.GetMachineById(1);
Assert.AreEqual(machine.MachineName, "Test 1");
var machine2 = _taskManager.GetMachineByConnectionToken("192.168.3.10");
Assert.AreEqual(machine2.MachineName, "Test 2");
}
[TestMethod]
public void BaseMachineGetAddressTest()
{
var addressUnit = _baseMachine.GetAddressUnitById(1);
Assert.AreEqual(addressUnit.Area, "3X");
Assert.AreEqual(addressUnit.Address, 1);
}
[TestCleanup]
public void MachineClean()
{

View File

@@ -1,150 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Modbus.Net.Modbus;
namespace Modbus.Net.Tests
{
[TestClass]
public class TaskManagerTest
{
private TaskManager _taskManager;
private Dictionary<string, double> _valueDic = new Dictionary<string, double>();
private Timer _timer;
[TestInitialize]
public void TaskManagerInit()
{
_taskManager = new TaskManager(20, true);
var addresses = new List<AddressUnit>
{
new AddressUnit
{
Id = "0",
Area = "4X",
Address = 2,
SubAddress = 0,
CommunicationTag = "A1",
DataType = typeof(ushort)
},
new AddressUnit
{
Id = "1",
Area = "4X",
Address = 3,
SubAddress = 0,
CommunicationTag = "A2",
DataType = typeof(ushort)
},
new AddressUnit
{
Id = "2",
Area = "4X",
Address = 4,
SubAddress = 0,
CommunicationTag = "A3",
DataType = typeof(ushort)
},
new AddressUnit
{
Id = "3",
Area = "4X",
Address = 5,
SubAddress = 0,
CommunicationTag = "A4",
DataType = typeof(ushort)
},
new AddressUnit
{
Id = "4",
Area = "4X",
Address = 6,
SubAddress = 0,
CommunicationTag = "A5",
DataType = typeof(uint)
},
new AddressUnit
{
Id = "5",
Area = "4X",
Address = 8,
SubAddress = 0,
CommunicationTag = "A6",
DataType = typeof(uint)
}
};
BaseMachine machine = new ModbusMachine("1", ModbusType.Tcp, "192.168.3.10", addresses, true, 2, 0);
_taskManager.AddMachine(machine);
var r = new Random();
_timer = new Timer(async state =>
{
lock (_valueDic)
{
_valueDic = new Dictionary<string, double>
{
{
"A1", r.Next(0, UInt16.MaxValue)
},
{
"A2", r.Next(0, UInt16.MaxValue)
},
{
"A3", r.Next(0, UInt16.MaxValue)
},
{
"A4", r.Next(0, UInt16.MaxValue)
},
{
"A5", r.Next()
},
{
"A6", r.Next()
}
};
}
await _taskManager.InvokeOnceAll(new TaskItemSetData(() => _valueDic, MachineSetDataType.CommunicationTag));
}, null, 0, 5000);
}
[TestMethod]
public async Task TaskManagerValueReadWriteTest()
{
Thread.Sleep(2000);
var i = 5;
while (i > 0)
{
Thread.Sleep(5000);
await _taskManager.InvokeOnceAll(new TaskItemGetData(
def =>
{
var dicans = def.ReturnValues.ToDictionary(p => p.Key, p => p.Value.PlcValue);
Assert.AreEqual(dicans["A1"], _valueDic["A1"]);
Assert.AreEqual(dicans["A2"], _valueDic["A2"]);
Assert.AreEqual(dicans["A3"], _valueDic["A3"]);
Assert.AreEqual(dicans["A4"], _valueDic["A4"]);
Assert.AreEqual(dicans["A5"], _valueDic["A5"]);
Assert.AreEqual(dicans["A6"], _valueDic["A6"]);
}, MachineGetDataType.CommunicationTag));
i--;
}
}
[TestCleanup]
public void TaskManagerFinilize()
{
_taskManager.StopTimerAll();
_timer.Dispose();
}
}
}