76 lines
2.5 KiB
C#
76 lines
2.5 KiB
C#
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.Tcp, "127.0.0.1",
|
|
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);
|
|
|
|
TaskManager<int> manager = new TaskManager<int>(20, true);
|
|
manager.AddMachines<string>(new List<IMachineProperty<int>> { machine });
|
|
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));
|
|
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();
|
|
}
|
|
}
|
|
}
|