2015-05-26 update 1 extend fix to support project

This commit is contained in:
parallelbgls@outlook.com
2015-05-26 15:24:50 +08:00
parent 3ca9e55ba3
commit a0e1009e4e
2 changed files with 17 additions and 10 deletions

View File

@@ -6,7 +6,7 @@ namespace ModBus.Net
{
public abstract class BaseMachine : IMachineProperty
{
public string Id { get; set; }
public int Id { get; set; }
public string ProjectName { get; set; }
@@ -21,6 +21,8 @@ namespace ModBus.Net
public AddressCombiner AddressCombiner { get; set; }
public MachineExtend MachineExtend { get; set; }
protected IEnumerable<CommunicationUnit> CommunicateAddresses
{
get { return AddressCombiner.Combine(GetAddresses); }
@@ -61,7 +63,7 @@ namespace ModBus.Net
p => p.Area == communicateAddress.Area && p.Address == pos + communicateAddress.Address);
if (address != null)
{
ans.Add(address.CommunicationTag, new ReturnUnit{PlcValue = String.Format("{0:#0.#}", Math.Round(Single.Parse(ValueHelper.Instance.GetValue(datas, ref pos, address.DataType).ToString()) * address.Zoom, 3)),ExtendUnit = address.ExtendUnit});
ans.Add(address.CommunicationTag, new ReturnUnit{PlcValue = String.Format("{0:#0.#}", Math.Round(Single.Parse(ValueHelper.Instance.GetValue(datas, ref pos, address.DataType).ToString()) * address.Zoom, 3)),UnitExtend = address.UnitExtend});
}
else
{
@@ -108,7 +110,12 @@ namespace ModBus.Net
public Type DataType { get; set; }
}
public class ExtendUnit
public class UnitExtend
{
}
public class MachineExtend
{
}
@@ -116,7 +123,7 @@ namespace ModBus.Net
public class ReturnUnit
{
public string PlcValue { get; set; }
public ExtendUnit ExtendUnit { get; set; }
public UnitExtend UnitExtend { get; set; }
}
public class AddressUnit
@@ -139,7 +146,7 @@ namespace ModBus.Net
public string Name { get; set; }
public string Unit { get; set; }
public ExtendUnit ExtendUnit { get; set; }
public UnitExtend UnitExtend { get; set; }
}
public struct AddressUnitEqualityComparer : IEqualityComparer<AddressUnit>
@@ -157,7 +164,7 @@ namespace ModBus.Net
public interface IMachineProperty
{
string Id { get; set; }
int Id { get; set; }
string ProjectName { get; set; }
string MachineName { get; set; }
string ConnectionToken { get; }

View File

@@ -191,7 +191,7 @@ namespace ModBus.Net
}
}
public delegate void ReturnValuesDelegate(KeyValuePair<string, Dictionary<string,ReturnUnit>> returnValue);
public delegate void ReturnValuesDelegate(KeyValuePair<int, Dictionary<string,ReturnUnit>> returnValue);
public event ReturnValuesDelegate ReturnValues;
@@ -273,7 +273,7 @@ namespace ModBus.Net
}
}
public void RemoveMachineWithId(string id)
public void RemoveMachineWithId(int id)
{
lock (_machines)
{
@@ -335,7 +335,7 @@ namespace ModBus.Net
var ans = _tasks.StartNew(machine.GetDatas).Result;
if (ReturnValues != null)
{
ReturnValues(new KeyValuePair<string, Dictionary<string,ReturnUnit>>(machine.Id, ans));
ReturnValues(new KeyValuePair<int, Dictionary<string,ReturnUnit>>(machine.Id, ans));
}
}
catch (Exception e)
@@ -343,7 +343,7 @@ namespace ModBus.Net
if (ReturnValues != null)
{
ReturnValues(new KeyValuePair<string, Dictionary<string,ReturnUnit>>(machine.Id, null));
ReturnValues(new KeyValuePair<int, Dictionary<string,ReturnUnit>>(machine.Id, null));
}
}
}