Add BaseMachine Extend
This commit is contained in:
@@ -468,18 +468,6 @@ namespace Modbus.Net
|
|||||||
{
|
{
|
||||||
return BaseUtility.Disconnect();
|
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>
|
public class BaseMachineEqualityComparer : IEqualityComparer<BaseMachine>
|
||||||
|
|||||||
24
Modbus.Net/Modbus.Net/BaseMachineExtend.cs
Normal file
24
Modbus.Net/Modbus.Net/BaseMachineExtend.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -54,6 +54,7 @@
|
|||||||
<Compile Include="AddressFormater.cs" />
|
<Compile Include="AddressFormater.cs" />
|
||||||
<Compile Include="AddressTranslator.cs" />
|
<Compile Include="AddressTranslator.cs" />
|
||||||
<Compile Include="AsyncHelper.cs" />
|
<Compile Include="AsyncHelper.cs" />
|
||||||
|
<Compile Include="BaseMachineExtend.cs" />
|
||||||
<Compile Include="BaseProtocal.cs" />
|
<Compile Include="BaseProtocal.cs" />
|
||||||
<Compile Include="BaseUtility.cs" />
|
<Compile Include="BaseUtility.cs" />
|
||||||
<Compile Include="BaseMachine.cs" />
|
<Compile Include="BaseMachine.cs" />
|
||||||
|
|||||||
@@ -65,8 +65,7 @@ namespace NA200H.UI.WPF
|
|||||||
machine.AddressCombiner = new AddressCombinerContinus(machine.AddressTranslator);
|
machine.AddressCombiner = new AddressCombinerContinus(machine.AddressTranslator);
|
||||||
machine.AddressCombinerSet = new AddressCombinerContinus(machine.AddressTranslator);
|
machine.AddressCombinerSet = new AddressCombinerContinus(machine.AddressTranslator);
|
||||||
}
|
}
|
||||||
var result = machine.GetDatas(MachineGetDataType.CommunicationTag);
|
var resultFormat = machine.GetDatas(MachineGetDataType.CommunicationTag).MapGetValuesToSetValues();
|
||||||
var resultFormat = BaseMachine.MapGetValuesToSetValues(result);
|
|
||||||
SetValue(new ushort[4] {(ushort)resultFormat["Add1"], (ushort)resultFormat["Add2"], (ushort)resultFormat["Add3"], (ushort)resultFormat["Ans"]});
|
SetValue(new ushort[4] {(ushort)resultFormat["Add1"], (ushort)resultFormat["Add2"], (ushort)resultFormat["Add3"], (ushort)resultFormat["Ans"]});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user