Job System and DuplicateWithCount bug fix.
This commit is contained in:
@@ -25,7 +25,7 @@ namespace Modbus.Net.Modbus
|
|||||||
public ModbusAsciiInTcpProtocolLinker(string ip, int port)
|
public ModbusAsciiInTcpProtocolLinker(string ip, int port)
|
||||||
: base(ip, port)
|
: base(ip, port)
|
||||||
{
|
{
|
||||||
((BaseConnector)BaseConnector).AddController(new FifoController(0));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "100")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace Modbus.Net.Modbus
|
|||||||
public ModbusAsciiInUdpProtocolLinker(string ip, int port)
|
public ModbusAsciiInUdpProtocolLinker(string ip, int port)
|
||||||
: base(ip, port)
|
: base(ip, port)
|
||||||
{
|
{
|
||||||
((BaseConnector)BaseConnector).AddController(new FifoController(0));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "0")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Configuration;
|
||||||
using System.IO.Ports;
|
using System.IO.Ports;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -17,7 +18,7 @@ namespace Modbus.Net.Modbus
|
|||||||
public ModbusAsciiProtocolLinker(string com, int slaveAddress)
|
public ModbusAsciiProtocolLinker(string com, int slaveAddress)
|
||||||
: base(com, 9600, Parity.None, StopBits.One, 8, slaveAddress)
|
: base(com, 9600, Parity.None, StopBits.One, 8, slaveAddress)
|
||||||
{
|
{
|
||||||
((BaseConnector)BaseConnector).AddController(new MatchController(new ICollection<(int,int)>[] { new List<(int,int)> { (1,1), (2,2) }, new List<(int, int)> { (3, 3), (4, 4) }}, 0));
|
((BaseConnector)BaseConnector).AddController(new MatchController(new ICollection<(int,int)>[] { new List<(int,int)> { (1,1), (2,2) }, new List<(int, int)> { (3, 3), (4, 4) }}, int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "0")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace Modbus.Net.Modbus
|
|||||||
public ModbusRtuInTcpProtocolLinker(string ip, int port)
|
public ModbusRtuInTcpProtocolLinker(string ip, int port)
|
||||||
: base(ip, port)
|
: base(ip, port)
|
||||||
{
|
{
|
||||||
((BaseConnector)BaseConnector).AddController(new FifoController(0));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "0")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace Modbus.Net.Modbus
|
|||||||
public ModbusRtuInUdpProtocolLinker(string ip, int port)
|
public ModbusRtuInUdpProtocolLinker(string ip, int port)
|
||||||
: base(ip, port)
|
: base(ip, port)
|
||||||
{
|
{
|
||||||
((BaseConnector)BaseConnector).AddController(new FifoController(0));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "0")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Configuration;
|
||||||
using System.IO.Ports;
|
using System.IO.Ports;
|
||||||
|
|
||||||
namespace Modbus.Net.Modbus
|
namespace Modbus.Net.Modbus
|
||||||
@@ -16,7 +17,7 @@ namespace Modbus.Net.Modbus
|
|||||||
public ModbusRtuProtocolLinker(string com, int slaveAddress)
|
public ModbusRtuProtocolLinker(string com, int slaveAddress)
|
||||||
: base(com, 9600, Parity.None, StopBits.One, 8, slaveAddress)
|
: base(com, 9600, Parity.None, StopBits.One, 8, slaveAddress)
|
||||||
{
|
{
|
||||||
((BaseConnector)BaseConnector).AddController(new MatchController(new ICollection<(int,int)>[]{new List<(int,int)>{(0,0)}, new List<(int, int)>{(1,1)}}, 0));
|
((BaseConnector)BaseConnector).AddController(new MatchController(new ICollection<(int,int)>[]{new List<(int,int)>{(0,0)}, new List<(int, int)>{(1,1)}}, int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "0")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace Modbus.Net.Modbus
|
|||||||
/// <param name="port">端口</param>
|
/// <param name="port">端口</param>
|
||||||
public ModbusTcpProtocolLinker(string ip, int port) : base(ip, port)
|
public ModbusTcpProtocolLinker(string ip, int port) : base(ip, port)
|
||||||
{
|
{
|
||||||
((BaseConnector)BaseConnector).AddController(new FifoController(0, true, DuplicateWithCount.GetDuplcateFunc(new List<int>{4,5})));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "0"), true, DuplicateWithCount.GetDuplcateFunc(new List<int>{4,5}, 6)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace Modbus.Net.Modbus
|
|||||||
/// <param name="port">端口</param>
|
/// <param name="port">端口</param>
|
||||||
public ModbusUdpProtocolLinker(string ip, int port) : base(ip, port)
|
public ModbusUdpProtocolLinker(string ip, int port) : base(ip, port)
|
||||||
{
|
{
|
||||||
((BaseConnector)BaseConnector).AddController(new FifoController(0, true, DuplicateWithCount.GetDuplcateFunc(new List<int> { 4, 5 })));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "0"), true, DuplicateWithCount.GetDuplcateFunc(new List<int> { 4, 5 }, 6)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
using System.Configuration;
|
||||||
using System.IO.Ports;
|
using System.IO.Ports;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
|
||||||
namespace Modbus.Net.Siemens
|
namespace Modbus.Net.Siemens
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -18,7 +19,7 @@ namespace Modbus.Net.Siemens
|
|||||||
public SiemensPpiProtocolLinker(string com, int slaveAddress)
|
public SiemensPpiProtocolLinker(string com, int slaveAddress)
|
||||||
: base(com, 9600, Parity.Even, StopBits.One, 8, slaveAddress)
|
: base(com, 9600, Parity.Even, StopBits.One, 8, slaveAddress)
|
||||||
{
|
{
|
||||||
((BaseConnector)BaseConnector).AddController(new FifoController(0));
|
((BaseConnector)BaseConnector).AddController(new FifoController(int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "0")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace Modbus.Net.Siemens
|
|||||||
public SiemensTcpProtocolLinker(string ip, int port)
|
public SiemensTcpProtocolLinker(string ip, int port)
|
||||||
: base(ip, port)
|
: base(ip, port)
|
||||||
{
|
{
|
||||||
((BaseConnector)BaseConnector).AddController(new MatchDirectlySendController(new ICollection<(int,int)>[] { new List<(int,int)> { (11,11), (12,12) } }, DuplicateWithCount.GetDuplcateFunc(new List<int>{2, 3})));
|
((BaseConnector)BaseConnector).AddController(new MatchDirectlySendController(new ICollection<(int,int)>[] { new List<(int,int)> { (11,11), (12,12) } }, int.Parse(ConfigurationManager.AppSettings["FetchSleepTime"] ?? "0"), DuplicateWithCount.GetDuplcateFunc(new List<int>{2, 3}, 0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -11,5 +11,6 @@
|
|||||||
<add key="OpcDaHost" value="opcda://localhost/..." />
|
<add key="OpcDaHost" value="opcda://localhost/..." />
|
||||||
<add key="OpcUaHost" value="opc.tcp://localhost/..." />
|
<add key="OpcUaHost" value="opc.tcp://localhost/..." />
|
||||||
<add key="SiemensPort" value="102" />
|
<add key="SiemensPort" value="102" />
|
||||||
|
<add key="FetchSleepTime" value="100" />
|
||||||
</appSettings>
|
</appSettings>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -17,7 +17,7 @@ namespace Modbus.Net
|
|||||||
/// <param name="receiveMessage">收到的报文信息</param>
|
/// <param name="receiveMessage">收到的报文信息</param>
|
||||||
/// <param name="packageCountPositions">收到的断包长度查询位置</param>
|
/// <param name="packageCountPositions">收到的断包长度查询位置</param>
|
||||||
/// <returns>切分后的报文信息</returns>
|
/// <returns>切分后的报文信息</returns>
|
||||||
private static ICollection<byte[]> DuplicateMessages(byte[] receiveMessage, ICollection<int> packageCountPositions)
|
private static ICollection<byte[]> DuplicateMessages(byte[] receiveMessage, ICollection<int> packageCountPositions, int otherCount)
|
||||||
{
|
{
|
||||||
if (packageCountPositions == null)
|
if (packageCountPositions == null)
|
||||||
return new List<byte[]> { receiveMessage };
|
return new List<byte[]> { receiveMessage };
|
||||||
@@ -32,6 +32,7 @@ namespace Modbus.Net
|
|||||||
{
|
{
|
||||||
length = length * 256 + receiveMessage[pos + countPos];
|
length = length * 256 + receiveMessage[pos + countPos];
|
||||||
}
|
}
|
||||||
|
length += otherCount;
|
||||||
if (pos + length > receiveMessage.Length) break;
|
if (pos + length > receiveMessage.Length) break;
|
||||||
byte[] currentPackage = new byte[length];
|
byte[] currentPackage = new byte[length];
|
||||||
Array.Copy(receiveMessage, pos, currentPackage, 0, length);
|
Array.Copy(receiveMessage, pos, currentPackage, 0, length);
|
||||||
@@ -51,9 +52,9 @@ namespace Modbus.Net
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="packageCountPositions">断包长度的位置信息</param>
|
/// <param name="packageCountPositions">断包长度的位置信息</param>
|
||||||
/// <returns>断包函数</returns>
|
/// <returns>断包函数</returns>
|
||||||
public static Func<byte[], ICollection<byte[]>> GetDuplcateFunc(ICollection<int> packageCountPositions)
|
public static Func<byte[], ICollection<byte[]>> GetDuplcateFunc(ICollection<int> packageCountPositions, int otherCount)
|
||||||
{
|
{
|
||||||
return receiveMessage => DuplicateMessages(receiveMessage, packageCountPositions);
|
return receiveMessage => DuplicateMessages(receiveMessage, packageCountPositions, otherCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ namespace Modbus.Net
|
|||||||
public class MatchDirectlySendController : MatchController
|
public class MatchDirectlySendController : MatchController
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public MatchDirectlySendController(ICollection<(int, int)>[] keyMatches,
|
public MatchDirectlySendController(ICollection<(int, int)>[] keyMatches, int acquireTime,
|
||||||
Func<byte[], ICollection<byte[]>> duplicateFunc = null) : base(keyMatches,
|
Func<byte[], ICollection<byte[]>> duplicateFunc = null) : base(keyMatches,
|
||||||
0, false, duplicateFunc)
|
acquireTime, false, duplicateFunc)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ namespace Modbus.Net
|
|||||||
/// 读取数据
|
/// 读取数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>从设备读取的数据</returns>
|
/// <returns>从设备读取的数据</returns>
|
||||||
Dictionary<string, ReturnUnit> GetDatas(MachineGetDataType getDataType);
|
Dictionary<string, ReturnUnit> GetDatas(MachineDataType getDataType);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 读取数据
|
/// 读取数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>从设备读取的数据</returns>
|
/// <returns>从设备读取的数据</returns>
|
||||||
Task<Dictionary<string, ReturnUnit>> GetDatasAsync(MachineGetDataType getDataType);
|
Task<Dictionary<string, ReturnUnit>> GetDatasAsync(MachineDataType getDataType);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 写入数据
|
/// 写入数据
|
||||||
@@ -33,7 +33,7 @@ namespace Modbus.Net
|
|||||||
/// <param name="setDataType">写入类型</param>
|
/// <param name="setDataType">写入类型</param>
|
||||||
/// <param name="values">需要写入的数据字典,当写入类型为Address时,键为需要写入的地址,当写入类型为CommunicationTag时,键为需要写入的单元的描述</param>
|
/// <param name="values">需要写入的数据字典,当写入类型为Address时,键为需要写入的地址,当写入类型为CommunicationTag时,键为需要写入的单元的描述</param>
|
||||||
/// <returns>是否写入成功</returns>
|
/// <returns>是否写入成功</returns>
|
||||||
bool SetDatas(MachineSetDataType setDataType, Dictionary<string, double> values);
|
bool SetDatas(MachineDataType setDataType, Dictionary<string, double> values);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 写入数据
|
/// 写入数据
|
||||||
@@ -41,6 +41,6 @@ namespace Modbus.Net
|
|||||||
/// <param name="setDataType">写入类型</param>
|
/// <param name="setDataType">写入类型</param>
|
||||||
/// <param name="values">需要写入的数据字典,当写入类型为Address时,键为需要写入的地址,当写入类型为CommunicationTag时,键为需要写入的单元的描述</param>
|
/// <param name="values">需要写入的数据字典,当写入类型为Address时,键为需要写入的地址,当写入类型为CommunicationTag时,键为需要写入的单元的描述</param>
|
||||||
/// <returns>是否写入成功</returns>
|
/// <returns>是否写入成功</returns>
|
||||||
Task<bool> SetDatasAsync(MachineSetDataType setDataType, Dictionary<string, double> values);
|
Task<bool> SetDatasAsync(MachineDataType setDataType, Dictionary<string, double> values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
using Quartz.Listener;
|
||||||
|
using Quartz;
|
||||||
|
using Serilog;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Modbus.Net.Job
|
||||||
|
{
|
||||||
|
public class JobChainingJobListenerWithDataMap : JobListenerSupport
|
||||||
|
{
|
||||||
|
public JobChainingJobListenerWithDataMap(string name, bool overwrite)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
OverWrite = overwrite;
|
||||||
|
chainLinks = new Dictionary<JobKey, JobKey>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly Dictionary<JobKey, JobKey> chainLinks;
|
||||||
|
|
||||||
|
public override string Name { get; }
|
||||||
|
|
||||||
|
public bool OverWrite { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a chain mapping - when the Job identified by the first key completes
|
||||||
|
/// the job identified by the second key will be triggered.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="firstJob">a JobKey with the name and group of the first job</param>
|
||||||
|
/// <param name="secondJob">a JobKey with the name and group of the follow-up job</param>
|
||||||
|
public new void AddJobChainLink(JobKey firstJob, JobKey secondJob)
|
||||||
|
{
|
||||||
|
chainLinks.Add(firstJob, secondJob);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task JobWasExecuted(IJobExecutionContext context,
|
||||||
|
JobExecutionException? jobException,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
chainLinks.TryGetValue(context.JobDetail.Key, out var sj);
|
||||||
|
|
||||||
|
if (sj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.Information("Job '{JobKey}' will now chain to Job '{Job}'", context.JobDetail.Key, sj);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sjJobDetail = await context.Scheduler.GetJobDetail(sj);
|
||||||
|
foreach (var entry in context.JobDetail.JobDataMap)
|
||||||
|
{
|
||||||
|
if (!OverWrite && !sjJobDetail.JobDataMap.ContainsKey(entry.Key))
|
||||||
|
{
|
||||||
|
sjJobDetail.JobDataMap.Put(entry.Key, entry.Value);
|
||||||
|
await context.Scheduler.AddJob(sjJobDetail, true, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await context.Scheduler.TriggerJob(sj, cancellationToken).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (SchedulerException se)
|
||||||
|
{
|
||||||
|
Log.Error(se, "Error encountered during chaining to Job '{Job}'", sj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
197
Modbus.Net/Modbus.Net/Job/MachineJobScheduler.cs
Normal file
197
Modbus.Net/Modbus.Net/Job/MachineJobScheduler.cs
Normal file
@@ -0,0 +1,197 @@
|
|||||||
|
using Modbus.Net.Interface;
|
||||||
|
using Quartz;
|
||||||
|
using Quartz.Impl;
|
||||||
|
using Quartz.Impl.Matchers;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Modbus.Net.Job
|
||||||
|
{
|
||||||
|
public sealed class MachineJobSchedulerCreator
|
||||||
|
{
|
||||||
|
public static async Task<MachineGetJobScheduler> CreateScheduler(int count, int interval)
|
||||||
|
{
|
||||||
|
IScheduler scheduler = await StdSchedulerFactory.GetDefaultScheduler();
|
||||||
|
|
||||||
|
ITrigger trigger;
|
||||||
|
if (count >= 0)
|
||||||
|
trigger = TriggerBuilder.Create()
|
||||||
|
.WithIdentity("Modbus.Net.DataQuery.Trigger", "Modbus.Net.DataQuery.Group")
|
||||||
|
.StartNow()
|
||||||
|
.WithSimpleSchedule(b => b.WithIntervalInSeconds(interval).WithRepeatCount(count))
|
||||||
|
.Build();
|
||||||
|
else
|
||||||
|
trigger = TriggerBuilder.Create()
|
||||||
|
.WithIdentity("Modbus.Net.DataQuery.Trigger", "Modbus.Net.DataQuery.Group")
|
||||||
|
.StartNow()
|
||||||
|
.WithSimpleSchedule(b => b.WithIntervalInSeconds(interval).RepeatForever())
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
return new MachineGetJobScheduler(scheduler, trigger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class MachineGetJobScheduler
|
||||||
|
{
|
||||||
|
IScheduler _scheduler;
|
||||||
|
|
||||||
|
ITrigger _trigger;
|
||||||
|
|
||||||
|
public MachineGetJobScheduler(IScheduler scheduler, ITrigger trigger)
|
||||||
|
{
|
||||||
|
_scheduler = scheduler;
|
||||||
|
_trigger = trigger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<MachineQueryJobScheduler> From(string queryId, IMachineMethodData machine, MachineDataType machineDataType)
|
||||||
|
{
|
||||||
|
JobKey jobKey = JobKey.Create("Modbus.Net.DataQuery.Job." + queryId, "Modbus.Net.DataQuery.Group");
|
||||||
|
|
||||||
|
IJobDetail job = JobBuilder.Create<MachineGetDataJob>()
|
||||||
|
.WithIdentity(jobKey)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
job.JobDataMap.Put("DataType", machineDataType);
|
||||||
|
job.JobDataMap.Put("Machine", machine);
|
||||||
|
|
||||||
|
await _scheduler.ScheduleJob(job, _trigger);
|
||||||
|
|
||||||
|
return new MachineQueryJobScheduler(_scheduler, _trigger, jobKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MachineQueryJobScheduler
|
||||||
|
{
|
||||||
|
IScheduler _scheduler;
|
||||||
|
|
||||||
|
ITrigger _trigger;
|
||||||
|
|
||||||
|
JobKey _parentJobKey;
|
||||||
|
|
||||||
|
public MachineQueryJobScheduler(IScheduler scheduler, ITrigger trigger, JobKey parentJobKey)
|
||||||
|
{
|
||||||
|
_scheduler = scheduler;
|
||||||
|
_trigger = trigger;
|
||||||
|
_parentJobKey = parentJobKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<MachineSetJobScheduler> Query(string queryId = null, Func<Dictionary<string, ReturnUnit>, Dictionary<string, ReturnUnit>> QueryDataFunc = null)
|
||||||
|
{
|
||||||
|
JobChainingJobListenerWithDataMap listener = new JobChainingJobListenerWithDataMap("Modbus.Net.DataQuery.Chain", false);
|
||||||
|
_scheduler.ListenerManager.AddJobListener(listener, GroupMatcher<JobKey>.GroupEquals("Modbus.Net.DataQuery.Group"));
|
||||||
|
|
||||||
|
if (queryId == null) return new MachineSetJobScheduler(_scheduler, _trigger, listener, _parentJobKey);
|
||||||
|
|
||||||
|
JobKey jobKey = JobKey.Create("Modbus.Net.DataQuery.Job." + queryId, "Modbus.Net.DataQuery.Group");
|
||||||
|
|
||||||
|
IJobDetail job = JobBuilder.Create<MachineQueryDataJob>()
|
||||||
|
.WithIdentity(jobKey)
|
||||||
|
.StoreDurably(true)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
job.JobDataMap.Put("QueryMethod", QueryDataFunc);
|
||||||
|
|
||||||
|
listener.AddJobChainLink(_parentJobKey, jobKey);
|
||||||
|
|
||||||
|
await _scheduler.AddJob(job, true);
|
||||||
|
|
||||||
|
return new MachineSetJobScheduler(_scheduler, _trigger, listener, jobKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MachineSetJobScheduler
|
||||||
|
{
|
||||||
|
IScheduler _scheduler;
|
||||||
|
|
||||||
|
ITrigger _trigger;
|
||||||
|
|
||||||
|
JobChainingJobListenerWithDataMap _listener;
|
||||||
|
|
||||||
|
JobKey _parentJobKey;
|
||||||
|
|
||||||
|
public MachineSetJobScheduler(IScheduler scheduler, ITrigger trigger, JobChainingJobListenerWithDataMap listener, JobKey parentJobKey)
|
||||||
|
{
|
||||||
|
_scheduler = scheduler;
|
||||||
|
|
||||||
|
_trigger = trigger;
|
||||||
|
|
||||||
|
_listener = listener;
|
||||||
|
|
||||||
|
_parentJobKey = parentJobKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<MachineSetJobScheduler> To(string queryId, IMachineMethodData machine)
|
||||||
|
{
|
||||||
|
JobKey jobKey = JobKey.Create("Modbus.Net.DataQuery.Job." + queryId, "Modbus.Net.DataQuery.Group");
|
||||||
|
|
||||||
|
IJobDetail job = JobBuilder.Create<MachineSetDataJob>()
|
||||||
|
.WithIdentity(jobKey)
|
||||||
|
.StoreDurably(true)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
job.JobDataMap.Put("Machine", machine);
|
||||||
|
|
||||||
|
_listener.AddJobChainLink(_parentJobKey, jobKey);
|
||||||
|
|
||||||
|
await _scheduler.AddJob(job, true);
|
||||||
|
|
||||||
|
return new MachineSetJobScheduler(_scheduler, _trigger, _listener, jobKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task Run()
|
||||||
|
{
|
||||||
|
await _scheduler.Start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MachineGetDataJob : IJob
|
||||||
|
{
|
||||||
|
public async Task Execute(IJobExecutionContext context)
|
||||||
|
{
|
||||||
|
object machine;
|
||||||
|
object machineDataType;
|
||||||
|
context.MergedJobDataMap.TryGetValue("Machine", out machine);
|
||||||
|
context.MergedJobDataMap.TryGetValue("DataType", out machineDataType);
|
||||||
|
var values = await (machine as IMachineMethodData)!.GetDatasAsync((MachineDataType)machineDataType);
|
||||||
|
|
||||||
|
context.JobDetail.JobDataMap.Put("Value", values);
|
||||||
|
await context.Scheduler.AddJob(context.JobDetail, true, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MachineQueryDataJob : IJob
|
||||||
|
{
|
||||||
|
public async Task Execute(IJobExecutionContext context)
|
||||||
|
{
|
||||||
|
object values;
|
||||||
|
object QueryMethod;
|
||||||
|
|
||||||
|
context.MergedJobDataMap.TryGetValue("Value", out values);
|
||||||
|
context.MergedJobDataMap.TryGetValue("QueryMethod", out QueryMethod);
|
||||||
|
Func<Dictionary<string, ReturnUnit>, Dictionary<string, ReturnUnit>> QueryMethodDispatch = (Func<Dictionary<string, ReturnUnit>, Dictionary<string, ReturnUnit>>)QueryMethod;
|
||||||
|
|
||||||
|
if (QueryMethod != null)
|
||||||
|
{
|
||||||
|
context.JobDetail.JobDataMap.Put("Value", QueryMethodDispatch((Dictionary<string, ReturnUnit>)values));
|
||||||
|
await context.Scheduler.AddJob(context.JobDetail, true, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MachineSetDataJob : IJob
|
||||||
|
{
|
||||||
|
public async Task Execute(IJobExecutionContext context)
|
||||||
|
{
|
||||||
|
object machine;
|
||||||
|
object machineDataType;
|
||||||
|
object values;
|
||||||
|
context.MergedJobDataMap.TryGetValue("Machine", out machine);
|
||||||
|
context.MergedJobDataMap.TryGetValue("DataType", out machineDataType);
|
||||||
|
context.MergedJobDataMap.TryGetValue("Value", out values);
|
||||||
|
Dictionary<string, double> valuesSet = ((Dictionary<string, ReturnUnit>)values).MapGetValuesToSetValues();
|
||||||
|
|
||||||
|
var success = await (machine as IMachine<string>)!.SetDatasAsync((MachineDataType)machineDataType, valuesSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,58 +33,6 @@ namespace Modbus.Net
|
|||||||
Id
|
Id
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取设备值的方式
|
|
||||||
/// </summary>
|
|
||||||
public enum MachineGetDataType
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 地址
|
|
||||||
/// </summary>
|
|
||||||
Address,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 通讯标识
|
|
||||||
/// </summary>
|
|
||||||
CommunicationTag,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 名称
|
|
||||||
/// </summary>
|
|
||||||
Name,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Id
|
|
||||||
/// </summary>
|
|
||||||
Id
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 向设备设置值的方式
|
|
||||||
/// </summary>
|
|
||||||
public enum MachineSetDataType
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 地址
|
|
||||||
/// </summary>
|
|
||||||
Address,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 通讯标识
|
|
||||||
/// </summary>
|
|
||||||
CommunicationTag,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 名称
|
|
||||||
/// </summary>
|
|
||||||
Name,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Id
|
|
||||||
/// </summary>
|
|
||||||
Id
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备
|
/// 设备
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -244,7 +192,7 @@ namespace Modbus.Net
|
|||||||
/// 读取数据
|
/// 读取数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>从设备读取的数据</returns>
|
/// <returns>从设备读取的数据</returns>
|
||||||
public Dictionary<string, ReturnUnit> GetDatas(MachineGetDataType getDataType)
|
public Dictionary<string, ReturnUnit> GetDatas(MachineDataType getDataType)
|
||||||
{
|
{
|
||||||
return AsyncHelper.RunSync(() => GetDatasAsync(getDataType));
|
return AsyncHelper.RunSync(() => GetDatasAsync(getDataType));
|
||||||
}
|
}
|
||||||
@@ -254,7 +202,7 @@ namespace Modbus.Net
|
|||||||
/// 读取数据
|
/// 读取数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>从设备读取的数据</returns>
|
/// <returns>从设备读取的数据</returns>
|
||||||
public async Task<Dictionary<string, ReturnUnit>> GetDatasAsync(MachineGetDataType getDataType)
|
public async Task<Dictionary<string, ReturnUnit>> GetDatasAsync(MachineDataType getDataType)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -304,22 +252,22 @@ namespace Modbus.Net
|
|||||||
string key;
|
string key;
|
||||||
switch (getDataType)
|
switch (getDataType)
|
||||||
{
|
{
|
||||||
case MachineGetDataType.CommunicationTag:
|
case MachineDataType.CommunicationTag:
|
||||||
{
|
{
|
||||||
key = address.CommunicationTag;
|
key = address.CommunicationTag;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MachineGetDataType.Address:
|
case MachineDataType.Address:
|
||||||
{
|
{
|
||||||
key = AddressFormater.FormatAddress(address.Area, address.Address, address.SubAddress);
|
key = AddressFormater.FormatAddress(address.Area, address.Address, address.SubAddress);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MachineGetDataType.Name:
|
case MachineDataType.Name:
|
||||||
{
|
{
|
||||||
key = address.Name;
|
key = address.Name;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MachineGetDataType.Id:
|
case MachineDataType.Id:
|
||||||
{
|
{
|
||||||
key = address.Id.ToString();
|
key = address.Id.ToString();
|
||||||
break;
|
break;
|
||||||
@@ -337,14 +285,14 @@ namespace Modbus.Net
|
|||||||
if (datas.Length == 0)
|
if (datas.Length == 0)
|
||||||
ans.Add(key, new ReturnUnit
|
ans.Add(key, new ReturnUnit
|
||||||
{
|
{
|
||||||
PlcValue = null,
|
DeviceValue = null,
|
||||||
UnitExtend = address.UnitExtend
|
UnitExtend = address.UnitExtend
|
||||||
});
|
});
|
||||||
else
|
else
|
||||||
ans.Add(key,
|
ans.Add(key,
|
||||||
new ReturnUnit
|
new ReturnUnit
|
||||||
{
|
{
|
||||||
PlcValue =
|
DeviceValue =
|
||||||
Convert.ToDouble(
|
Convert.ToDouble(
|
||||||
ValueHelper.GetInstance(BaseUtility.Endian)
|
ValueHelper.GetInstance(BaseUtility.Endian)
|
||||||
.GetValue(datas, ref localMainPos, ref localSubPos,
|
.GetValue(datas, ref localMainPos, ref localSubPos,
|
||||||
@@ -367,7 +315,7 @@ namespace Modbus.Net
|
|||||||
if (!KeepConnect)
|
if (!KeepConnect)
|
||||||
BaseUtility.Disconnect();
|
BaseUtility.Disconnect();
|
||||||
//返回数据
|
//返回数据
|
||||||
if (ans.All(p => p.Value.PlcValue == null)) ans = null;
|
if (ans.All(p => p.Value.DeviceValue == null)) ans = null;
|
||||||
ErrorCount = 0;
|
ErrorCount = 0;
|
||||||
return ans;
|
return ans;
|
||||||
}
|
}
|
||||||
@@ -388,7 +336,7 @@ namespace Modbus.Net
|
|||||||
/// <param name="setDataType">写入类型</param>
|
/// <param name="setDataType">写入类型</param>
|
||||||
/// <param name="values">需要写入的数据字典,当写入类型为Address时,键为需要写入的地址,当写入类型为CommunicationTag时,键为需要写入的单元的描述</param>
|
/// <param name="values">需要写入的数据字典,当写入类型为Address时,键为需要写入的地址,当写入类型为CommunicationTag时,键为需要写入的单元的描述</param>
|
||||||
/// <returns>是否写入成功</returns>
|
/// <returns>是否写入成功</returns>
|
||||||
public bool SetDatas(MachineSetDataType setDataType, Dictionary<string, double> values)
|
public bool SetDatas(MachineDataType setDataType, Dictionary<string, double> values)
|
||||||
{
|
{
|
||||||
return AsyncHelper.RunSync(() => SetDatasAsync(setDataType, values));
|
return AsyncHelper.RunSync(() => SetDatasAsync(setDataType, values));
|
||||||
}
|
}
|
||||||
@@ -399,7 +347,7 @@ namespace Modbus.Net
|
|||||||
/// <param name="setDataType">写入类型</param>
|
/// <param name="setDataType">写入类型</param>
|
||||||
/// <param name="values">需要写入的数据字典,当写入类型为Address时,键为需要写入的地址,当写入类型为CommunicationTag时,键为需要写入的单元的描述</param>
|
/// <param name="values">需要写入的数据字典,当写入类型为Address时,键为需要写入的地址,当写入类型为CommunicationTag时,键为需要写入的单元的描述</param>
|
||||||
/// <returns>是否写入成功</returns>
|
/// <returns>是否写入成功</returns>
|
||||||
public async Task<bool> SetDatasAsync(MachineSetDataType setDataType, Dictionary<string, double> values)
|
public async Task<bool> SetDatasAsync(MachineDataType setDataType, Dictionary<string, double> values)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -416,7 +364,7 @@ namespace Modbus.Net
|
|||||||
AddressUnit<TUnitKey> address = null;
|
AddressUnit<TUnitKey> address = null;
|
||||||
switch (setDataType)
|
switch (setDataType)
|
||||||
{
|
{
|
||||||
case MachineSetDataType.Address:
|
case MachineDataType.Address:
|
||||||
{
|
{
|
||||||
address =
|
address =
|
||||||
GetAddresses.SingleOrDefault(
|
GetAddresses.SingleOrDefault(
|
||||||
@@ -426,18 +374,18 @@ namespace Modbus.Net
|
|||||||
AddressFormater.FormatAddress(p.Area, p.Address) == value.Key);
|
AddressFormater.FormatAddress(p.Area, p.Address) == value.Key);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MachineSetDataType.CommunicationTag:
|
case MachineDataType.CommunicationTag:
|
||||||
{
|
{
|
||||||
address =
|
address =
|
||||||
GetAddresses.SingleOrDefault(p => p.CommunicationTag == value.Key);
|
GetAddresses.SingleOrDefault(p => p.CommunicationTag == value.Key);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MachineSetDataType.Name:
|
case MachineDataType.Name:
|
||||||
{
|
{
|
||||||
address = GetAddresses.SingleOrDefault(p => p.Name == value.Key);
|
address = GetAddresses.SingleOrDefault(p => p.Name == value.Key);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MachineSetDataType.Id:
|
case MachineDataType.Id:
|
||||||
{
|
{
|
||||||
address = GetAddresses.SingleOrDefault(p => p.Id.ToString() == value.Key);
|
address = GetAddresses.SingleOrDefault(p => p.Id.ToString() == value.Key);
|
||||||
break;
|
break;
|
||||||
@@ -526,7 +474,7 @@ namespace Modbus.Net
|
|||||||
KeyValuePair<string, double> value;
|
KeyValuePair<string, double> value;
|
||||||
switch (setDataType)
|
switch (setDataType)
|
||||||
{
|
{
|
||||||
case MachineSetDataType.Address:
|
case MachineDataType.Address:
|
||||||
{
|
{
|
||||||
//获取要写入的值
|
//获取要写入的值
|
||||||
value =
|
value =
|
||||||
@@ -534,17 +482,17 @@ namespace Modbus.Net
|
|||||||
p => p.Key == address || address2 != null && p.Key == address2);
|
p => p.Key == address || address2 != null && p.Key == address2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MachineSetDataType.CommunicationTag:
|
case MachineDataType.CommunicationTag:
|
||||||
{
|
{
|
||||||
value = values.SingleOrDefault(p => p.Key == addressUnit.CommunicationTag);
|
value = values.SingleOrDefault(p => p.Key == addressUnit.CommunicationTag);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MachineSetDataType.Name:
|
case MachineDataType.Name:
|
||||||
{
|
{
|
||||||
value = values.SingleOrDefault(p => p.Key == addressUnit.Name);
|
value = values.SingleOrDefault(p => p.Key == addressUnit.Name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MachineSetDataType.Id:
|
case MachineDataType.Id:
|
||||||
{
|
{
|
||||||
value = values.SingleOrDefault(p => p.Key == addressUnit.Id.ToString());
|
value = values.SingleOrDefault(p => p.Key == addressUnit.Id.ToString());
|
||||||
break;
|
break;
|
||||||
@@ -760,7 +708,7 @@ namespace Modbus.Net
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 返回的数据
|
/// 返回的数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double? PlcValue { get; set; }
|
public double? DeviceValue { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 数据的扩展
|
/// 数据的扩展
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ namespace Modbus.Net
|
|||||||
{
|
{
|
||||||
if (getValues == null) return null;
|
if (getValues == null) return null;
|
||||||
return (from getValue in getValues
|
return (from getValue in getValues
|
||||||
where getValue.Value.PlcValue != null
|
where getValue.Value.DeviceValue != null
|
||||||
select new KeyValuePair<string, double>(getValue.Key, getValue.Value.PlcValue.Value)).ToDictionary(
|
select new KeyValuePair<string, double>(getValue.Key, getValue.Value.DeviceValue.Value)).ToDictionary(
|
||||||
p => p.Key, p => p.Value);
|
p => p.Key, p => p.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||||
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
|
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
|
||||||
|
<PackageReference Include="Quartz" Version="3.6.0" />
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
|
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
|
||||||
<PackageReference Include="System.IO.Ports" Version="7.0.0" />
|
<PackageReference Include="System.IO.Ports" Version="7.0.0" />
|
||||||
|
|||||||
@@ -156,10 +156,10 @@ machine = new ModbusMachine(ModbusType.Rtu, "COM3", new List<AddressUnit>()
|
|||||||
machine.AddressCombiner = new AddressCombinerContinus(machine.AddressTranslator);
|
machine.AddressCombiner = new AddressCombinerContinus(machine.AddressTranslator);
|
||||||
machine.AddressCombinerSet = new AddressCombinerContinus(machine.AddressTranslator);
|
machine.AddressCombinerSet = new AddressCombinerContinus(machine.AddressTranslator);
|
||||||
machine.AddressCombiner = new AddressCombinerPercentageJump(20.0);
|
machine.AddressCombiner = new AddressCombinerPercentageJump(20.0);
|
||||||
var result = machine.InvokeMachineMethods<IMachineMethodData>?.GetDatas(MachineGetDataType.CommunicationTag);
|
var result = machine.InvokeMachineMethods<IMachineMethodData>?.GetDatas(MachineDataType.CommunicationTag);
|
||||||
var add1 = result["Add1"].PlcValue;
|
var add1 = result["Add1"].DeviceValue;
|
||||||
var resultFormat = result.MapGetValuesToSetValues();
|
var resultFormat = result.MapGetValuesToSetValues();
|
||||||
machine.InvokeMachineMethods<IMachineMethodData>?.SetDatas(MachineSetDataType.CommunicationTag, resultFormat);
|
machine.InvokeMachineMethods<IMachineMethodData>?.SetDatas(MachineDataType.CommunicationTag, resultFormat);
|
||||||
```
|
```
|
||||||
|
|
||||||
To use BaseMachine, follow these steps.
|
To use BaseMachine, follow these steps.
|
||||||
@@ -196,13 +196,13 @@ There are 4 AddressCombiners implemented in the platform.
|
|||||||
|
|
||||||
3.Use GetDatas Api.
|
3.Use GetDatas Api.
|
||||||
```C#
|
```C#
|
||||||
var result = machine.InvokeMachineMethods<IMachineMethodData>?.GetDatas(MachineGetDataType.CommunicationTag);
|
var result = machine.InvokeMachineMethods<IMachineMethodData>?.GetDatas(MachineDataType.CommunicationTag);
|
||||||
//var result = await machine.InvokeMachineMethods<IMachineMethodData>?.GetDatasAsync(MachineGetDataType.CommunicationTag);
|
//var result = await machine.InvokeMachineMethods<IMachineMethodData>?.GetDatasAsync(MachineDataType.CommunicationTag);
|
||||||
```
|
```
|
||||||
|
|
||||||
4.Retrive data from result.
|
4.Retrive data from result.
|
||||||
```C#
|
```C#
|
||||||
var add1 = result["Add1"].PlcValue;
|
var add1 = result["Add1"].DeviceValue;
|
||||||
```
|
```
|
||||||
|
|
||||||
5.Format result to SetData parameter.
|
5.Format result to SetData parameter.
|
||||||
@@ -212,15 +212,15 @@ var resultFormat = result.MapGetValuesToSetValues();
|
|||||||
|
|
||||||
6.SetData to machine or another machine.
|
6.SetData to machine or another machine.
|
||||||
```C#
|
```C#
|
||||||
machine.InvokeMachineMethods<IMachineMethodData>?.SetDatas(MachineSetDataType.CommunicationTag, resultFormat);
|
machine.InvokeMachineMethods<IMachineMethodData>?.SetDatas(MachineDataType.CommunicationTag, resultFormat);
|
||||||
```
|
```
|
||||||
There is also a SetDatasAsync Api.
|
There is also a SetDatasAsync Api.
|
||||||
machine.SetDatas has four types. It is referenced as the first parameter.
|
machine.SetDatas has four types. It is referenced as the first parameter.
|
||||||
|
|
||||||
1. MachineSetDataType.Address: the key of the dictionary of the second parameter is address.
|
1. MachineDataType.Address: the key of the dictionary of the second parameter is address.
|
||||||
2. MachineSetDataType.CommunicationTag: the key of the dictionary of the second parameter is communication tag.
|
2. MachineDataType.CommunicationTag: the key of the dictionary of the second parameter is communication tag.
|
||||||
3. MachineSetDataType.Id: the key of the dictionary of the second paramenter is ID.
|
3. MachineDataType.Id: the key of the dictionary of the second paramenter is ID.
|
||||||
4. MachineSetDataType.Name: the key of the dictionary of the second paramenter is name.
|
4. MachineDataType.Name: the key of the dictionary of the second paramenter is name.
|
||||||
|
|
||||||
##<a name="implement"></a> Implementing Your Own Protocol
|
##<a name="implement"></a> 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.
|
The main target of Modbus.Net is building a high extensable hardware communication protocol, so we allow everyone to extend the protocol.
|
||||||
|
|||||||
@@ -7,10 +7,6 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Quartz.Jobs" Version="3.6.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Modbus.Net\Modbus.Net.Modbus\Modbus.Net.Modbus.csproj" />
|
<ProjectReference Include="..\..\Modbus.Net\Modbus.Net.Modbus\Modbus.Net.Modbus.csproj" />
|
||||||
<ProjectReference Include="..\..\Modbus.Net\Modbus.Net\Modbus.Net.csproj" />
|
<ProjectReference Include="..\..\Modbus.Net\Modbus.Net\Modbus.Net.csproj" />
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
using Modbus.Net;
|
using Modbus.Net;
|
||||||
using Modbus.Net.Modbus;
|
using Modbus.Net.Modbus;
|
||||||
using Modbus.Net.Interface;
|
using Modbus.Net.Interface;
|
||||||
using Quartz;
|
using Modbus.Net.Job;
|
||||||
using Quartz.Impl;
|
|
||||||
|
|
||||||
List<AddressUnit> _addresses = new List<AddressUnit>
|
List<AddressUnit> _addresses = new List<AddressUnit>
|
||||||
{
|
{
|
||||||
@@ -19,63 +18,21 @@ List<AddressUnit> _addresses = new List<AddressUnit>
|
|||||||
new AddressUnit() { Area = "4X", Address = 10, DataType = typeof(short), Id = "10", Name = "Test10" }
|
new AddressUnit() { Area = "4X", Address = 10, DataType = typeof(short), Id = "10", Name = "Test10" }
|
||||||
};
|
};
|
||||||
|
|
||||||
IMachine<string> machine = new ModbusMachine<string, string>("ModbusMachine1", ModbusType.Tcp, "192.168.0.172:502", _addresses, true, 2, 1, Endian.BigEndianLsb);
|
IMachine<string> machine = new ModbusMachine<string, string>("ModbusMachine1", ModbusType.Tcp, "192.168.0.172:502", _addresses, true, 1, 2, Endian.BigEndianLsb);
|
||||||
|
|
||||||
|
await MachineJobSchedulerCreator.CreateScheduler(-1, 5).Result.From(machine.Id, machine, MachineDataType.Name).Result.Query("ConsoleQuery", QueryConsole).Result.To(machine.Id + ".To", machine).Result.Run();
|
||||||
//1.首先创建一个作业调度池
|
|
||||||
ISchedulerFactory schedf = new StdSchedulerFactory();
|
|
||||||
//2.实例化调度器工厂
|
|
||||||
ISchedulerFactory schedulefactory = new StdSchedulerFactory();
|
|
||||||
//3.实例化调度器
|
|
||||||
IScheduler scheduler = await schedulefactory.GetScheduler();
|
|
||||||
|
|
||||||
//4.创建一个作业
|
|
||||||
IJobDetail job1 = JobBuilder.Create<Class1>()
|
|
||||||
.WithIdentity("demojob1", "groupa")
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
//5.1:第一种方法直接写死多少秒执行一次
|
|
||||||
//ITrigger trigger1 = TriggerBuilder.Create()//创建一个触发器
|
|
||||||
// .WithIdentity("demotrigger1", "groupa")
|
|
||||||
// .StartNow()
|
|
||||||
// .WithSimpleSchedule(b => b.WithIntervalInSeconds(5)//5秒执行一次
|
|
||||||
// .RepeatForever())//无限循环执行
|
|
||||||
// .Build();
|
|
||||||
|
|
||||||
//5.2推荐:第二种使用cron表达式
|
|
||||||
//在线生成cron表达式: http://cron.qqe2.com/
|
|
||||||
string corn = "*/5 * * * * ?";
|
|
||||||
ITrigger trigger1 = TriggerBuilder.Create()
|
|
||||||
.WithIdentity("demotrigger1", "groupa")
|
|
||||||
.WithCronSchedule(corn)//每一小时执行一次
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
//6.添加参数(键值对),如果不需要传参则忽略这一步
|
|
||||||
//方法内获取你传的参数: string Name = context.Trigger.JobDataMap.GetString("Name");
|
|
||||||
trigger1.JobDataMap.Add("Machine", machine);
|
|
||||||
|
|
||||||
//7.把作业,触发器加入调度器
|
|
||||||
await scheduler.ScheduleJob(job1, trigger1);
|
|
||||||
//8.开始运行
|
|
||||||
await scheduler.Start();
|
|
||||||
|
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
|
|
||||||
public class Class1 : IJob
|
Dictionary<string, ReturnUnit> QueryConsole(Dictionary<string, ReturnUnit> values)
|
||||||
{
|
{
|
||||||
public async Task Execute(IJobExecutionContext context)
|
|
||||||
{
|
|
||||||
object machine;
|
|
||||||
context.Trigger.JobDataMap.TryGetValue("Machine", out machine);
|
|
||||||
var values = await (machine as IMachine<string>)!.GetDatasAsync(MachineGetDataType.Name);
|
|
||||||
if (values != null)
|
|
||||||
{
|
|
||||||
foreach (var value in values)
|
foreach (var value in values)
|
||||||
{
|
{
|
||||||
Console.WriteLine(value.Key + " " + value.Value.PlcValue);
|
Console.WriteLine(value.Key + " " + value.Value.DeviceValue);
|
||||||
}
|
value.Value.DeviceValue = new Random().Next(65536) - 32768;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -50,11 +50,11 @@ namespace Modbus.Net.Tests
|
|||||||
|
|
||||||
_modbusTcpMachine.GetAddresses = addresses;
|
_modbusTcpMachine.GetAddresses = addresses;
|
||||||
_modbusTcpMachine2.GetAddresses = addresses;
|
_modbusTcpMachine2.GetAddresses = addresses;
|
||||||
await _modbusTcpMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
await _modbusTcpMachine.SetDatasAsync(MachineDataType.Address, dic1);
|
||||||
var ans = await _modbusTcpMachine.GetDatasAsync(MachineGetDataType.Address);
|
var ans = await _modbusTcpMachine.GetDatasAsync(MachineDataType.Address);
|
||||||
var ans2 = await _modbusTcpMachine2.GetDatasAsync(MachineGetDataType.Address);
|
var ans2 = await _modbusTcpMachine2.GetDatasAsync(MachineDataType.Address);
|
||||||
Assert.AreEqual(ans["4X 1.0"].PlcValue, dic1["4X 1"]);
|
Assert.AreEqual(ans["4X 1.0"].DeviceValue, dic1["4X 1"]);
|
||||||
Assert.AreEqual(ans2["4X 1.0"].PlcValue, (ushort)dic1["4X 1"] % 256 * 256 + (ushort)dic1["4X 1"] / 256);
|
Assert.AreEqual(ans2["4X 1.0"].DeviceValue, (ushort)dic1["4X 1"] % 256 * 256 + (ushort)dic1["4X 1"] / 256);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace Modbus.Net.Tests
|
|||||||
}
|
}
|
||||||
}, true, 2, 0);
|
}, true, 2, 0);
|
||||||
var success = await baseMachine.GetMachineMethods<IMachineMethodData>().SetDatasAsync(
|
var success = await baseMachine.GetMachineMethods<IMachineMethodData>().SetDatasAsync(
|
||||||
MachineSetDataType.Address,
|
MachineDataType.Address,
|
||||||
new Dictionary<string, double>
|
new Dictionary<string, double>
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@@ -57,10 +57,10 @@ namespace Modbus.Net.Tests
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
Assert.AreEqual(success, true);
|
Assert.AreEqual(success, true);
|
||||||
var datas = await baseMachine.GetMachineMethods<IMachineMethodData>().GetDatasAsync(MachineGetDataType.Address);
|
var datas = await baseMachine.GetMachineMethods<IMachineMethodData>().GetDatasAsync(MachineDataType.Address);
|
||||||
Assert.AreEqual(datas["0X 1.0"].PlcValue, 1);
|
Assert.AreEqual(datas["0X 1.0"].DeviceValue, 1);
|
||||||
success = await baseMachine.GetMachineMethods<IMachineMethodData>().SetDatasAsync(
|
success = await baseMachine.GetMachineMethods<IMachineMethodData>().SetDatasAsync(
|
||||||
MachineSetDataType.Address,
|
MachineDataType.Address,
|
||||||
new Dictionary<string, double>
|
new Dictionary<string, double>
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -130,27 +130,27 @@ namespace Modbus.Net.Tests
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await _modbusRtuMachine1.SetDatasAsync(MachineSetDataType.CommunicationTag, dic1);
|
await _modbusRtuMachine1.SetDatasAsync(MachineDataType.CommunicationTag, dic1);
|
||||||
await _modbusRtuMachine2.SetDatasAsync(MachineSetDataType.CommunicationTag, dic2);
|
await _modbusRtuMachine2.SetDatasAsync(MachineDataType.CommunicationTag, dic2);
|
||||||
|
|
||||||
var ans = await _modbusRtuMachine1.GetDatasAsync(MachineGetDataType.CommunicationTag);
|
var ans = await _modbusRtuMachine1.GetDatasAsync(MachineDataType.CommunicationTag);
|
||||||
var ans2 = await _modbusRtuMachine2.GetDatasAsync(MachineGetDataType.CommunicationTag);
|
var ans2 = await _modbusRtuMachine2.GetDatasAsync(MachineDataType.CommunicationTag);
|
||||||
|
|
||||||
_modbusRtuMachine1.Disconnect();
|
_modbusRtuMachine1.Disconnect();
|
||||||
_modbusRtuMachine2.Disconnect();
|
_modbusRtuMachine2.Disconnect();
|
||||||
|
|
||||||
Assert.AreEqual(ans["A1"].PlcValue, dic1["A1"]);
|
Assert.AreEqual(ans["A1"].DeviceValue, dic1["A1"]);
|
||||||
Assert.AreEqual(ans2["A1"].PlcValue, dic2["A1"]);
|
Assert.AreEqual(ans2["A1"].DeviceValue, dic2["A1"]);
|
||||||
Assert.AreEqual(ans["A2"].PlcValue, dic1["A2"]);
|
Assert.AreEqual(ans["A2"].DeviceValue, dic1["A2"]);
|
||||||
Assert.AreEqual(ans2["A2"].PlcValue, dic2["A2"]);
|
Assert.AreEqual(ans2["A2"].DeviceValue, dic2["A2"]);
|
||||||
Assert.AreEqual(ans["A3"].PlcValue, dic1["A3"]);
|
Assert.AreEqual(ans["A3"].DeviceValue, dic1["A3"]);
|
||||||
Assert.AreEqual(ans2["A3"].PlcValue, dic2["A3"]);
|
Assert.AreEqual(ans2["A3"].DeviceValue, dic2["A3"]);
|
||||||
Assert.AreEqual(ans["A4"].PlcValue, dic1["A4"]);
|
Assert.AreEqual(ans["A4"].DeviceValue, dic1["A4"]);
|
||||||
Assert.AreEqual(ans2["A4"].PlcValue, dic2["A4"]);
|
Assert.AreEqual(ans2["A4"].DeviceValue, dic2["A4"]);
|
||||||
Assert.AreEqual(ans["A5"].PlcValue, dic1["A5"]);
|
Assert.AreEqual(ans["A5"].DeviceValue, dic1["A5"]);
|
||||||
Assert.AreEqual(ans2["A5"].PlcValue, dic2["A5"]);
|
Assert.AreEqual(ans2["A5"].DeviceValue, dic2["A5"]);
|
||||||
Assert.AreEqual(ans["A6"].PlcValue, dic1["A6"]);
|
Assert.AreEqual(ans["A6"].DeviceValue, dic1["A6"]);
|
||||||
Assert.AreEqual(ans2["A6"].PlcValue, dic2["A6"]);
|
Assert.AreEqual(ans2["A6"].DeviceValue, dic2["A6"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,15 +53,15 @@ namespace Modbus.Net.Tests
|
|||||||
_modbusTcpMachine.GetAddresses = addresses;
|
_modbusTcpMachine.GetAddresses = addresses;
|
||||||
_modbusAsciiMachine.GetAddresses = addresses;
|
_modbusAsciiMachine.GetAddresses = addresses;
|
||||||
_modbusRtuMachine.GetAddresses = addresses;
|
_modbusRtuMachine.GetAddresses = addresses;
|
||||||
await _modbusTcpMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
await _modbusTcpMachine.SetDatasAsync(MachineDataType.Address, dic1);
|
||||||
await _modbusAsciiMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
await _modbusAsciiMachine.SetDatasAsync(MachineDataType.Address, dic1);
|
||||||
await _modbusRtuMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
await _modbusRtuMachine.SetDatasAsync(MachineDataType.Address, dic1);
|
||||||
var ans = await _modbusTcpMachine.GetDatasAsync(MachineGetDataType.Address);
|
var ans = await _modbusTcpMachine.GetDatasAsync(MachineDataType.Address);
|
||||||
var ans2 = await _modbusRtuMachine.GetDatasAsync(MachineGetDataType.Address);
|
var ans2 = await _modbusRtuMachine.GetDatasAsync(MachineDataType.Address);
|
||||||
var ans3 = await _modbusAsciiMachine.GetDatasAsync(MachineGetDataType.Address);
|
var ans3 = await _modbusAsciiMachine.GetDatasAsync(MachineDataType.Address);
|
||||||
Assert.AreEqual(ans["0X 1.0"].PlcValue, dic1["0X 1.0"]);
|
Assert.AreEqual(ans["0X 1.0"].DeviceValue, dic1["0X 1.0"]);
|
||||||
Assert.AreEqual(ans2["0X 1.0"].PlcValue, dic1["0X 1.0"]);
|
Assert.AreEqual(ans2["0X 1.0"].DeviceValue, dic1["0X 1.0"]);
|
||||||
Assert.AreEqual(ans3["0X 1.0"].PlcValue, dic1["0X 1.0"]);
|
Assert.AreEqual(ans3["0X 1.0"].DeviceValue, dic1["0X 1.0"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -83,12 +83,12 @@ namespace Modbus.Net.Tests
|
|||||||
_modbusTcpMachine.GetAddresses = addresses;
|
_modbusTcpMachine.GetAddresses = addresses;
|
||||||
_modbusRtuMachine.GetAddresses = addresses;
|
_modbusRtuMachine.GetAddresses = addresses;
|
||||||
_modbusAsciiMachine.GetAddresses = addresses;
|
_modbusAsciiMachine.GetAddresses = addresses;
|
||||||
var ans = await _modbusTcpMachine.GetDatasAsync(MachineGetDataType.Address);
|
var ans = await _modbusTcpMachine.GetDatasAsync(MachineDataType.Address);
|
||||||
var ans2 = await _modbusRtuMachine.GetDatasAsync(MachineGetDataType.Address);
|
var ans2 = await _modbusRtuMachine.GetDatasAsync(MachineDataType.Address);
|
||||||
var ans3 = await _modbusAsciiMachine.GetDatasAsync(MachineGetDataType.Address);
|
var ans3 = await _modbusAsciiMachine.GetDatasAsync(MachineDataType.Address);
|
||||||
Assert.AreEqual(ans["1X 1.0"].PlcValue, 0);
|
Assert.AreEqual(ans["1X 1.0"].DeviceValue, 0);
|
||||||
Assert.AreEqual(ans2["1X 1.0"].PlcValue, 0);
|
Assert.AreEqual(ans2["1X 1.0"].DeviceValue, 0);
|
||||||
Assert.AreEqual(ans3["1X 1.0"].PlcValue, 0);
|
Assert.AreEqual(ans3["1X 1.0"].DeviceValue, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -110,12 +110,12 @@ namespace Modbus.Net.Tests
|
|||||||
_modbusTcpMachine.GetAddresses = addresses;
|
_modbusTcpMachine.GetAddresses = addresses;
|
||||||
_modbusRtuMachine.GetAddresses = addresses;
|
_modbusRtuMachine.GetAddresses = addresses;
|
||||||
_modbusAsciiMachine.GetAddresses = addresses;
|
_modbusAsciiMachine.GetAddresses = addresses;
|
||||||
var ans = await _modbusTcpMachine.GetDatasAsync(MachineGetDataType.Address);
|
var ans = await _modbusTcpMachine.GetDatasAsync(MachineDataType.Address);
|
||||||
var ans2 = await _modbusRtuMachine.GetDatasAsync(MachineGetDataType.Address);
|
var ans2 = await _modbusRtuMachine.GetDatasAsync(MachineDataType.Address);
|
||||||
var ans3 = await _modbusAsciiMachine.GetDatasAsync(MachineGetDataType.Address);
|
var ans3 = await _modbusAsciiMachine.GetDatasAsync(MachineDataType.Address);
|
||||||
Assert.AreEqual(ans["3X 1.0"].PlcValue, 0);
|
Assert.AreEqual(ans["3X 1.0"].DeviceValue, 0);
|
||||||
Assert.AreEqual(ans2["3X 1.0"].PlcValue, 0);
|
Assert.AreEqual(ans2["3X 1.0"].DeviceValue, 0);
|
||||||
Assert.AreEqual(ans3["3X 1.0"].PlcValue, 0);
|
Assert.AreEqual(ans3["3X 1.0"].DeviceValue, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -146,15 +146,15 @@ namespace Modbus.Net.Tests
|
|||||||
_modbusTcpMachine.GetAddresses = addresses;
|
_modbusTcpMachine.GetAddresses = addresses;
|
||||||
_modbusAsciiMachine.GetAddresses = addresses;
|
_modbusAsciiMachine.GetAddresses = addresses;
|
||||||
_modbusRtuMachine.GetAddresses = addresses;
|
_modbusRtuMachine.GetAddresses = addresses;
|
||||||
await _modbusTcpMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
await _modbusTcpMachine.SetDatasAsync(MachineDataType.Address, dic1);
|
||||||
await _modbusAsciiMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
await _modbusAsciiMachine.SetDatasAsync(MachineDataType.Address, dic1);
|
||||||
await _modbusRtuMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
await _modbusRtuMachine.SetDatasAsync(MachineDataType.Address, dic1);
|
||||||
var ans = await _modbusTcpMachine.GetDatasAsync(MachineGetDataType.Address);
|
var ans = await _modbusTcpMachine.GetDatasAsync(MachineDataType.Address);
|
||||||
var ans2 = await _modbusRtuMachine.GetDatasAsync(MachineGetDataType.Address);
|
var ans2 = await _modbusRtuMachine.GetDatasAsync(MachineDataType.Address);
|
||||||
var ans3 = await _modbusAsciiMachine.GetDatasAsync(MachineGetDataType.Address);
|
var ans3 = await _modbusAsciiMachine.GetDatasAsync(MachineDataType.Address);
|
||||||
Assert.AreEqual(ans["4X 1.0"].PlcValue, dic1["4X 1"]);
|
Assert.AreEqual(ans["4X 1.0"].DeviceValue, dic1["4X 1"]);
|
||||||
Assert.AreEqual(ans2["4X 1.0"].PlcValue, dic1["4X 1"]);
|
Assert.AreEqual(ans2["4X 1.0"].DeviceValue, dic1["4X 1"]);
|
||||||
Assert.AreEqual(ans3["4X 1.0"].PlcValue, dic1["4X 1"]);
|
Assert.AreEqual(ans3["4X 1.0"].DeviceValue, dic1["4X 1"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -245,32 +245,32 @@ namespace Modbus.Net.Tests
|
|||||||
_modbusTcpMachine.GetAddresses = addresses;
|
_modbusTcpMachine.GetAddresses = addresses;
|
||||||
_modbusRtuMachine.GetAddresses = addresses;
|
_modbusRtuMachine.GetAddresses = addresses;
|
||||||
_modbusAsciiMachine.GetAddresses = addresses;
|
_modbusAsciiMachine.GetAddresses = addresses;
|
||||||
await _modbusTcpMachine.SetDatasAsync(MachineSetDataType.CommunicationTag, dic1);
|
await _modbusTcpMachine.SetDatasAsync(MachineDataType.CommunicationTag, dic1);
|
||||||
await _modbusRtuMachine.SetDatasAsync(MachineSetDataType.CommunicationTag, dic1);
|
await _modbusRtuMachine.SetDatasAsync(MachineDataType.CommunicationTag, dic1);
|
||||||
await _modbusAsciiMachine.SetDatasAsync(MachineSetDataType.CommunicationTag, dic1);
|
await _modbusAsciiMachine.SetDatasAsync(MachineDataType.CommunicationTag, dic1);
|
||||||
|
|
||||||
var ans = await _modbusTcpMachine.GetDatasAsync(MachineGetDataType.CommunicationTag);
|
var ans = await _modbusTcpMachine.GetDatasAsync(MachineDataType.CommunicationTag);
|
||||||
var ans2 = await _modbusRtuMachine.GetDatasAsync(MachineGetDataType.CommunicationTag);
|
var ans2 = await _modbusRtuMachine.GetDatasAsync(MachineDataType.CommunicationTag);
|
||||||
var ans3 = await _modbusAsciiMachine.GetDatasAsync(MachineGetDataType.CommunicationTag);
|
var ans3 = await _modbusAsciiMachine.GetDatasAsync(MachineDataType.CommunicationTag);
|
||||||
|
|
||||||
Assert.AreEqual(ans["A1"].PlcValue, dic1["A1"]);
|
Assert.AreEqual(ans["A1"].DeviceValue, dic1["A1"]);
|
||||||
Assert.AreEqual(ans["A2"].PlcValue, dic1["A2"]);
|
Assert.AreEqual(ans["A2"].DeviceValue, dic1["A2"]);
|
||||||
Assert.AreEqual(ans["A3"].PlcValue, dic1["A3"]);
|
Assert.AreEqual(ans["A3"].DeviceValue, dic1["A3"]);
|
||||||
Assert.AreEqual(ans["A4"].PlcValue, dic1["A4"]);
|
Assert.AreEqual(ans["A4"].DeviceValue, dic1["A4"]);
|
||||||
Assert.AreEqual(ans["A5"].PlcValue, dic1["A5"]);
|
Assert.AreEqual(ans["A5"].DeviceValue, dic1["A5"]);
|
||||||
Assert.AreEqual(ans["A6"].PlcValue, dic1["A6"]);
|
Assert.AreEqual(ans["A6"].DeviceValue, dic1["A6"]);
|
||||||
Assert.AreEqual(ans2["A1"].PlcValue, dic1["A1"]);
|
Assert.AreEqual(ans2["A1"].DeviceValue, dic1["A1"]);
|
||||||
Assert.AreEqual(ans2["A2"].PlcValue, dic1["A2"]);
|
Assert.AreEqual(ans2["A2"].DeviceValue, dic1["A2"]);
|
||||||
Assert.AreEqual(ans2["A3"].PlcValue, dic1["A3"]);
|
Assert.AreEqual(ans2["A3"].DeviceValue, dic1["A3"]);
|
||||||
Assert.AreEqual(ans2["A4"].PlcValue, dic1["A4"]);
|
Assert.AreEqual(ans2["A4"].DeviceValue, dic1["A4"]);
|
||||||
Assert.AreEqual(ans2["A5"].PlcValue, dic1["A5"]);
|
Assert.AreEqual(ans2["A5"].DeviceValue, dic1["A5"]);
|
||||||
Assert.AreEqual(ans2["A6"].PlcValue, dic1["A6"]);
|
Assert.AreEqual(ans2["A6"].DeviceValue, dic1["A6"]);
|
||||||
Assert.AreEqual(ans3["A1"].PlcValue, dic1["A1"]);
|
Assert.AreEqual(ans3["A1"].DeviceValue, dic1["A1"]);
|
||||||
Assert.AreEqual(ans3["A2"].PlcValue, dic1["A2"]);
|
Assert.AreEqual(ans3["A2"].DeviceValue, dic1["A2"]);
|
||||||
Assert.AreEqual(ans3["A3"].PlcValue, dic1["A3"]);
|
Assert.AreEqual(ans3["A3"].DeviceValue, dic1["A3"]);
|
||||||
Assert.AreEqual(ans3["A4"].PlcValue, dic1["A4"]);
|
Assert.AreEqual(ans3["A4"].DeviceValue, dic1["A4"]);
|
||||||
Assert.AreEqual(ans3["A5"].PlcValue, dic1["A5"]);
|
Assert.AreEqual(ans3["A5"].DeviceValue, dic1["A5"]);
|
||||||
Assert.AreEqual(ans3["A6"].PlcValue, dic1["A6"]);
|
Assert.AreEqual(ans3["A6"].DeviceValue, dic1["A6"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
|
|||||||
@@ -44,10 +44,10 @@ namespace Modbus.Net.Tests
|
|||||||
};
|
};
|
||||||
|
|
||||||
_siemensTcpMachine.GetAddresses = addresses;
|
_siemensTcpMachine.GetAddresses = addresses;
|
||||||
await _siemensTcpMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
await _siemensTcpMachine.SetDatasAsync(MachineDataType.Address, dic1);
|
||||||
|
|
||||||
var ans = await _siemensTcpMachine.GetDatasAsync(MachineGetDataType.Address);
|
var ans = await _siemensTcpMachine.GetDatasAsync(MachineDataType.Address);
|
||||||
Assert.AreEqual(ans["Q 0.0"].PlcValue, dic1["Q 0.0"]);
|
Assert.AreEqual(ans["Q 0.0"].DeviceValue, dic1["Q 0.0"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -67,8 +67,8 @@ namespace Modbus.Net.Tests
|
|||||||
};
|
};
|
||||||
|
|
||||||
_siemensTcpMachine.GetAddresses = addresses;
|
_siemensTcpMachine.GetAddresses = addresses;
|
||||||
var ans = await _siemensTcpMachine.GetDatasAsync(MachineGetDataType.Address);
|
var ans = await _siemensTcpMachine.GetDatasAsync(MachineDataType.Address);
|
||||||
Assert.AreEqual(ans["I 0.0"].PlcValue, 0);
|
Assert.AreEqual(ans["I 0.0"].DeviceValue, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -98,9 +98,9 @@ namespace Modbus.Net.Tests
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
await _siemensTcpMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
await _siemensTcpMachine.SetDatasAsync(MachineDataType.Address, dic1);
|
||||||
var ans = await _siemensTcpMachine.GetDatasAsync(MachineGetDataType.Address);
|
var ans = await _siemensTcpMachine.GetDatasAsync(MachineDataType.Address);
|
||||||
Assert.AreEqual(ans["M 0.0"].PlcValue, dic1["M 0"]);
|
Assert.AreEqual(ans["M 0.0"].DeviceValue, dic1["M 0"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -130,10 +130,10 @@ namespace Modbus.Net.Tests
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
await _siemensTcpMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
await _siemensTcpMachine.SetDatasAsync(MachineDataType.Address, dic1);
|
||||||
|
|
||||||
var ans = await _siemensTcpMachine.GetDatasAsync(MachineGetDataType.Address);
|
var ans = await _siemensTcpMachine.GetDatasAsync(MachineDataType.Address);
|
||||||
Assert.AreEqual(ans["M 0.0"].PlcValue, dic1["M 0.0"]);
|
Assert.AreEqual(ans["M 0.0"].DeviceValue, dic1["M 0.0"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -162,10 +162,10 @@ namespace Modbus.Net.Tests
|
|||||||
};
|
};
|
||||||
|
|
||||||
_siemensTcpMachine.GetAddresses = addresses;
|
_siemensTcpMachine.GetAddresses = addresses;
|
||||||
await _siemensTcpMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
await _siemensTcpMachine.SetDatasAsync(MachineDataType.Address, dic1);
|
||||||
|
|
||||||
var ans = await _siemensTcpMachine.GetDatasAsync(MachineGetDataType.Address);
|
var ans = await _siemensTcpMachine.GetDatasAsync(MachineDataType.Address);
|
||||||
Assert.AreEqual(ans["DB2 0.0"].PlcValue, dic1["DB2 0.0"]);
|
Assert.AreEqual(ans["DB2 0.0"].DeviceValue, dic1["DB2 0.0"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -254,14 +254,14 @@ namespace Modbus.Net.Tests
|
|||||||
};
|
};
|
||||||
|
|
||||||
_siemensTcpMachine.GetAddresses = addresses;
|
_siemensTcpMachine.GetAddresses = addresses;
|
||||||
await _siemensTcpMachine.SetDatasAsync(MachineSetDataType.CommunicationTag, dic1);
|
await _siemensTcpMachine.SetDatasAsync(MachineDataType.CommunicationTag, dic1);
|
||||||
var ans = await _siemensTcpMachine.GetDatasAsync(MachineGetDataType.CommunicationTag);
|
var ans = await _siemensTcpMachine.GetDatasAsync(MachineDataType.CommunicationTag);
|
||||||
Assert.AreEqual(ans["A1"].PlcValue, dic1["A1"]);
|
Assert.AreEqual(ans["A1"].DeviceValue, dic1["A1"]);
|
||||||
Assert.AreEqual(ans["A2"].PlcValue, dic1["A2"]);
|
Assert.AreEqual(ans["A2"].DeviceValue, dic1["A2"]);
|
||||||
Assert.AreEqual(ans["A3"].PlcValue, dic1["A3"]);
|
Assert.AreEqual(ans["A3"].DeviceValue, dic1["A3"]);
|
||||||
Assert.AreEqual(ans["A4"].PlcValue, dic1["A4"]);
|
Assert.AreEqual(ans["A4"].DeviceValue, dic1["A4"]);
|
||||||
Assert.AreEqual(ans["A5"].PlcValue, dic1["A5"]);
|
Assert.AreEqual(ans["A5"].DeviceValue, dic1["A5"]);
|
||||||
Assert.AreEqual(ans["A6"].PlcValue, dic1["A6"]);
|
Assert.AreEqual(ans["A6"].DeviceValue, dic1["A6"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCleanup]
|
[TestCleanup]
|
||||||
|
|||||||
Reference in New Issue
Block a user