2015-05-18 update 1
This commit is contained in:
@@ -16,7 +16,7 @@ namespace CrossLampControl.WebApi.Controllers
|
|||||||
|
|
||||||
public CrossLampController()
|
public CrossLampController()
|
||||||
{
|
{
|
||||||
_utility = new SimenseUtility(SimenseType.Tcp, "192.168.3.241,200");
|
_utility = new SimenseUtility(SimenseType.Tcp, "192.168.3.241", SimenseMachineModel.S7_200);
|
||||||
_utility.AddressTranslator = new AddressTranslatorSimense();
|
_utility.AddressTranslator = new AddressTranslatorSimense();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ namespace ModBus.Net
|
|||||||
KeepConnect = keepConnect;
|
KeepConnect = keepConnect;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<string,string> GetDatas()
|
public Dictionary<string,ReturnUnit> GetDatas()
|
||||||
{
|
{
|
||||||
Dictionary<string, string> ans = new Dictionary<string, string>();
|
Dictionary<string, ReturnUnit> ans = new Dictionary<string, ReturnUnit>();
|
||||||
if (!BaseUtility.IsConnected)
|
if (!BaseUtility.IsConnected)
|
||||||
{
|
{
|
||||||
BaseUtility.Connect();
|
BaseUtility.Connect();
|
||||||
@@ -61,7 +61,7 @@ namespace ModBus.Net
|
|||||||
p => p.Area == communicateAddress.Area && p.Address == pos + communicateAddress.Address);
|
p => p.Area == communicateAddress.Area && p.Address == pos + communicateAddress.Address);
|
||||||
if (address != null)
|
if (address != null)
|
||||||
{
|
{
|
||||||
ans.Add(address.CommunicationTag, (String.Format("{0:#0.#}", Math.Round(Double.Parse(ValueHelper.Instance.GetValue(datas, ref pos, address.DataType).ToString()) * address.Zoom, 3))));
|
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});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -100,7 +100,7 @@ namespace ModBus.Net
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct CommunicationUnit
|
public class CommunicationUnit
|
||||||
{
|
{
|
||||||
public string Area { get; set; }
|
public string Area { get; set; }
|
||||||
public int Address { get; set; }
|
public int Address { get; set; }
|
||||||
@@ -108,6 +108,17 @@ namespace ModBus.Net
|
|||||||
public Type DataType { get; set; }
|
public Type DataType { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ExtendUnit
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ReturnUnit
|
||||||
|
{
|
||||||
|
public string PlcValue { get; set; }
|
||||||
|
public ExtendUnit ExtendUnit { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class AddressUnit
|
public class AddressUnit
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
@@ -127,6 +138,8 @@ namespace ModBus.Net
|
|||||||
public string CommunicationTag { get; set; }
|
public string CommunicationTag { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string Unit { get; set; }
|
public string Unit { get; set; }
|
||||||
|
|
||||||
|
public ExtendUnit ExtendUnit { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct AddressUnitEqualityComparer : IEqualityComparer<AddressUnit>
|
public struct AddressUnitEqualityComparer : IEqualityComparer<AddressUnit>
|
||||||
|
|||||||
@@ -71,15 +71,25 @@ namespace ModBus.Net
|
|||||||
public virtual OutputStruct SendReceive(ProtocalUnit unit, InputStruct content)
|
public virtual OutputStruct SendReceive(ProtocalUnit unit, InputStruct content)
|
||||||
{
|
{
|
||||||
int t = 0;
|
int t = 0;
|
||||||
//如果为特别处理协议的话,跳过协议扩展收缩
|
//如果为特别处理协议的话,跳过协议扩展收缩
|
||||||
if (unit is SpecialProtocalUnit)
|
var formatContent = unit.Format(content);
|
||||||
|
if (formatContent != null)
|
||||||
{
|
{
|
||||||
return unit.Unformat(ProtocalLinker.SendReceiveWithoutExtAndDec(unit.Format(content)), ref t);
|
byte[] receiveContent;
|
||||||
}
|
if (unit is SpecialProtocalUnit)
|
||||||
else
|
{
|
||||||
{
|
receiveContent = ProtocalLinker.SendReceiveWithoutExtAndDec(formatContent);
|
||||||
return unit.Unformat(ProtocalLinker.SendReceive(unit.Format(content)), ref t);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
receiveContent = ProtocalLinker.SendReceive(formatContent);
|
||||||
|
}
|
||||||
|
if (receiveContent != null)
|
||||||
|
{
|
||||||
|
return unit.Unformat(receiveContent, ref t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ namespace ModBus.Net
|
|||||||
public class TaskManager
|
public class TaskManager
|
||||||
{
|
{
|
||||||
private HashSet<BaseMachine> _machines;
|
private HashSet<BaseMachine> _machines;
|
||||||
private TaskFactory<Dictionary<string,string>> _tasks;
|
private TaskFactory<Dictionary<string,ReturnUnit>> _tasks;
|
||||||
private TaskScheduler _scheduler;
|
private TaskScheduler _scheduler;
|
||||||
private CancellationTokenSource _cts;
|
private CancellationTokenSource _cts;
|
||||||
private Timer _timer;
|
private Timer _timer;
|
||||||
@@ -191,7 +191,7 @@ namespace ModBus.Net
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public delegate void ReturnValuesDelegate(KeyValuePair<string, Dictionary<string,string>> returnValue);
|
public delegate void ReturnValuesDelegate(KeyValuePair<string, Dictionary<string,ReturnUnit>> returnValue);
|
||||||
|
|
||||||
public event ReturnValuesDelegate ReturnValues;
|
public event ReturnValuesDelegate ReturnValues;
|
||||||
|
|
||||||
@@ -304,7 +304,7 @@ namespace ModBus.Net
|
|||||||
{
|
{
|
||||||
TaskStop();
|
TaskStop();
|
||||||
_cts = new CancellationTokenSource();
|
_cts = new CancellationTokenSource();
|
||||||
_tasks = new TaskFactory<Dictionary<string,string>>(_cts.Token, TaskCreationOptions.None, TaskContinuationOptions.None, _scheduler);
|
_tasks = new TaskFactory<Dictionary<string,ReturnUnit>>(_cts.Token, TaskCreationOptions.None, TaskContinuationOptions.None, _scheduler);
|
||||||
GetCycle = TimeRestore.Restore;
|
GetCycle = TimeRestore.Restore;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,7 +335,7 @@ namespace ModBus.Net
|
|||||||
var ans = _tasks.StartNew(machine.GetDatas).Result;
|
var ans = _tasks.StartNew(machine.GetDatas).Result;
|
||||||
if (ReturnValues != null)
|
if (ReturnValues != null)
|
||||||
{
|
{
|
||||||
ReturnValues(new KeyValuePair<string, Dictionary<string,string>>(machine.Id, ans));
|
ReturnValues(new KeyValuePair<string, Dictionary<string,ReturnUnit>>(machine.Id, ans));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -343,7 +343,7 @@ namespace ModBus.Net
|
|||||||
|
|
||||||
if (ReturnValues != null)
|
if (ReturnValues != null)
|
||||||
{
|
{
|
||||||
ReturnValues(new KeyValuePair<string, Dictionary<string,string>>(machine.Id, null));
|
ReturnValues(new KeyValuePair<string, Dictionary<string,ReturnUnit>>(machine.Id, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user