Warning fix

This commit is contained in:
luosheng
2023-02-18 08:52:21 +08:00
parent 5118fc5ac3
commit d99cad0d77
23 changed files with 283 additions and 93 deletions

View File

@@ -126,7 +126,7 @@ namespace Hylasoft.Opc.Ua
} }
} }
private void SessionClosing(object? sender, EventArgs e) private void SessionClosing(object sender, EventArgs e)
{ {
Status = OpcStatus.NotConnected; Status = OpcStatus.NotConnected;
NotifyServerConnectionLost(); NotifyServerConnectionLost();

View File

@@ -1,9 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFrameworks>net6.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings> <AssemblyName>Modbus.Net.Modbus.NA200H</AssemblyName>
<Nullable>enable</Nullable> <RootNamespace>Modbus.Net.Modbus.NA200H</RootNamespace>
<PackageId>Modbus.Net.Modbus.NA200H</PackageId>
<Version>1.4.0</Version>
<Authors>Chris L.(Luo Sheng)</Authors>
<Company>Hangzhou Delian Science Technology Co.,Ltd.</Company>
<Product>Modbus.Net.Modbus</Product>
<Description>Modbus.Net Modbus Implementation</Description>
<Copyright>Copyright 2023 Hangzhou Delian Science Technology Co.,Ltd.</Copyright>
<PackageProjectUrl>https://github.com/parallelbgls/Modbus.Net/tree/master/Modbus.Net/Modbus.Net.Modbus.NA200H</PackageProjectUrl>
<RepositoryUrl>https://github.com/parallelbgls/Modbus.Net</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>hardware communicate protocol modbus Delian</PackageTags>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<IncludeSymbols>True</IncludeSymbols>
<IncludeSource>True</IncludeSource>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -5,7 +5,7 @@
<AssemblyName>Modbus.Net.Modbus</AssemblyName> <AssemblyName>Modbus.Net.Modbus</AssemblyName>
<RootNamespace>Modbus.Net.Modbus</RootNamespace> <RootNamespace>Modbus.Net.Modbus</RootNamespace>
<PackageId>Modbus.Net.Modbus</PackageId> <PackageId>Modbus.Net.Modbus</PackageId>
<Version>1.4.1</Version> <Version>1.4.0</Version>
<Authors>Chris L.(Luo Sheng)</Authors> <Authors>Chris L.(Luo Sheng)</Authors>
<Company>Hangzhou Delian Science Technology Co.,Ltd.</Company> <Company>Hangzhou Delian Science Technology Co.,Ltd.</Company>
<Product>Modbus.Net.Modbus</Product> <Product>Modbus.Net.Modbus</Product>

View File

@@ -5,7 +5,7 @@
<AssemblyName>Modbus.Net.OPC</AssemblyName> <AssemblyName>Modbus.Net.OPC</AssemblyName>
<RootNamespace>Modbus.Net.OPC</RootNamespace> <RootNamespace>Modbus.Net.OPC</RootNamespace>
<PackageId>Modbus.Net.OPC</PackageId> <PackageId>Modbus.Net.OPC</PackageId>
<Version>1.4.1</Version> <Version>1.4.0</Version>
<Authors>Chris L.(Luo Sheng)</Authors> <Authors>Chris L.(Luo Sheng)</Authors>
<Company>Hangzhou Delian Science Technology Co.,Ltd.</Company> <Company>Hangzhou Delian Science Technology Co.,Ltd.</Company>
<Product>Modbus.Net.OPC</Product> <Product>Modbus.Net.OPC</Product>

View File

@@ -72,16 +72,19 @@ namespace Modbus.Net.OPC
} }
} }
/// <inheritdoc />
protected override void ReceiveMsgThreadStart() protected override void ReceiveMsgThreadStart()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
/// <inheritdoc />
protected override void ReceiveMsgThreadStop() protected override void ReceiveMsgThreadStop()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
/// <inheritdoc />
protected override Task SendMsgWithoutConfirm(OpcParamIn message) protected override Task SendMsgWithoutConfirm(OpcParamIn message)
{ {
throw new NotImplementedException(); throw new NotImplementedException();

View File

@@ -5,7 +5,7 @@
<AssemblyName>Modbus.Net.Siemens</AssemblyName> <AssemblyName>Modbus.Net.Siemens</AssemblyName>
<RootNamespace>Modbus.Net.Siemens</RootNamespace> <RootNamespace>Modbus.Net.Siemens</RootNamespace>
<PackageId>Modbus.Net.Siemens</PackageId> <PackageId>Modbus.Net.Siemens</PackageId>
<Version>1.4.1</Version> <Version>1.4.0</Version>
<Authors>Chris L.(Luo Sheng)</Authors> <Authors>Chris L.(Luo Sheng)</Authors>
<Company>Hangzhou Delian Science Technology Co.,Ltd.</Company> <Company>Hangzhou Delian Science Technology Co.,Ltd.</Company>
<Description>Modbus.Net Siemens Profinet Implementation</Description> <Description>Modbus.Net Siemens Profinet Implementation</Description>

View File

@@ -31,8 +31,6 @@ namespace Modbus.Net
private int _timeoutTime; private int _timeoutTime;
private bool m_disposed;
private Task _receiveThread; private Task _receiveThread;
private bool _taskCancel = false; private bool _taskCancel = false;

View File

@@ -2,10 +2,17 @@
namespace Modbus.Net namespace Modbus.Net
{ {
/// <summary>
/// 设备的抽象
/// </summary>
public interface IMachine : IMachine<string> public interface IMachine : IMachine<string>
{ {
} }
/// <summary>
/// 设备的抽象
/// </summary>
/// <typeparam name="TKey"></typeparam>
public interface IMachine<TKey> : IMachineProperty<TKey>, IMachineMethodData where TKey : IEquatable<TKey> public interface IMachine<TKey> : IMachineProperty<TKey>, IMachineMethodData where TKey : IEquatable<TKey>
{ {
} }

View File

@@ -65,7 +65,7 @@ namespace Modbus.Net
} }
/// <summary> /// <summary>
/// 设备的抽象 /// 设备属性的抽象
/// </summary> /// </summary>
public interface IMachineProperty<TKey> : IMachinePropertyWithoutKey where TKey : IEquatable<TKey> public interface IMachineProperty<TKey> : IMachinePropertyWithoutKey where TKey : IEquatable<TKey>
{ {

View File

@@ -1,5 +1,8 @@
namespace Modbus.Net namespace Modbus.Net
{ {
/// <summary>
/// Api入口的抽象
/// </summary>
public interface IUtility : IUtilityProperty, IUtilityMethodData public interface IUtility : IUtilityProperty, IUtilityMethodData
{ {
} }

View File

@@ -3,7 +3,7 @@
namespace Modbus.Net namespace Modbus.Net
{ {
/// <summary> /// <summary>
/// Api入口的抽象 /// Api入口的属性抽象
/// </summary> /// </summary>
public interface IUtilityProperty public interface IUtilityProperty
{ {

View File

@@ -4,12 +4,19 @@ using Serilog;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq;
namespace Modbus.Net namespace Modbus.Net
{ {
/// <summary>
/// JobChaningJobListener with DataMap passing from parent job to next job
/// </summary>
public class JobChainingJobListenerWithDataMap : JobListenerSupport public class JobChainingJobListenerWithDataMap : JobListenerSupport
{ {
/// <summary>
/// JobChaningJobListener with DataMap passing from parent job to next job
/// </summary>
/// <param name="name">Job name</param>
/// <param name="overwriteKeys">If key is overwritable, parent job will pass the value to next job event next job contains that key</param>
public JobChainingJobListenerWithDataMap(string name, ICollection<string> overwriteKeys) public JobChainingJobListenerWithDataMap(string name, ICollection<string> overwriteKeys)
{ {
Name = name; Name = name;
@@ -19,8 +26,12 @@ namespace Modbus.Net
private readonly Dictionary<JobKey, JobKey> chainLinks; private readonly Dictionary<JobKey, JobKey> chainLinks;
/// <inheritdoc />
public override string Name { get; } public override string Name { get; }
/// <summary>
/// Keys that should overwritable
/// </summary>
public ICollection<string> OverWriteKeys { get; } public ICollection<string> OverWriteKeys { get; }
/// <summary> /// <summary>
@@ -34,6 +45,8 @@ namespace Modbus.Net
chainLinks.Add(firstJob, secondJob); chainLinks.Add(firstJob, secondJob);
} }
#nullable enable
/// <inheritdoc />
public override async Task JobWasExecuted(IJobExecutionContext context, public override async Task JobWasExecuted(IJobExecutionContext context,
JobExecutionException? jobException, JobExecutionException? jobException,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
@@ -50,6 +63,8 @@ namespace Modbus.Net
try try
{ {
var sjJobDetail = await context.Scheduler.GetJobDetail(sj); var sjJobDetail = await context.Scheduler.GetJobDetail(sj);
if (sjJobDetail != null)
{
foreach (var entry in context.JobDetail.JobDataMap) foreach (var entry in context.JobDetail.JobDataMap)
{ {
if (!sjJobDetail.JobDataMap.ContainsKey(entry.Key) || sjJobDetail.JobDataMap.ContainsKey(entry.Key) && OverWriteKeys != null && OverWriteKeys.Contains(entry.Key)) if (!sjJobDetail.JobDataMap.ContainsKey(entry.Key) || sjJobDetail.JobDataMap.ContainsKey(entry.Key) && OverWriteKeys != null && OverWriteKeys.Contains(entry.Key))
@@ -60,10 +75,12 @@ namespace Modbus.Net
await context.Scheduler.AddJob(sjJobDetail, true, false); await context.Scheduler.AddJob(sjJobDetail, true, false);
await context.Scheduler.TriggerJob(sj, cancellationToken).ConfigureAwait(false); await context.Scheduler.TriggerJob(sj, cancellationToken).ConfigureAwait(false);
} }
}
catch (SchedulerException se) catch (SchedulerException se)
{ {
Log.Error(se, "Error encountered during chaining to Job '{Job}'", sj); Log.Error(se, "Error encountered during chaining to Job '{Job}'", sj);
} }
} }
#nullable disable
} }
} }

View File

@@ -30,13 +30,30 @@ namespace Modbus.Net
public Dictionary<string, ReturnUnit> ReturnValues { get; set; } public Dictionary<string, ReturnUnit> ReturnValues { get; set; }
} }
/// <summary>
/// 设备调度器创建类
/// </summary>
public sealed class MachineJobSchedulerCreator public sealed class MachineJobSchedulerCreator
{ {
/// <summary>
/// 创建设备调度器
/// </summary>
/// <param name="triggerKey">键,全局唯一不能重复,重复会终止并删除已存在的调度器</param>
/// <param name="count">重复次数负数为无限循环0为执行一次</param>
/// <param name="intervalSecond">间隔秒数</param>
/// <returns></returns>
public static async Task<MachineGetJobScheduler> CreateScheduler(string triggerKey, int count = 0, int intervalSecond = 1) public static async Task<MachineGetJobScheduler> CreateScheduler(string triggerKey, int count = 0, int intervalSecond = 1)
{ {
return await CreateScheduler(triggerKey, count, intervalSecond); return await CreateScheduler(triggerKey, count, intervalSecond);
} }
/// <summary>
/// 创建设备调度器
/// </summary>
/// <param name="triggerKey">调度器键名,全局唯一不能重复,重复会终止并删除已存在的调度器</param>
/// <param name="count">重复次数负数为无限循环0为执行一次</param>
/// <param name="intervalMilliSecond">间隔毫秒数</param>
/// <returns></returns>
public static async Task<MachineGetJobScheduler> CreateSchedulerMillisecond(string triggerKey, int count = 0, int intervalMilliSecond = 1000) public static async Task<MachineGetJobScheduler> CreateSchedulerMillisecond(string triggerKey, int count = 0, int intervalMilliSecond = 1000)
{ {
return await CreateScheduler(triggerKey, count, intervalMilliSecond / 1000.0); return await CreateScheduler(triggerKey, count, intervalMilliSecond / 1000.0);
@@ -73,6 +90,11 @@ namespace Modbus.Net
return new MachineGetJobScheduler(scheduler, trigger); return new MachineGetJobScheduler(scheduler, trigger);
} }
/// <summary>
/// 取消并删除任务调度器
/// </summary>
/// <param name="triggerKey">调度器键名</param>
/// <returns></returns>
public static async Task CancelJob(string triggerKey) public static async Task CancelJob(string triggerKey)
{ {
IScheduler scheduler = await StdSchedulerFactory.GetDefaultScheduler(); IScheduler scheduler = await StdSchedulerFactory.GetDefaultScheduler();
@@ -82,20 +104,34 @@ namespace Modbus.Net
} }
} }
/// <summary>
/// 获取数据任务
/// </summary>
public sealed class MachineGetJobScheduler public sealed class MachineGetJobScheduler
{ {
IScheduler _scheduler; private IScheduler _scheduler;
ITrigger _trigger; private ITrigger _trigger;
JobKey _parentJobKey = null; private JobKey _parentJobKey = null;
/// <summary>
/// 获取数据任务
/// </summary>
/// <param name="scheduler">调度器</param>
/// <param name="trigger">触发器</param>
public MachineGetJobScheduler(IScheduler scheduler, ITrigger trigger) public MachineGetJobScheduler(IScheduler scheduler, ITrigger trigger)
{ {
_scheduler = scheduler; _scheduler = scheduler;
_trigger = trigger; _trigger = trigger;
} }
/// <summary>
/// 获取数据任务
/// </summary>
/// <param name="scheduler">调度器</param>
/// <param name="trigger">触发器</param>
/// <param name="parentJobKey">父任务的键</param>
public MachineGetJobScheduler(IScheduler scheduler, ITrigger trigger, JobKey parentJobKey) public MachineGetJobScheduler(IScheduler scheduler, ITrigger trigger, JobKey parentJobKey)
{ {
_scheduler = scheduler; _scheduler = scheduler;
@@ -103,6 +139,14 @@ namespace Modbus.Net
_parentJobKey = parentJobKey; _parentJobKey = parentJobKey;
} }
/// <summary>
/// 从设备获取数据
/// </summary>
/// <param name="queryId">任务ID每个触发器唯一</param>
/// <param name="machine">要获取数据的设备实例</param>
/// <param name="machineDataType">获取数据的方式</param>
/// <returns></returns>
/// <exception cref="NullReferenceException"></exception>
public async Task<MachineQueryJobScheduler> From(string queryId, IMachineMethodData machine, MachineDataType machineDataType) public async Task<MachineQueryJobScheduler> From(string queryId, IMachineMethodData machine, MachineDataType machineDataType)
{ {
JobKey jobKey = JobKey.Create("Modbus.Net.DataQuery.Job." + queryId, "Modbus.Net.DataQuery.Group." + _trigger.Key.Name); JobKey jobKey = JobKey.Create("Modbus.Net.DataQuery.Job." + queryId, "Modbus.Net.DataQuery.Group." + _trigger.Key.Name);
@@ -118,6 +162,7 @@ namespace Modbus.Net
if (_parentJobKey != null) if (_parentJobKey != null)
{ {
var listener = _scheduler.ListenerManager.GetJobListener("Modbus.Net.DataQuery.Chain." + _trigger.Key.Name) as JobChainingJobListenerWithDataMap; var listener = _scheduler.ListenerManager.GetJobListener("Modbus.Net.DataQuery.Chain." + _trigger.Key.Name) as JobChainingJobListenerWithDataMap;
if (listener == null) throw new NullReferenceException("Listener " + "Modbus.Net.DataQuery.Chain." + _trigger.Key.Name + " is null");
listener.AddJobChainLink(_parentJobKey, jobKey); listener.AddJobChainLink(_parentJobKey, jobKey);
await _scheduler.AddJob(job, true); await _scheduler.AddJob(job, true);
@@ -130,11 +175,27 @@ namespace Modbus.Net
return new MachineQueryJobScheduler(_scheduler, _trigger, jobKey); return new MachineQueryJobScheduler(_scheduler, _trigger, jobKey);
} }
/// <summary>
/// 直接向任务队列中写一个数据模板
/// </summary>
/// <param name="queryId">任务ID每个触发器唯一</param>
/// <param name="values">要写入的数据模板</param>
/// <param name="machineDataType">获取数据的方式</param>
/// <returns></returns>
public Task<MachineQueryJobScheduler> Apply(string queryId, Dictionary<string, double> values, MachineDataType machineDataType) public Task<MachineQueryJobScheduler> Apply(string queryId, Dictionary<string, double> values, MachineDataType machineDataType)
{ {
return Apply<string>(queryId, values, machineDataType); return Apply<string>(queryId, values, machineDataType);
} }
/// <summary>
/// 直接向任务队列中写一个数据模板
/// </summary>
/// <typeparam name="TMachineKey">设备的ID类型</typeparam>
/// <param name="queryId">任务ID每个触发器唯一</param>
/// <param name="values">要写入的数据模板</param>
/// <param name="machineDataType">获取数据的方式</param>
/// <returns></returns>
/// <exception cref="NullReferenceException"></exception>
public async Task<MachineQueryJobScheduler> Apply<TMachineKey>(string queryId, Dictionary<string, double> values, MachineDataType machineDataType) where TMachineKey : IEquatable<TMachineKey> public async Task<MachineQueryJobScheduler> Apply<TMachineKey>(string queryId, Dictionary<string, double> values, MachineDataType machineDataType) where TMachineKey : IEquatable<TMachineKey>
{ {
JobKey jobKey = JobKey.Create("Modbus.Net.DataQuery.Job." + queryId, "Modbus.Net.DataQuery.Group." + _trigger.Key.Name); JobKey jobKey = JobKey.Create("Modbus.Net.DataQuery.Job." + queryId, "Modbus.Net.DataQuery.Group." + _trigger.Key.Name);
@@ -151,6 +212,7 @@ namespace Modbus.Net
if (_parentJobKey != null) if (_parentJobKey != null)
{ {
var listener = _scheduler.ListenerManager.GetJobListener("Modbus.Net.DataQuery.Chain." + _trigger.Key.Name) as JobChainingJobListenerWithDataMap; var listener = _scheduler.ListenerManager.GetJobListener("Modbus.Net.DataQuery.Chain." + _trigger.Key.Name) as JobChainingJobListenerWithDataMap;
if (listener == null) throw new NullReferenceException("Listener " + "Modbus.Net.DataQuery.Chain." + _trigger.Key.Name + " is null");
listener.AddJobChainLink(_parentJobKey, jobKey); listener.AddJobChainLink(_parentJobKey, jobKey);
await _scheduler.AddJob(job, true); await _scheduler.AddJob(job, true);
@@ -163,11 +225,27 @@ namespace Modbus.Net
return new MachineQueryJobScheduler(_scheduler, _trigger, jobKey); return new MachineQueryJobScheduler(_scheduler, _trigger, jobKey);
} }
/// <summary>
/// 直接向任务队列中写一个数据模板,并跳过处理数据流程
/// </summary>
/// <param name="queryId">任务ID每个触发器唯一</param>
/// <param name="values">要写入的数据模板</param>
/// <param name="machineDataType">获取数据的方式</param>
/// <returns></returns>
public Task<MachineSetJobScheduler> ApplyTo(string queryId, Dictionary<string, double> values, MachineDataType machineDataType) public Task<MachineSetJobScheduler> ApplyTo(string queryId, Dictionary<string, double> values, MachineDataType machineDataType)
{ {
return ApplyTo<string>(queryId, values, machineDataType); return ApplyTo<string>(queryId, values, machineDataType);
} }
/// <summary>
/// 直接向任务队列中写一个数据模板,并跳过处理数据流程
/// </summary>
/// <typeparam name="TMachineKey">设备的ID类型</typeparam>
/// <param name="queryId">任务ID每个触发器唯一</param>
/// <param name="values">要写入的数据模板</param>
/// <param name="machineDataType">获取数据的方式</param>
/// <returns></returns>
/// <exception cref="NullReferenceException"></exception>
public async Task<MachineSetJobScheduler> ApplyTo<TMachineKey>(string queryId, Dictionary<string, double> values, MachineDataType machineDataType) where TMachineKey : IEquatable<TMachineKey> public async Task<MachineSetJobScheduler> ApplyTo<TMachineKey>(string queryId, Dictionary<string, double> values, MachineDataType machineDataType) where TMachineKey : IEquatable<TMachineKey>
{ {
var applyJobScheduler = await Apply<TMachineKey>(queryId, values, machineDataType); var applyJobScheduler = await Apply<TMachineKey>(queryId, values, machineDataType);
@@ -175,14 +253,23 @@ namespace Modbus.Net
} }
} }
/// <summary>
/// 处理数据任务
/// </summary>
public sealed class MachineQueryJobScheduler public sealed class MachineQueryJobScheduler
{ {
IScheduler _scheduler; private IScheduler _scheduler;
ITrigger _trigger; private ITrigger _trigger;
JobKey _parentJobKey; private JobKey _parentJobKey;
/// <summary>
/// 处理数据任务
/// </summary>
/// <param name="scheduler">调度器</param>
/// <param name="trigger">触发器</param>
/// <param name="parentJobKey">父任务的键</param>
public MachineQueryJobScheduler(IScheduler scheduler, ITrigger trigger, JobKey parentJobKey) public MachineQueryJobScheduler(IScheduler scheduler, ITrigger trigger, JobKey parentJobKey)
{ {
_scheduler = scheduler; _scheduler = scheduler;
@@ -190,11 +277,25 @@ namespace Modbus.Net
_parentJobKey = parentJobKey; _parentJobKey = parentJobKey;
} }
/// <summary>
/// 处理数据
/// </summary>
/// <param name="queryId">任务ID每个触发器唯一</param>
/// <param name="QueryDataFunc">处理数据的函数,输入返回读数据的定义和值,输出写数据字典</param>
/// <returns></returns>
public Task<MachineSetJobScheduler> Query(string queryId = null, Func<DataReturnDef, Dictionary<string, double>> QueryDataFunc = null) public Task<MachineSetJobScheduler> Query(string queryId = null, Func<DataReturnDef, Dictionary<string, double>> QueryDataFunc = null)
{ {
return Query<string>(queryId, QueryDataFunc); return Query<string>(queryId, QueryDataFunc);
} }
/// <summary>
/// 处理数据
/// </summary>
/// <typeparam name="TMachineKey">设备的ID类型</typeparam>
/// <param name="queryId">任务ID每个触发器唯一</param>
/// <param name="QueryDataFunc">处理数据的函数,输入返回读数据的定义和值,输出写数据字典</param>
/// <returns></returns>
/// <exception cref="NullReferenceException"></exception>
public async Task<MachineSetJobScheduler> Query<TMachineKey>(string queryId = null, Func<DataReturnDef, Dictionary<string, double>> QueryDataFunc = null) where TMachineKey : IEquatable<TMachineKey> public async Task<MachineSetJobScheduler> Query<TMachineKey>(string queryId = null, Func<DataReturnDef, Dictionary<string, double>> QueryDataFunc = null) where TMachineKey : IEquatable<TMachineKey>
{ {
if (queryId == null) return new MachineSetJobScheduler(_scheduler, _trigger, _parentJobKey); if (queryId == null) return new MachineSetJobScheduler(_scheduler, _trigger, _parentJobKey);
@@ -206,9 +307,11 @@ namespace Modbus.Net
.StoreDurably(true) .StoreDurably(true)
.Build(); .Build();
if (QueryDataFunc != null)
job.JobDataMap.Put("QueryMethod", QueryDataFunc); job.JobDataMap.Put("QueryMethod", QueryDataFunc);
var listener = _scheduler.ListenerManager.GetJobListener("Modbus.Net.DataQuery.Chain." + _trigger.Key.Name) as JobChainingJobListenerWithDataMap; var listener = _scheduler.ListenerManager.GetJobListener("Modbus.Net.DataQuery.Chain." + _trigger.Key.Name) as JobChainingJobListenerWithDataMap;
if (listener == null) throw new NullReferenceException("Listener " + "Modbus.Net.DataQuery.Chain." + _trigger.Key.Name + " is null");
listener.AddJobChainLink(_parentJobKey, jobKey); listener.AddJobChainLink(_parentJobKey, jobKey);
await _scheduler.AddJob(job, true); await _scheduler.AddJob(job, true);
@@ -217,14 +320,23 @@ namespace Modbus.Net
} }
} }
/// <summary>
/// 写入数据任务
/// </summary>
public sealed class MachineSetJobScheduler public sealed class MachineSetJobScheduler
{ {
IScheduler _scheduler; private IScheduler _scheduler;
ITrigger _trigger; private ITrigger _trigger;
JobKey _parentJobKey; private JobKey _parentJobKey;
/// <summary>
/// 写入数据任务
/// </summary>
/// <param name="scheduler">调度器</param>
/// <param name="trigger">触发器</param>
/// <param name="parentJobKey">父任务的键</param>
public MachineSetJobScheduler(IScheduler scheduler, ITrigger trigger, JobKey parentJobKey) public MachineSetJobScheduler(IScheduler scheduler, ITrigger trigger, JobKey parentJobKey)
{ {
_scheduler = scheduler; _scheduler = scheduler;
@@ -234,6 +346,13 @@ namespace Modbus.Net
_parentJobKey = parentJobKey; _parentJobKey = parentJobKey;
} }
/// <summary>
/// 向设备写入数据
/// </summary>
/// <param name="queryId">任务ID每个触发器唯一</param>
/// <param name="machine">写入数据的设备实例</param>
/// <returns></returns>
/// <exception cref="NullReferenceException"></exception>
public async Task<MachineSetJobScheduler> To(string queryId, IMachineMethodData machine) public async Task<MachineSetJobScheduler> To(string queryId, IMachineMethodData machine)
{ {
JobKey jobKey = JobKey.Create("Modbus.Net.DataQuery.Job." + queryId, "Modbus.Net.DataQuery.Group." + _trigger.Key.Name); JobKey jobKey = JobKey.Create("Modbus.Net.DataQuery.Job." + queryId, "Modbus.Net.DataQuery.Group." + _trigger.Key.Name);
@@ -246,6 +365,7 @@ namespace Modbus.Net
job.JobDataMap.Put("Machine", machine); job.JobDataMap.Put("Machine", machine);
var listener = _scheduler.ListenerManager.GetJobListener("Modbus.Net.DataQuery.Chain." + _trigger.Key.Name) as JobChainingJobListenerWithDataMap; var listener = _scheduler.ListenerManager.GetJobListener("Modbus.Net.DataQuery.Chain." + _trigger.Key.Name) as JobChainingJobListenerWithDataMap;
if (listener == null) throw new NullReferenceException("Listener " + "Modbus.Net.DataQuery.Chain." + _trigger.Key.Name + " is null");
listener.AddJobChainLink(_parentJobKey, jobKey); listener.AddJobChainLink(_parentJobKey, jobKey);
await _scheduler.AddJob(job, true); await _scheduler.AddJob(job, true);
@@ -253,19 +373,34 @@ namespace Modbus.Net
return new MachineSetJobScheduler(_scheduler, _trigger, jobKey); return new MachineSetJobScheduler(_scheduler, _trigger, jobKey);
} }
/// <summary>
/// 再次获取一个设备的数据
/// </summary>
/// <param name="queryId">任务ID每个触发器唯一</param>
/// <param name="machine">要获取数据的设备实例</param>
/// <param name="machineDataType">获取数据的方式</param>
/// <returns></returns>
public async Task<MachineQueryJobScheduler> From(string queryId, IMachineMethodData machine, MachineDataType machineDataType) public async Task<MachineQueryJobScheduler> From(string queryId, IMachineMethodData machine, MachineDataType machineDataType)
{ {
return await new MachineGetJobScheduler(_scheduler, _trigger, _parentJobKey).From(queryId, machine, machineDataType); return await new MachineGetJobScheduler(_scheduler, _trigger, _parentJobKey).From(queryId, machine, machineDataType);
} }
/// <summary>
/// 执行任务
/// </summary>
/// <returns></returns>
public async Task Run() public async Task Run()
{ {
await _scheduler.Start(); await _scheduler.Start();
} }
} }
/// <summary>
/// 获取数据任务
/// </summary>
public class MachineGetDataJob : IJob public class MachineGetDataJob : IJob
{ {
/// <inheritdoc />
public async Task Execute(IJobExecutionContext context) public async Task Execute(IJobExecutionContext context)
{ {
object machine; object machine;
@@ -279,8 +414,13 @@ namespace Modbus.Net
} }
} }
/// <summary>
/// 处理数据任务
/// </summary>
/// <typeparam name="TMachineKey"></typeparam>
public class MachineQueryDataJob<TMachineKey> : IJob where TMachineKey : IEquatable<TMachineKey> public class MachineQueryDataJob<TMachineKey> : IJob where TMachineKey : IEquatable<TMachineKey>
{ {
/// <inheritdoc />
public async Task Execute(IJobExecutionContext context) public async Task Execute(IJobExecutionContext context)
{ {
object machine; object machine;
@@ -299,8 +439,12 @@ namespace Modbus.Net
} }
} }
/// <summary>
/// 写数据任务
/// </summary>
public class MachineSetDataJob : IJob public class MachineSetDataJob : IJob
{ {
/// <inheritdoc />
public async Task Execute(IJobExecutionContext context) public async Task Execute(IJobExecutionContext context)
{ {
object machine; object machine;
@@ -314,7 +458,9 @@ namespace Modbus.Net
if (valuesSet == null && values != null) if (valuesSet == null && values != null)
valuesSet = ((Dictionary<string, ReturnUnit>)values).MapGetValuesToSetValues(); valuesSet = ((Dictionary<string, ReturnUnit>)values).MapGetValuesToSetValues();
if (valuesSet == null) throw new NullReferenceException("Set value is null");
var success = await (machine as IMachineMethodData)!.SetDatasAsync((MachineDataType)machineDataType, (Dictionary<string, double>)valuesSet); var success = await (machine as IMachineMethodData)!.SetDatasAsync((MachineDataType)machineDataType, (Dictionary<string, double>)valuesSet);
} }
} }
} }

View File

@@ -5,7 +5,7 @@
<AssemblyName>Modbus.Net</AssemblyName> <AssemblyName>Modbus.Net</AssemblyName>
<RootNamespace>Modbus.Net</RootNamespace> <RootNamespace>Modbus.Net</RootNamespace>
<PackageId>Modbus.Net</PackageId> <PackageId>Modbus.Net</PackageId>
<Version>1.4.1</Version> <Version>1.4.0</Version>
<Product>Modbus.Net</Product> <Product>Modbus.Net</Product>
<Authors>Chris L.(Luo Sheng)</Authors> <Authors>Chris L.(Luo Sheng)</Authors>
<Company>Hangzhou Delian Science Technology Co.,Ltd.</Company> <Company>Hangzhou Delian Science Technology Co.,Ltd.</Company>

View File

@@ -7,10 +7,10 @@ namespace AnyType.Models
{ {
public class TaskViewModel public class TaskViewModel
{ {
public string Id { get; set; } public string? Id { get; set; }
public string Name { get; set; } public string? Name { get; set; }
public string Address { get; set; } public string? Address { get; set; }
public double Value { get; set; } public double? Value { get; set; }
public string Type { get; set; } public string? Type { get; set; }
} }
} }

View File

@@ -16,7 +16,7 @@ namespace CrossLamp.Controllers
_logger = logger; _logger = logger;
} }
private static BaseUtility _utility; private static BaseUtility? _utility = null;
public ActionResult Index() public ActionResult Index()
{ {
@@ -24,7 +24,7 @@ namespace CrossLamp.Controllers
} }
[HttpGet] [HttpGet]
public async Task<JsonResult> GetLamp() public async Task<JsonResult?> GetLamp()
{ {
try try
{ {

View File

@@ -8,9 +8,9 @@ namespace CrossLampControl.WebApi.Models
{ {
public class Lamp public class Lamp
{ {
public string MainLamp { get; set; } public string? MainLamp { get; set; }
public string SubLamp { get; set; } public string? SubLamp { get; set; }
public string StartPause { get; set; } public string? StartPause { get; set; }
public Lamp() public Lamp()
{ {

View File

@@ -15,8 +15,8 @@ namespace TripleAdd.Controllers
_logger = logger; _logger = logger;
} }
private static BaseUtility utility; private static BaseUtility? utility;
private static BaseMachine machine; private static BaseMachine? machine;
public ActionResult Index() public ActionResult Index()
{ {
@@ -83,7 +83,7 @@ namespace TripleAdd.Controllers
public async Task<ActionResult> SetUtility(TripleAddViewModel model) public async Task<ActionResult> SetUtility(TripleAddViewModel model)
{ {
ushort add1 = model.Add1, add2 = model.Add2, add3 = model.Add3; ushort add1 = model.Add1, add2 = model.Add2, add3 = model.Add3;
await utility.SetDatasAsync("4X 1", new object[] { add1, add2, add3 }); await utility!.SetDatasAsync("4X 1", new object[] { add1, add2, add3 });
return RedirectToAction("Utility"); return RedirectToAction("Utility");
} }
@@ -92,7 +92,7 @@ namespace TripleAdd.Controllers
{ {
ushort add1 = model.Add1, add2 = model.Add2, add3 = model.Add3; ushort add1 = model.Add1, add2 = model.Add2, add3 = model.Add3;
var setDic = new Dictionary<string, double> { { "Add1", add1 }, { "Add2", add2 }, { "Add3", add3 } }; var setDic = new Dictionary<string, double> { { "Add1", add1 }, { "Add2", add2 }, { "Add3", add3 } };
await machine.SetDatasAsync(MachineDataType.CommunicationTag, setDic); await machine!.SetDatasAsync(MachineDataType.CommunicationTag, setDic);
return RedirectToAction("Machine"); return RedirectToAction("Machine");
} }

View File

@@ -10,9 +10,9 @@ namespace Modbus.Net.Tests
[TestClass] [TestClass]
public class BaseTest public class BaseTest
{ {
private List<AddressUnit<int>> _addressUnits; private List<AddressUnit<int>>? _addressUnits;
private BaseMachine<int, int> _baseMachine2; private BaseMachine<int, int>? _baseMachine2;
[TestInitialize] [TestInitialize]
public void Init() public void Init()
@@ -138,7 +138,7 @@ namespace Modbus.Net.Tests
public void AddressCombinerContinusTest() public void AddressCombinerContinusTest()
{ {
var addressCombiner = new AddressCombinerContinus<int>(new AddressTranslatorModbus(), 100000); var addressCombiner = new AddressCombinerContinus<int>(new AddressTranslatorModbus(), 100000);
var combinedAddresses = addressCombiner.Combine(_addressUnits).ToArray(); var combinedAddresses = addressCombiner.Combine(_addressUnits!).ToArray();
Assert.AreEqual(combinedAddresses[0].Area, "3X"); Assert.AreEqual(combinedAddresses[0].Area, "3X");
Assert.AreEqual(combinedAddresses[0].Address, 1); Assert.AreEqual(combinedAddresses[0].Address, 1);
Assert.AreEqual(combinedAddresses[0].GetCount, 1); Assert.AreEqual(combinedAddresses[0].GetCount, 1);
@@ -166,7 +166,7 @@ namespace Modbus.Net.Tests
public void AddressCombinerContinusLimitTest() public void AddressCombinerContinusLimitTest()
{ {
var addressCombiner = new AddressCombinerContinus<int>(new AddressTranslatorModbus(), 4); var addressCombiner = new AddressCombinerContinus<int>(new AddressTranslatorModbus(), 4);
var combinedAddresses = addressCombiner.Combine(_addressUnits).ToArray(); var combinedAddresses = addressCombiner.Combine(_addressUnits!).ToArray();
Assert.AreEqual(combinedAddresses[0].Area, "3X"); Assert.AreEqual(combinedAddresses[0].Area, "3X");
Assert.AreEqual(combinedAddresses[0].Address, 1); Assert.AreEqual(combinedAddresses[0].Address, 1);
Assert.AreEqual(combinedAddresses[0].GetCount, 1); Assert.AreEqual(combinedAddresses[0].GetCount, 1);
@@ -197,7 +197,7 @@ namespace Modbus.Net.Tests
public void AddressCombinerSingleTest() public void AddressCombinerSingleTest()
{ {
var addressCombiner = new AddressCombinerSingle<int>(); var addressCombiner = new AddressCombinerSingle<int>();
var combinedAddresses = addressCombiner.Combine(_addressUnits).ToArray(); var combinedAddresses = addressCombiner.Combine(_addressUnits!).ToArray();
Assert.AreEqual(combinedAddresses[0].Area, "3X"); Assert.AreEqual(combinedAddresses[0].Area, "3X");
Assert.AreEqual(combinedAddresses[0].Address, 1); Assert.AreEqual(combinedAddresses[0].Address, 1);
Assert.AreEqual(combinedAddresses[0].GetCount, 1); Assert.AreEqual(combinedAddresses[0].GetCount, 1);
@@ -221,7 +221,7 @@ namespace Modbus.Net.Tests
public void AddressCombinerNumericJumpTest() public void AddressCombinerNumericJumpTest()
{ {
var addressCombiner = new AddressCombinerNumericJump<int>(10, 100000, new AddressTranslatorModbus()); var addressCombiner = new AddressCombinerNumericJump<int>(10, 100000, new AddressTranslatorModbus());
var combinedAddresses = addressCombiner.Combine(_addressUnits).ToArray(); var combinedAddresses = addressCombiner.Combine(_addressUnits!).ToArray();
Assert.AreEqual(combinedAddresses[0].Area, "3X"); Assert.AreEqual(combinedAddresses[0].Area, "3X");
Assert.AreEqual(combinedAddresses[0].Address, 1); Assert.AreEqual(combinedAddresses[0].Address, 1);
Assert.AreEqual(combinedAddresses[0].GetCount, 20); Assert.AreEqual(combinedAddresses[0].GetCount, 20);
@@ -237,7 +237,7 @@ namespace Modbus.Net.Tests
public void AddressCombinerNumericJumpLimitTest() public void AddressCombinerNumericJumpLimitTest()
{ {
var addressCombiner = new AddressCombinerNumericJump<int>(10, 10, new AddressTranslatorModbus()); var addressCombiner = new AddressCombinerNumericJump<int>(10, 10, new AddressTranslatorModbus());
var combinedAddresses = addressCombiner.Combine(_addressUnits).ToArray(); var combinedAddresses = addressCombiner.Combine(_addressUnits!).ToArray();
Assert.AreEqual(combinedAddresses[0].Area, "3X"); Assert.AreEqual(combinedAddresses[0].Area, "3X");
Assert.AreEqual(combinedAddresses[0].Address, 1); Assert.AreEqual(combinedAddresses[0].Address, 1);
Assert.AreEqual(combinedAddresses[0].GetCount, 8); Assert.AreEqual(combinedAddresses[0].GetCount, 8);
@@ -256,7 +256,7 @@ namespace Modbus.Net.Tests
public void AddressCombinerPercentageJumpTest() public void AddressCombinerPercentageJumpTest()
{ {
var addressCombiner = new AddressCombinerPercentageJump<int>(30.0, 100000, new AddressTranslatorModbus()); var addressCombiner = new AddressCombinerPercentageJump<int>(30.0, 100000, new AddressTranslatorModbus());
var combinedAddresses = addressCombiner.Combine(_addressUnits).ToArray(); var combinedAddresses = addressCombiner.Combine(_addressUnits!).ToArray();
Assert.AreEqual(combinedAddresses[0].Area, "3X"); Assert.AreEqual(combinedAddresses[0].Area, "3X");
Assert.AreEqual(combinedAddresses[0].Address, 1); Assert.AreEqual(combinedAddresses[0].Address, 1);
Assert.AreEqual(combinedAddresses[0].GetCount, 12); Assert.AreEqual(combinedAddresses[0].GetCount, 12);
@@ -275,7 +275,7 @@ namespace Modbus.Net.Tests
public void AddressCombinerPercentageJumpLimitTest() public void AddressCombinerPercentageJumpLimitTest()
{ {
var addressCombiner = new AddressCombinerPercentageJump<int>(30.0, 10, new AddressTranslatorModbus()); var addressCombiner = new AddressCombinerPercentageJump<int>(30.0, 10, new AddressTranslatorModbus());
var combinedAddresses = addressCombiner.Combine(_addressUnits).ToArray(); var combinedAddresses = addressCombiner.Combine(_addressUnits!).ToArray();
Assert.AreEqual(combinedAddresses[0].Area, "3X"); Assert.AreEqual(combinedAddresses[0].Area, "3X");
Assert.AreEqual(combinedAddresses[0].Address, 1); Assert.AreEqual(combinedAddresses[0].Address, 1);
Assert.AreEqual(combinedAddresses[0].GetCount, 8); Assert.AreEqual(combinedAddresses[0].GetCount, 8);
@@ -296,7 +296,7 @@ namespace Modbus.Net.Tests
[TestCleanup] [TestCleanup]
public void MachineClean() public void MachineClean()
{ {
_baseMachine2.Disconnect(); _baseMachine2?.Disconnect();
} }
} }
} }

View File

@@ -11,9 +11,9 @@ namespace Modbus.Net.Tests
[TestClass] [TestClass]
public class EndianTest public class EndianTest
{ {
private BaseMachine _modbusTcpMachine; private BaseMachine? _modbusTcpMachine;
private BaseMachine _modbusTcpMachine2; private BaseMachine? _modbusTcpMachine2;
[TestInitialize] [TestInitialize]
public void Init() public void Init()
@@ -48,8 +48,8 @@ namespace Modbus.Net.Tests
} }
}; };
_modbusTcpMachine.GetAddresses = addresses; _modbusTcpMachine!.GetAddresses = addresses;
_modbusTcpMachine2.GetAddresses = addresses; _modbusTcpMachine2!.GetAddresses = addresses;
await _modbusTcpMachine.SetDatasAsync(MachineDataType.Address, dic1); await _modbusTcpMachine.SetDatasAsync(MachineDataType.Address, dic1);
var ans = await _modbusTcpMachine.GetDatasAsync(MachineDataType.Address); var ans = await _modbusTcpMachine.GetDatasAsync(MachineDataType.Address);
var ans2 = await _modbusTcpMachine2.GetDatasAsync(MachineDataType.Address); var ans2 = await _modbusTcpMachine2.GetDatasAsync(MachineDataType.Address);

View File

@@ -10,9 +10,9 @@ namespace Modbus.Net.Tests
[TestClass] [TestClass]
public class ModbusMultiStationTest public class ModbusMultiStationTest
{ {
private BaseMachine _modbusRtuMachine1; private BaseMachine? _modbusRtuMachine1;
private BaseMachine _modbusRtuMachine2; private BaseMachine? _modbusRtuMachine2;
[TestInitialize] [TestInitialize]
public void Init() public void Init()
@@ -82,8 +82,8 @@ namespace Modbus.Net.Tests
} }
}; };
_modbusRtuMachine1.GetAddresses = addresses.ToList(); _modbusRtuMachine1!.GetAddresses = addresses.ToList();
_modbusRtuMachine2.GetAddresses = addresses.ToList(); _modbusRtuMachine2!.GetAddresses = addresses.ToList();
Random r = new Random(); Random r = new Random();
var dic1 = new Dictionary<string, double>() var dic1 = new Dictionary<string, double>()

View File

@@ -9,11 +9,11 @@ namespace Modbus.Net.Tests
[TestClass] [TestClass]
public class ModbusTest public class ModbusTest
{ {
private BaseMachine _modbusTcpMachine; private BaseMachine? _modbusTcpMachine;
private BaseMachine _modbusRtuMachine; private BaseMachine? _modbusRtuMachine;
private BaseMachine _modbusAsciiMachine; private BaseMachine? _modbusAsciiMachine;
[TestInitialize] [TestInitialize]
public void Init() public void Init()
@@ -50,9 +50,9 @@ 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(MachineDataType.Address, dic1); await _modbusTcpMachine.SetDatasAsync(MachineDataType.Address, dic1);
await _modbusAsciiMachine.SetDatasAsync(MachineDataType.Address, dic1); await _modbusAsciiMachine.SetDatasAsync(MachineDataType.Address, dic1);
await _modbusRtuMachine.SetDatasAsync(MachineDataType.Address, dic1); await _modbusRtuMachine.SetDatasAsync(MachineDataType.Address, dic1);
@@ -80,9 +80,9 @@ 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(MachineDataType.Address); var ans = await _modbusTcpMachine.GetDatasAsync(MachineDataType.Address);
var ans2 = await _modbusRtuMachine.GetDatasAsync(MachineDataType.Address); var ans2 = await _modbusRtuMachine.GetDatasAsync(MachineDataType.Address);
var ans3 = await _modbusAsciiMachine.GetDatasAsync(MachineDataType.Address); var ans3 = await _modbusAsciiMachine.GetDatasAsync(MachineDataType.Address);
@@ -107,9 +107,9 @@ 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(MachineDataType.Address); var ans = await _modbusTcpMachine.GetDatasAsync(MachineDataType.Address);
var ans2 = await _modbusRtuMachine.GetDatasAsync(MachineDataType.Address); var ans2 = await _modbusRtuMachine.GetDatasAsync(MachineDataType.Address);
var ans3 = await _modbusAsciiMachine.GetDatasAsync(MachineDataType.Address); var ans3 = await _modbusAsciiMachine.GetDatasAsync(MachineDataType.Address);
@@ -143,9 +143,9 @@ 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(MachineDataType.Address, dic1); await _modbusTcpMachine.SetDatasAsync(MachineDataType.Address, dic1);
await _modbusAsciiMachine.SetDatasAsync(MachineDataType.Address, dic1); await _modbusAsciiMachine.SetDatasAsync(MachineDataType.Address, dic1);
await _modbusRtuMachine.SetDatasAsync(MachineDataType.Address, dic1); await _modbusRtuMachine.SetDatasAsync(MachineDataType.Address, dic1);
@@ -242,9 +242,9 @@ 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(MachineDataType.CommunicationTag, dic1); await _modbusTcpMachine.SetDatasAsync(MachineDataType.CommunicationTag, dic1);
await _modbusRtuMachine.SetDatasAsync(MachineDataType.CommunicationTag, dic1); await _modbusRtuMachine.SetDatasAsync(MachineDataType.CommunicationTag, dic1);
await _modbusAsciiMachine.SetDatasAsync(MachineDataType.CommunicationTag, dic1); await _modbusAsciiMachine.SetDatasAsync(MachineDataType.CommunicationTag, dic1);
@@ -292,9 +292,9 @@ namespace Modbus.Net.Tests
} }
}; };
await _modbusTcpMachine.BaseUtility.GetUtilityMethods<IUtilityMethodWriteSingle>().SetSingleDataAsync("4X 1", dic1["4X 1"]); await _modbusTcpMachine!.BaseUtility.GetUtilityMethods<IUtilityMethodWriteSingle>().SetSingleDataAsync("4X 1", dic1["4X 1"]);
await _modbusAsciiMachine.BaseUtility.GetUtilityMethods<IUtilityMethodWriteSingle>().SetSingleDataAsync("4X 1", dic1["4X 1"]); await _modbusAsciiMachine!.BaseUtility.GetUtilityMethods<IUtilityMethodWriteSingle>().SetSingleDataAsync("4X 1", dic1["4X 1"]);
await _modbusRtuMachine.BaseUtility.GetUtilityMethods<IUtilityMethodWriteSingle>().SetSingleDataAsync("4X 1", dic1["4X 1"]); await _modbusRtuMachine!.BaseUtility.GetUtilityMethods<IUtilityMethodWriteSingle>().SetSingleDataAsync("4X 1", dic1["4X 1"]);
var ans = await _modbusTcpMachine.BaseUtility.GetUtilityMethods<IUtilityMethodData>().GetDatasAsync<ushort>("4X 1", 1); var ans = await _modbusTcpMachine.BaseUtility.GetUtilityMethods<IUtilityMethodData>().GetDatasAsync<ushort>("4X 1", 1);
var ans2 = await _modbusRtuMachine.BaseUtility.GetUtilityMethods<IUtilityMethodData>().GetDatasAsync<ushort>("4X 1", 1); var ans2 = await _modbusRtuMachine.BaseUtility.GetUtilityMethods<IUtilityMethodData>().GetDatasAsync<ushort>("4X 1", 1);
var ans3 = await _modbusAsciiMachine.BaseUtility.GetUtilityMethods<IUtilityMethodData>().GetDatasAsync<ushort>("4X 1", 1); var ans3 = await _modbusAsciiMachine.BaseUtility.GetUtilityMethods<IUtilityMethodData>().GetDatasAsync<ushort>("4X 1", 1);
@@ -316,9 +316,9 @@ namespace Modbus.Net.Tests
[TestCleanup] [TestCleanup]
public void MachineClean() public void MachineClean()
{ {
_modbusAsciiMachine.Disconnect(); _modbusAsciiMachine!.Disconnect();
_modbusRtuMachine.Disconnect(); _modbusRtuMachine!.Disconnect();
_modbusTcpMachine.Disconnect(); _modbusTcpMachine!.Disconnect();
} }
} }
} }

View File

@@ -10,7 +10,7 @@ namespace Modbus.Net.Tests
[TestClass] [TestClass]
public class SiemensTest public class SiemensTest
{ {
private BaseMachine _siemensTcpMachine; private BaseMachine? _siemensTcpMachine;
[TestInitialize] [TestInitialize]
public void Init() public void Init()
@@ -43,7 +43,7 @@ namespace Modbus.Net.Tests
} }
}; };
_siemensTcpMachine.GetAddresses = addresses; _siemensTcpMachine!.GetAddresses = addresses;
await _siemensTcpMachine.SetDatasAsync(MachineDataType.Address, dic1); await _siemensTcpMachine.SetDatasAsync(MachineDataType.Address, dic1);
var ans = await _siemensTcpMachine.GetDatasAsync(MachineDataType.Address); var ans = await _siemensTcpMachine.GetDatasAsync(MachineDataType.Address);
@@ -66,7 +66,7 @@ namespace Modbus.Net.Tests
} }
}; };
_siemensTcpMachine.GetAddresses = addresses; _siemensTcpMachine!.GetAddresses = addresses;
var ans = await _siemensTcpMachine.GetDatasAsync(MachineDataType.Address); var ans = await _siemensTcpMachine.GetDatasAsync(MachineDataType.Address);
Assert.AreEqual(ans["I 0.0"].DeviceValue, 0); Assert.AreEqual(ans["I 0.0"].DeviceValue, 0);
} }
@@ -89,7 +89,7 @@ namespace Modbus.Net.Tests
} }
}; };
_siemensTcpMachine.GetAddresses = addresses; _siemensTcpMachine!.GetAddresses = addresses;
var dic1 = new Dictionary<string, double>() var dic1 = new Dictionary<string, double>()
{ {
@@ -121,7 +121,7 @@ namespace Modbus.Net.Tests
} }
}; };
_siemensTcpMachine.GetAddresses = addresses; _siemensTcpMachine!.GetAddresses = addresses;
var dic1 = new Dictionary<string, double>() var dic1 = new Dictionary<string, double>()
{ {
@@ -161,7 +161,7 @@ namespace Modbus.Net.Tests
} }
}; };
_siemensTcpMachine.GetAddresses = addresses; _siemensTcpMachine!.GetAddresses = addresses;
await _siemensTcpMachine.SetDatasAsync(MachineDataType.Address, dic1); await _siemensTcpMachine.SetDatasAsync(MachineDataType.Address, dic1);
var ans = await _siemensTcpMachine.GetDatasAsync(MachineDataType.Address); var ans = await _siemensTcpMachine.GetDatasAsync(MachineDataType.Address);
@@ -253,7 +253,7 @@ namespace Modbus.Net.Tests
}, },
}; };
_siemensTcpMachine.GetAddresses = addresses; _siemensTcpMachine!.GetAddresses = addresses;
await _siemensTcpMachine.SetDatasAsync(MachineDataType.CommunicationTag, dic1); await _siemensTcpMachine.SetDatasAsync(MachineDataType.CommunicationTag, dic1);
var ans = await _siemensTcpMachine.GetDatasAsync(MachineDataType.CommunicationTag); var ans = await _siemensTcpMachine.GetDatasAsync(MachineDataType.CommunicationTag);
Assert.AreEqual(ans["A1"].DeviceValue, dic1["A1"]); Assert.AreEqual(ans["A1"].DeviceValue, dic1["A1"]);
@@ -267,7 +267,7 @@ namespace Modbus.Net.Tests
[TestCleanup] [TestCleanup]
public void MachineClean() public void MachineClean()
{ {
_siemensTcpMachine.Disconnect(); _siemensTcpMachine!.Disconnect();
} }
} }
} }