Add BaseMachine Extend

This commit is contained in:
parallelbgls
2016-10-14 11:43:20 +08:00
parent 6ad13bf97b
commit c5c816d6c4
4 changed files with 26 additions and 14 deletions

View File

@@ -468,18 +468,6 @@ namespace Modbus.Net
{
return BaseUtility.Disconnect();
}
/// <summary>
/// 将获取的数据转换成可以向设备写入的数据格式
/// </summary>
/// <param name="getValues">获取的数据</param>
/// <returns>写入的数据</returns>
public static Dictionary<string, double> MapGetValuesToSetValues(Dictionary<string, ReturnUnit> getValues)
{
if (getValues == null) return null;
return (from getValue in getValues where getValue.Value.PlcValue != null
select new KeyValuePair<string, double>(getValue.Key, getValue.Value.PlcValue.Value)).ToDictionary(p=>p.Key,p=>p.Value);
}
}
public class BaseMachineEqualityComparer : IEqualityComparer<BaseMachine>

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Modbus.Net
{
public static class BaseMachineExtend
{
/// <summary>
/// 将获取的数据转换成可以向设备写入的数据格式
/// </summary>
/// <param name="getValues">获取的数据</param>
/// <returns>写入的数据</returns>
public static Dictionary<string, double> MapGetValuesToSetValues(this Dictionary<string, ReturnUnit> getValues)
{
if (getValues == null) return null;
return (from getValue in getValues
where getValue.Value.PlcValue != null
select new KeyValuePair<string, double>(getValue.Key, getValue.Value.PlcValue.Value)).ToDictionary(p => p.Key, p => p.Value);
}
}
}

View File

@@ -54,6 +54,7 @@
<Compile Include="AddressFormater.cs" />
<Compile Include="AddressTranslator.cs" />
<Compile Include="AsyncHelper.cs" />
<Compile Include="BaseMachineExtend.cs" />
<Compile Include="BaseProtocal.cs" />
<Compile Include="BaseUtility.cs" />
<Compile Include="BaseMachine.cs" />

View File

@@ -65,8 +65,7 @@ namespace NA200H.UI.WPF
machine.AddressCombiner = new AddressCombinerContinus(machine.AddressTranslator);
machine.AddressCombinerSet = new AddressCombinerContinus(machine.AddressTranslator);
}
var result = machine.GetDatas(MachineGetDataType.CommunicationTag);
var resultFormat = BaseMachine.MapGetValuesToSetValues(result);
var resultFormat = machine.GetDatas(MachineGetDataType.CommunicationTag).MapGetValuesToSetValues();
SetValue(new ushort[4] {(ushort)resultFormat["Add1"], (ushort)resultFormat["Add2"], (ushort)resultFormat["Add3"], (ushort)resultFormat["Ans"]});
}