首次上传
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,508 @@
|
||||
using System.Xml;
|
||||
using Aitex.Core.RT.DataCenter;
|
||||
using Aitex.Core.RT.Device;
|
||||
using Aitex.Core.RT.Event;
|
||||
using Aitex.Core.RT.IOCore;
|
||||
using Aitex.Core.RT.OperationCenter;
|
||||
using Aitex.Core.RT.SCCore;
|
||||
using Aitex.Core.Util;
|
||||
|
||||
namespace SicModules.Devices
|
||||
{
|
||||
public class IoLoadRotation : BaseDevice, IDevice
|
||||
{
|
||||
private DIAccessor _diServoOn = null;
|
||||
private DIAccessor _diServoBusy = null;
|
||||
private DIAccessor _diServoError = null;
|
||||
private DIAccessor _diMoveDone = null;
|
||||
private DIAccessor _diRelativeHomeDone = null;
|
||||
private DIAccessor _diOneCircleDone = null;
|
||||
private DIAccessor _diCCD1PosDone = null;
|
||||
private DIAccessor _diCCD2PosDone = null;
|
||||
|
||||
private DOAccessor _doServoOn = null;
|
||||
private DOAccessor _doServoReset = null;
|
||||
private DOAccessor _doJogCW = null;
|
||||
private DOAccessor _doJogCCW = null;
|
||||
private DOAccessor _doStop = null;
|
||||
private DOAccessor _doMoveRelativeHome = null;
|
||||
private DOAccessor _doMoveOneCircle = null;
|
||||
private DOAccessor _doMoveCCD1Pos = null;
|
||||
private DOAccessor _doMoveCCD2Pos = null;
|
||||
|
||||
private AIAccessor _aiCurPos = null;
|
||||
private AIAccessor _aiCCD1Degree = null;
|
||||
private AIAccessor _aiCCD2Degree = null;
|
||||
|
||||
private AOAccessor _aoHomeOffset = null;
|
||||
private AOAccessor _aoJogDegree = null;
|
||||
private AOAccessor _aoCCD1Degree = null;
|
||||
private AOAccessor _aoHomeSpeed = null;
|
||||
private AOAccessor _aoPosSpeed = null;
|
||||
private AOAccessor _aoCCD2Degree = null;
|
||||
|
||||
private SCConfigItem _scHomeSpeed;
|
||||
private SCConfigItem _scHomeOffset;
|
||||
private SCConfigItem _scPosSpeed;
|
||||
private SCConfigItem _scCCD1Pos;
|
||||
private SCConfigItem _scCCD2Pos;
|
||||
|
||||
private DeviceTimer _timer = new DeviceTimer();
|
||||
|
||||
public bool IsServoOn
|
||||
{
|
||||
get { return _diServoOn != null ? _diServoOn.Value : false; }
|
||||
}
|
||||
|
||||
public bool IsServoBusy
|
||||
{
|
||||
get { return _diServoBusy != null ? _diServoBusy.Value : false; }
|
||||
}
|
||||
|
||||
public bool IsServoError
|
||||
{
|
||||
get { return _diServoError != null ? _diServoError.Value : false; }
|
||||
}
|
||||
|
||||
public bool IsMoveDone
|
||||
{
|
||||
get { return _diMoveDone != null ? _diMoveDone.Value : false; }
|
||||
}
|
||||
|
||||
public double CurPos
|
||||
{
|
||||
get { return _aiCurPos != null ? _aiCurPos.Value : 0; }
|
||||
}
|
||||
|
||||
public double CCD1Degree
|
||||
{
|
||||
get { return _aiCCD1Degree != null ? _aiCCD1Degree.Value : 0; }
|
||||
}
|
||||
|
||||
public double CCD2Degree
|
||||
{
|
||||
get { return _aiCCD2Degree != null ? _aiCCD2Degree.Value : 0; }
|
||||
}
|
||||
|
||||
public IoLoadRotation(string module, XmlElement node, string ioModule = "")
|
||||
{
|
||||
var attrModule = node.GetAttribute("module");
|
||||
base.Module = string.IsNullOrEmpty(attrModule) ? module : attrModule;
|
||||
|
||||
base.Name = node.GetAttribute("id");
|
||||
base.Display = node.GetAttribute("display");
|
||||
base.DeviceID = node.GetAttribute("schematicId");
|
||||
|
||||
_diServoOn = ParseDiNode("diServoOn", node, ioModule);
|
||||
_diServoBusy = ParseDiNode("diServoBusy", node, ioModule);
|
||||
_diServoError = ParseDiNode("diServoError", node, ioModule);
|
||||
_diMoveDone = ParseDiNode("diMoveDone", node, ioModule);
|
||||
_diRelativeHomeDone = ParseDiNode("diRelativeHomeDone", node, ioModule);
|
||||
_diOneCircleDone = ParseDiNode("diOneCircleDone", node, ioModule);
|
||||
_diCCD1PosDone = ParseDiNode("diCCD1PosDone", node, ioModule);
|
||||
_diCCD2PosDone = ParseDiNode("diCCD2PosDone", node, ioModule);
|
||||
|
||||
_doServoOn = ParseDoNode("doServoOn", node, ioModule);
|
||||
_doServoReset = ParseDoNode("doServoReset", node, ioModule);
|
||||
_doJogCW = ParseDoNode("doJogCW", node, ioModule);
|
||||
_doJogCCW = ParseDoNode("doJogCCW", node, ioModule);
|
||||
_doStop = ParseDoNode("doStop", node, ioModule);
|
||||
_doMoveRelativeHome = ParseDoNode("doMoveRelativeHome", node, ioModule);
|
||||
_doMoveOneCircle = ParseDoNode("doMoveOneCircle", node, ioModule);
|
||||
_doMoveCCD1Pos = ParseDoNode("doMoveCCD1Pos", node, ioModule);
|
||||
_doMoveCCD2Pos = ParseDoNode("doMoveCCD2Pos", node, ioModule);
|
||||
|
||||
_aiCurPos = ParseAiNode("aiCurPos", node, ioModule);
|
||||
_aiCCD1Degree = ParseAiNode("aiCCD1Degree", node, ioModule);
|
||||
_aiCCD2Degree = ParseAiNode("aiCCD2Degree", node, ioModule);
|
||||
|
||||
_aoHomeOffset = ParseAoNode("aoHomeOffset", node, ioModule);
|
||||
_aoJogDegree = ParseAoNode("aoJogDegree", node, ioModule);
|
||||
_aoCCD1Degree = ParseAoNode("aoCCD1Degree", node, ioModule);
|
||||
_aoHomeSpeed = ParseAoNode("aoHomeSpeed", node, ioModule);
|
||||
_aoPosSpeed = ParseAoNode("aoPosSpeed", node, ioModule);
|
||||
_aoCCD2Degree = ParseAoNode("aoCCD2Degree", node, ioModule);
|
||||
|
||||
_scHomeOffset = ParseScNode("HomeOffset", node, "LoadLock", "LoadLock.LoadRotation.HomeOffset");
|
||||
_scHomeSpeed = ParseScNode("MoveHomeSpeed", node, "LoadLock", "LoadLock.LoadRotation.MoveHomeSpeed");
|
||||
_scPosSpeed = ParseScNode("MoveHomeSpeed", node, "LoadLock", "LoadLock.LoadRotation.MovePosSpeed");
|
||||
_scCCD1Pos = ParseScNode("CCD1Pos", node, "LoadLock", "LoadLock.LoadRotation.CCD1Pos");
|
||||
_scCCD2Pos = ParseScNode("CCD2Pos", node, "LoadLock", "LoadLock.LoadRotation.CCD2Pos");
|
||||
}
|
||||
|
||||
public bool Initialize()
|
||||
{
|
||||
DATA.Subscribe($"{Module}.{Name}.IsServoOn", () => IsServoOn);
|
||||
DATA.Subscribe($"{Module}.{Name}.IsServoBusy", () => IsServoBusy);
|
||||
DATA.Subscribe($"{Module}.{Name}.IsServoError", () => IsServoError);
|
||||
DATA.Subscribe($"{Module}.{Name}.IsMoveDone", () => IsMoveDone);
|
||||
DATA.Subscribe($"{Module}.{Name}.CurPos", () => CurPos);
|
||||
DATA.Subscribe($"{Module}.{Name}.CCD1Degree", () => CCD1Degree);
|
||||
DATA.Subscribe($"{Module}.{Name}.CCD2Degree", () => CCD2Degree);
|
||||
|
||||
OP.Subscribe($"{Module}.{Name}.ServoOn", (function, args) =>
|
||||
{
|
||||
bool ret = ServoOn(out string reason);
|
||||
if (!ret)
|
||||
{
|
||||
EV.PostWarningLog(Module, reason);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
OP.Subscribe($"{Module}.{Name}.ServoReset", (function, args) =>
|
||||
{
|
||||
bool ret = ServoReset(out string reason);
|
||||
if (!ret)
|
||||
{
|
||||
EV.PostWarningLog(Module, reason);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
OP.Subscribe($"{Module}.{Name}.HomeOffset", (function, args) =>
|
||||
{
|
||||
bool ret = HomeOffset((float)_scHomeOffset.DoubleValue, out string reason);
|
||||
if (!ret)
|
||||
{
|
||||
EV.PostWarningLog(Module, reason);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
OP.Subscribe($"{Module}.{Name}.JogCW", (function, args) =>
|
||||
{
|
||||
bool ret = JogCW((float)args[0],out string reason);
|
||||
if (!ret)
|
||||
{
|
||||
EV.PostWarningLog(Module, reason);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
OP.Subscribe($"{Module}.{Name}.JogCCW", (function, args) =>
|
||||
{
|
||||
bool ret = JogCCW((float)args[0], out string reason);
|
||||
if (!ret)
|
||||
{
|
||||
EV.PostWarningLog(Module, reason);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
OP.Subscribe($"{Module}.{Name}.Stop", (function, args) =>
|
||||
{
|
||||
bool ret = Stop(out string reason);
|
||||
if (!ret)
|
||||
{
|
||||
EV.PostWarningLog(Module, reason);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
OP.Subscribe($"{Module}.{Name}.MoveRelativeHome", (function, args) =>
|
||||
{
|
||||
bool ret = MoveRelativeHome(out string reason);
|
||||
if (!ret)
|
||||
{
|
||||
EV.PostWarningLog(Module, reason);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
OP.Subscribe($"{Module}.{Name}.MoveOneCircle", (function, args) =>
|
||||
{
|
||||
bool ret = MoveOneCircle(out string reason);
|
||||
if (!ret)
|
||||
{
|
||||
EV.PostWarningLog(Module, reason);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
OP.Subscribe($"{Module}.{Name}.MoveCCD1Pos", (function, args) =>
|
||||
{
|
||||
bool ret = MoveCCD1Pos(out string reason);
|
||||
if (!ret)
|
||||
{
|
||||
EV.PostWarningLog(Module, reason);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
OP.Subscribe($"{Module}.{Name}.MoveCCD2Pos", (function, args) =>
|
||||
{
|
||||
bool ret = MoveCCD2Pos(out string reason);
|
||||
if (!ret)
|
||||
{
|
||||
EV.PostWarningLog(Module, reason);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ServoOn(out string reason)
|
||||
{
|
||||
if (!_doServoOn.Check(!_diServoOn.Value, out reason))
|
||||
return false;
|
||||
|
||||
if (!_doServoOn.SetValue(!_diServoOn.Value, out reason))
|
||||
return false;
|
||||
|
||||
_timer.Start(200);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ServoReset(out string reason)
|
||||
{
|
||||
if (!_doServoReset.Check(true, out reason))
|
||||
return false;
|
||||
|
||||
if (!_doServoReset.SetValue(true, out reason))
|
||||
return false;
|
||||
|
||||
_timer.Start(200);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool HomeOffset(float relativeDis, out string reason)
|
||||
{
|
||||
if (_diServoBusy.Value || !_diServoOn.Value)
|
||||
{
|
||||
reason = "Load Rotation Busy or not ServoOn";
|
||||
return false;
|
||||
}
|
||||
|
||||
//传进来为相对值
|
||||
_aoJogDegree.Value = relativeDis;
|
||||
_aoPosSpeed.Value = (float)_scPosSpeed.DoubleValue;
|
||||
|
||||
if (!_doJogCW.Check(true, out reason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_doJogCW.SetValue(true, out reason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_timer.Start(200);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool JogCW(float relativeDis, out string reason)
|
||||
{
|
||||
if (_diServoBusy.Value || !_diServoOn.Value)
|
||||
{
|
||||
reason = "Load Rotation Busy or not ServoOn";
|
||||
return false;
|
||||
}
|
||||
|
||||
//传进来为相对值
|
||||
_aoJogDegree.Value = relativeDis;
|
||||
_aoPosSpeed.Value = (float)_scPosSpeed.DoubleValue;
|
||||
|
||||
if (!_doJogCW.Check(true, out reason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_doJogCW.SetValue(true, out reason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_timer.Start(200);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool JogCCW(float relativeDis, out string reason)
|
||||
{
|
||||
if (_diServoBusy.Value || !_diServoOn.Value)
|
||||
{
|
||||
reason = "Load Rotation Busy or not ServoOn";
|
||||
return false;
|
||||
}
|
||||
|
||||
//传进来为相对值
|
||||
_aoJogDegree.Value = relativeDis;
|
||||
_aoPosSpeed.Value = (float)_scPosSpeed.DoubleValue;
|
||||
|
||||
if (!_doJogCCW.Check(true, out reason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_doJogCCW.SetValue(true, out reason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_timer.Start(200);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Stop(out string reason)
|
||||
{
|
||||
if (!_doStop.SetValue(true, out reason))
|
||||
return false;
|
||||
|
||||
_timer.Start(200);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool MoveRelativeHome(out string reason)
|
||||
{
|
||||
if (_diServoBusy.Value || !_diServoOn.Value)
|
||||
{
|
||||
reason = "Load Rotation Busy or not ServoOn";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_doMoveRelativeHome.Check(true, out reason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_aoHomeSpeed.Value = (float)_scHomeSpeed.DoubleValue;
|
||||
_aoHomeOffset.Value = (float)_scHomeOffset.DoubleValue;
|
||||
|
||||
if (!_doMoveRelativeHome.SetValue(true, out reason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_timer.Start(200);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool MoveOneCircle(out string reason)
|
||||
{
|
||||
if (_diServoBusy.Value || !_diServoOn.Value)
|
||||
{
|
||||
reason = "Load Rotation Busy or not ServoOn";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_doMoveOneCircle.Check(true, out reason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_aoPosSpeed.Value = (float)_scPosSpeed.DoubleValue;
|
||||
|
||||
if (!_doMoveOneCircle.SetValue(true, out reason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_timer.Start(200);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool MoveCCD1Pos(out string reason)
|
||||
{
|
||||
if (_diServoBusy.Value || !_diServoOn.Value)
|
||||
{
|
||||
reason = "Load Rotation Busy or not ServoOn";
|
||||
return false;
|
||||
}
|
||||
|
||||
//将参数写入到对应AO中
|
||||
_aoPosSpeed.Value = (float)_scPosSpeed.DoubleValue;
|
||||
_aoCCD1Degree.Value = (float)_scCCD1Pos.DoubleValue;
|
||||
|
||||
if (!_doMoveCCD1Pos.Check(true, out reason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_doMoveCCD1Pos.SetValue(true, out reason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_timer.Start(200);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool MoveCCD2Pos(out string reason)
|
||||
{
|
||||
if (_diServoBusy.Value || !_diServoOn.Value)
|
||||
{
|
||||
reason = "Load Rotation Busy or not ServoOn";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_doMoveCCD2Pos.Check(true, out reason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//将参数写入到对应AO中
|
||||
_aoPosSpeed.Value = (float)_scPosSpeed.DoubleValue;
|
||||
_aoCCD2Degree.Value = (float)_scCCD2Pos.DoubleValue;
|
||||
|
||||
if (!_doMoveCCD2Pos.SetValue(true, out reason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_timer.Start(200);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Monitor()
|
||||
{
|
||||
if (_timer.IsTimeout())
|
||||
{
|
||||
_doServoReset.Value = false;
|
||||
_doJogCW.Value = false;
|
||||
_doJogCCW.Value = false;
|
||||
_doStop.Value = false;
|
||||
_doMoveRelativeHome.Value = false;
|
||||
_doMoveOneCircle.Value = false;
|
||||
_doMoveCCD1Pos.Value = false;
|
||||
_doMoveCCD2Pos.Value = false;
|
||||
|
||||
_timer.Stop();
|
||||
}
|
||||
|
||||
if(_diServoError.Value)
|
||||
{
|
||||
_doServoOn.SetValue(false, out _);
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
}
|
||||
|
||||
public void Terminate()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using Aitex.Core.Common.DeviceData;
|
||||
using Aitex.Core.RT.DataCenter;
|
||||
using Aitex.Core.RT.Device;
|
||||
using Aitex.Core.RT.Event;
|
||||
using Aitex.Core.RT.IOCore;
|
||||
using Aitex.Core.RT.Log;
|
||||
using Aitex.Core.Util;
|
||||
using MECF.Framework.Common.Event;
|
||||
|
||||
namespace SicModules.Devices
|
||||
{
|
||||
public class IoPump: BaseDevice, IDevice
|
||||
{
|
||||
public bool IsRunning
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_diRunning != null)
|
||||
return _diRunning.Value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public bool IsWarning
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_diWarning!= null)
|
||||
return !_diWarning.Value;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool IsAlarm
|
||||
{
|
||||
get
|
||||
{
|
||||
return _diAlarm != null && !_diAlarm.Value;
|
||||
}
|
||||
}
|
||||
public bool IsWaterFlow
|
||||
{
|
||||
get
|
||||
{
|
||||
return _diWaterFlow!= null && _diWaterFlow.Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private AITPumpData DeviceData
|
||||
{
|
||||
get
|
||||
{
|
||||
AITPumpData data = new AITPumpData()
|
||||
{
|
||||
DeviceName = Name,
|
||||
DeviceSchematicId = DeviceID,
|
||||
DisplayName = Display,
|
||||
DeviceModule = Module,
|
||||
Module = Module,
|
||||
|
||||
IsOn = IsRunning,
|
||||
IsError = HasAlarm || IsAlarm,
|
||||
IsWarning = IsWarning,
|
||||
// IsWaterFlowEnable = _diWaterFlow.Value,
|
||||
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private DIAccessor _diRunning = null;
|
||||
private DIAccessor _diOverloadAlarm;
|
||||
private DIAccessor _diWarning;
|
||||
private DIAccessor _diAlarm;
|
||||
private DIAccessor _diWaterFlow;
|
||||
|
||||
//private DOAccessor _doStart;
|
||||
//private DOAccessor _doPowerOn;
|
||||
//private DOAccessor _doResetError;
|
||||
|
||||
private R_TRIG _trigWarning = new R_TRIG();
|
||||
private R_TRIG _trigError = new R_TRIG();
|
||||
private R_TRIG _trigNotRunning = new R_TRIG();
|
||||
|
||||
public AlarmEventItem AlarmOverload { get; set; }
|
||||
public AlarmEventItem AlarmFailedStartStop { get; set; }
|
||||
|
||||
|
||||
|
||||
public IoPump(string module, XmlElement node, string ioModule = "")
|
||||
{
|
||||
var attrModule = node.GetAttribute("module");
|
||||
base.Module = string.IsNullOrEmpty(attrModule) ? module : attrModule;
|
||||
|
||||
base.Name = node.GetAttribute("id");
|
||||
base.Display = node.GetAttribute("display");
|
||||
base.DeviceID = node.GetAttribute("schematicId");
|
||||
|
||||
_diRunning = ParseDiNode("diRunning", node, ioModule);
|
||||
// _diOverloadAlarm = ParseDiNode("diOverloadAlarm", node, ioModule);
|
||||
_diWarning = ParseDiNode("diWarning", node, ioModule);
|
||||
_diAlarm = ParseDiNode("diAlarm", node, ioModule);
|
||||
_diRunning = ParseDiNode("diRunning", node, ioModule);
|
||||
//_diWaterFlow = ParseDiNode("diWaterFlow", node, ioModule);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public bool Initialize()
|
||||
{
|
||||
DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
|
||||
|
||||
DATA.Subscribe($"{Module}.{Name}.IsAlarm", () => IsAlarm);
|
||||
DATA.Subscribe($"{Module}.{Name}.IsRunning", () => IsRunning);
|
||||
DATA.Subscribe($"{Module}.{Name}.IsWarning", () => IsWarning);
|
||||
// DATA.Subscribe($"{Module}.{Name},IsWaterFlowEable", () => IsWaterFlow);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Terminate()
|
||||
{
|
||||
}
|
||||
|
||||
public void Monitor()
|
||||
{
|
||||
try
|
||||
{
|
||||
string s = "";
|
||||
|
||||
_trigWarning.CLK = IsWarning;
|
||||
if (_trigWarning.Q)
|
||||
{
|
||||
if(Name.Contains("1"))
|
||||
{
|
||||
s = "Alarm530 TMDryPump1 Not Runing[DI - 44]"; //"Alarm531 TMDryPump1 Warning [DI-44]";
|
||||
}
|
||||
else
|
||||
{
|
||||
s = "Alarm533 TMDryPump2 Not Runing [DI-79]"; //"Alarm534 TMDryPump2 Warning[DI - 79]";
|
||||
}
|
||||
EV.PostMessage(Module, EventEnum.DefaultAlarm, s);
|
||||
EV.PostAlarmLog(Module, s);
|
||||
}
|
||||
|
||||
_trigError.CLK = IsAlarm;
|
||||
if (_trigError.Q)
|
||||
{
|
||||
if (Name.Contains("1"))
|
||||
{
|
||||
s = "Alarm529 TMDryPump1 Alarm [DI-43]";
|
||||
}
|
||||
else
|
||||
{
|
||||
s = "Alarm532 TMDryPump2 Alarm [DI-78]";
|
||||
}
|
||||
EV.PostAlarmLog(Module, s);
|
||||
}
|
||||
|
||||
_trigNotRunning.CLK = !IsRunning;
|
||||
if (_trigNotRunning.Q)
|
||||
{
|
||||
if (Name.Contains("1"))
|
||||
{
|
||||
s = "Alarm531 TMDryPump1 Warning [DI-49]"; //"Alarm530 TMDryPump1 Not Runing [DI-49]";
|
||||
}
|
||||
else
|
||||
{
|
||||
s = "Alarm534 TMDryPump2 Warning [DI-86]"; // Alarm533 TMDryPump2 Not Runing [DI-86]";
|
||||
}
|
||||
EV.PostAlarmLog(Module, s);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Write(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_trigWarning.RST = true;
|
||||
_trigError.RST = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Xml;
|
||||
|
||||
namespace SicModules.Devices
|
||||
{
|
||||
public class SicAds : TcAds
|
||||
{
|
||||
//public override string Address
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return SC.GetStringValue("PM1.AdsIPAddr");
|
||||
// }
|
||||
//}
|
||||
|
||||
public SicAds(string module, XmlElement node, string ioModule = "") : base(module, node, ioModule)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,371 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using Aitex.Core.RT.Device;
|
||||
using Aitex.Core.RT.IOCore;
|
||||
using Aitex.Core.RT.Log;
|
||||
using Aitex.Core.Util;
|
||||
using MECF.Framework.Common.IOCore;
|
||||
using MECF.Framework.Common.PLC;
|
||||
using MECF.Framework.RT.Core.IoProviders;
|
||||
|
||||
namespace SicModules.Devices
|
||||
{
|
||||
public class SiemensIoProvider : IoProvider
|
||||
{
|
||||
|
||||
|
||||
private IAdsPlc _ads;
|
||||
private static object _locker = new object();
|
||||
|
||||
private R_TRIG _trigConnected = new R_TRIG();
|
||||
|
||||
protected override void SetParameter(XmlElement nodeParameter)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
private bool MonitorAdsConnection()
|
||||
{
|
||||
|
||||
//if (_SiemensClient == null)
|
||||
//{
|
||||
// _SiemensClient = DEVICE.GetDevice<PMModule>(Module + "." + Module)?.Siemens;
|
||||
//}
|
||||
//if (_SiemensClient != null) return _SiemensClient.IsTrue;
|
||||
//return false;
|
||||
|
||||
if (_ads == null)
|
||||
{
|
||||
_ads = DEVICE.GetOptionDevice($"{Module}.MainPLC", typeof(SicAds)) as IAdsPlc;
|
||||
}
|
||||
|
||||
return _ads != null && _ads.CheckIsConnected();
|
||||
}
|
||||
|
||||
//public bool IsCommunicationError
|
||||
//{
|
||||
// get { return _ads.IsCommunicationError; }
|
||||
//}
|
||||
protected override void Close()
|
||||
{
|
||||
|
||||
}
|
||||
protected override void Open()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override bool OnTimer()
|
||||
{
|
||||
_trigConnected.CLK = MonitorAdsConnection();
|
||||
|
||||
if (!_trigConnected.M)
|
||||
return true;
|
||||
|
||||
lock (_locker)
|
||||
{
|
||||
// PLC数据以32位二级制存储,软件读取的值与DINT相同
|
||||
// 如果是DINT类型数据,直接使用,无需转换;
|
||||
// 如果是REAL类型数据,先使用BitConverter.GetBytes获取有4个元素的字节数组,再使用BitConverter.ToSingle,得到float类型值;
|
||||
// 如果是DWORD类型数据,先使用BitConverter.GetBytes获取有4个元素的字节数组,再进行位运算,得到每位的值
|
||||
|
||||
//int[] input = ReadInput();
|
||||
//Console.WriteLine(input[0]);
|
||||
//byte[] byteArr = BitConverter.GetBytes(input[0]);
|
||||
//float fValve = BitConverter.ToSingle(byteArr, 0);
|
||||
|
||||
foreach (var blockIndex in DiVariables.Keys)
|
||||
{
|
||||
var ioVar = DiVariables[blockIndex];
|
||||
var diData = ReadDIn(ioVar.Name, (ushort)ioVar.Length);
|
||||
if (diData != null)
|
||||
{
|
||||
var diBuffer = ParseDI(blockIndex, diData);
|
||||
if (diBuffer != null)
|
||||
{
|
||||
_buffer.SetDiBuffer(_source, ioVar.Block.Index, diBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach (var blockIndex in DoVariables.Keys)
|
||||
{
|
||||
var ioVar = DoVariables[blockIndex];
|
||||
var doData = ReadDOut(ioVar.Name, (ushort)ioVar.Length);
|
||||
if (doData != null)
|
||||
{
|
||||
var doBuffer = ParseDO(blockIndex, doData);
|
||||
if (doBuffer != null)
|
||||
{
|
||||
_buffer.SetDoBuffer(_source, ioVar.Block.Index, doBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach (var blockIndex in AiVariables.Keys)
|
||||
{
|
||||
var ioVar = AiVariables[blockIndex];
|
||||
var aiData = ReadAIn(ioVar.Name, (ushort)ioVar.Length);
|
||||
if (aiData != null)
|
||||
{
|
||||
var aiBuffer = ParseAI(blockIndex, aiData);
|
||||
if (aiBuffer != null)
|
||||
{
|
||||
_buffer.SetAiBuffer(_source, ioVar.Block.Index, aiBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var blockIndex in AoVariables.Keys)
|
||||
{
|
||||
var ioVar = AoVariables[blockIndex];
|
||||
var aoData = ReadAOut(ioVar.Name, (ushort)ioVar.Length);
|
||||
if (aoData != null)
|
||||
{
|
||||
var aoBuffer = ParseAO(blockIndex, aoData);
|
||||
if (aoBuffer != null)
|
||||
{
|
||||
_buffer.SetAoBuffer(_source, ioVar.Block.Index, aoBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
private bool CommunicationError()
|
||||
{
|
||||
//_buffer.SetDiBuffer(_source, 0, new bool[1000]);
|
||||
//_buffer.SetDoBuffer(_source, 0, new bool[1000]);
|
||||
//_buffer.SetAiBufferFloat(_source, 0, new float[500]);
|
||||
//_buffer.SetAoBufferFloat(_source, 0, new float[500]);
|
||||
|
||||
return true;
|
||||
}
|
||||
protected byte[] ReadDIn(string variable, ushort len)
|
||||
{
|
||||
if (!_trigConnected.M)
|
||||
return null;
|
||||
|
||||
if (_ads.BulkReadRenderResult(variable, len, out var data))
|
||||
return data;
|
||||
|
||||
return null;
|
||||
}
|
||||
private byte[] ReadDOut(string variable, ushort len)
|
||||
{
|
||||
if (!_trigConnected.M)
|
||||
return null;
|
||||
|
||||
if (_ads.BulkReadRenderResult(variable, len, out var data))
|
||||
return (byte[])data;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected byte[] ReadAIn(string variable, ushort len)
|
||||
{
|
||||
if (!_trigConnected.M)
|
||||
return null;
|
||||
|
||||
if (_ads.BulkReadRenderResult(variable, len, out var data))
|
||||
return data;
|
||||
|
||||
return null;
|
||||
}
|
||||
private byte[] ReadAOut(string variable, ushort len)
|
||||
{
|
||||
if (!_trigConnected.M)
|
||||
return null;
|
||||
|
||||
if (_ads.BulkReadRenderResult(variable, len, out var data))
|
||||
return (byte[])data;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool[] ParseDI(int blockIndex, byte[] inputValue)
|
||||
{
|
||||
var diList = Singleton<IoManager>.Instance.GetDIList($"{Module}.io").Where(x => x.BlockIndex == blockIndex);
|
||||
|
||||
var result = new bool[1000];
|
||||
foreach (var diAccessor in diList)
|
||||
{
|
||||
var addr = diAccessor.Addr;
|
||||
var index = int.Parse(addr);
|
||||
var Offset = index % 8;
|
||||
var val = index % 8 == 0 ? index / 8 : (index - index % 8) / 8;
|
||||
result[diAccessor.BlockOffset] = ((inputValue[val] >> Offset) & 0x1) == 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private bool[] ParseDO(int blockIndex, byte[] outputValue)
|
||||
{
|
||||
//Addr="OUTPUT[0].4"
|
||||
var doList = Singleton<IoManager>.Instance.GetDOList($"{Module}.io").Where(x => x.BlockIndex == blockIndex);
|
||||
|
||||
var cache = new bool[1000];
|
||||
foreach (var doAccessor in doList)
|
||||
{
|
||||
var addr = doAccessor.Addr;
|
||||
var index = int.Parse(addr);
|
||||
var whichBit = index % 8;
|
||||
var whichByte = index % 8 == 0 ? index / 8 : (index - index % 8) / 8;
|
||||
|
||||
cache[doAccessor.BlockOffset] = ((outputValue[whichByte] >> whichBit) & 0x1) == 1;
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
|
||||
private float[] ParseAI(int blockIndex, byte[] inputValue)
|
||||
{
|
||||
var aiList = Singleton<IoManager>.Instance.GetAIList($"{Module}.io").Where(x => x.BlockIndex == blockIndex);
|
||||
var result = new float[500];
|
||||
foreach (var aiAccessor in aiList)
|
||||
{
|
||||
var addr = aiAccessor.Addr;
|
||||
var index = int.Parse(addr);
|
||||
var valve = BitConverter.ToSingle(new byte[] { inputValue[index * 4 + 3], inputValue[index * 4 + 2], inputValue[index * 4 + 1], inputValue[index * 4] }, 0);
|
||||
result[aiAccessor.BlockOffset] = valve;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private float[] ParseAO(int blockIndex, byte[] outputValue)
|
||||
{
|
||||
//Addr="OUTPUT[30]"
|
||||
var aoList = Singleton<IoManager>.Instance.GetAOList($"{Module}.io").Where(x => x.BlockIndex == blockIndex);
|
||||
|
||||
var result = new float[500];
|
||||
foreach (var aoAccessor in aoList)
|
||||
{
|
||||
var addr = aoAccessor.Addr;
|
||||
var index = int.Parse(addr);
|
||||
var valve = BitConverter.ToSingle(new[]
|
||||
{
|
||||
outputValue[index * 4 + 3],
|
||||
outputValue[index * 4 + 2],
|
||||
outputValue[index * 4 + 1],
|
||||
outputValue[index * 4]
|
||||
},
|
||||
0);
|
||||
result[aoAccessor.BlockOffset] = valve;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
protected override short[] ReadAi(int offset, int size)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override bool[] ReadDi(int offset, int size)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected override void WriteAo(int offset, short[] buffer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override void ReadDo(int offset, bool[] buffer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override short[] ReadAo(int offset, int size)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override void WriteDo(int offset, bool[] buffer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
public override bool SetValue(AOAccessor aoItem, float value)
|
||||
{
|
||||
if (!_trigConnected.M)
|
||||
return false;
|
||||
|
||||
var ioVar = AoVariables[aoItem.BlockIndex];
|
||||
|
||||
//// 获取下标,转换成16进制 IEEE 754浮点数,然后整个写下去
|
||||
var addr = aoItem.Addr;
|
||||
var index = int.Parse(addr);
|
||||
var address = ioVar.Name.Substring(0, 9) + (int.Parse(ioVar.Name.Substring(9, 3)) + index * 4);
|
||||
var data = new byte[4];
|
||||
|
||||
if (index <= 48)
|
||||
{
|
||||
data = BitConverter.GetBytes(value);
|
||||
}
|
||||
else if (index >= 49)
|
||||
{
|
||||
data = BitConverter.GetBytes((int)value);
|
||||
}
|
||||
|
||||
Array.Reverse(data);
|
||||
|
||||
return _ads.BulkWriteByteRenderResult(address, data);
|
||||
}
|
||||
|
||||
public override bool SetValue(DOAccessor doItem, bool value)
|
||||
{
|
||||
if (!_trigConnected.M)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IO.CanSetDO(doItem.Name, value, out var reason))
|
||||
{
|
||||
LOG.Write(reason);
|
||||
return false;
|
||||
}
|
||||
|
||||
lock (_locker)
|
||||
{
|
||||
var ioVar = DoVariables[doItem.BlockIndex];
|
||||
|
||||
////获取单个DWORD数据,修改其中一位,然后整个Byte写下去
|
||||
var addr = doItem.Addr;
|
||||
var add = int.Parse(addr);
|
||||
var indexByte = add % 8;
|
||||
var index = add % 8 == 0 ? add / 8 : (add - add % 8) / 8;
|
||||
var val = 1 << indexByte;
|
||||
var output = ReadDOut(ioVar.Name, (ushort)ioVar.Length);
|
||||
if (output == null)
|
||||
{
|
||||
LOG.Write("ReadDOut = null , in SetValue()");
|
||||
return false;
|
||||
}
|
||||
|
||||
output[index] = value
|
||||
? Convert.ToByte(Convert.ToUInt16(output[index]) | val)
|
||||
: Convert.ToByte((Convert.ToUInt16(output[index]) & ~val));
|
||||
|
||||
var stringSeparators = new string[] { "DBB" };
|
||||
var result = ioVar.Name.Split(stringSeparators, StringSplitOptions.None);
|
||||
int.TryParse(result[1], out var startIndex);
|
||||
var finalIndex = startIndex + index;
|
||||
var address = $"{result[0]}DBB{finalIndex}";
|
||||
var data = new byte[] { output[index] };
|
||||
|
||||
return _ads.BulkWriteByteRenderResult(address, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml;
|
||||
using Aitex.Core.RT.Device;
|
||||
using Aitex.Core.RT.Event;
|
||||
using Aitex.Core.RT.SCCore;
|
||||
using MECF.Framework.Common.Communications;
|
||||
using MECF.Framework.Common.Event;
|
||||
using MECF.Framework.Common.PLC;
|
||||
using MECF.Framework.RT.Core.IoProviders.Siemens;
|
||||
|
||||
namespace SicModules.Devices
|
||||
{
|
||||
|
||||
|
||||
public class TcAds : BaseDevice, IConnectable, IConnectionContext, IDevice, IConnection, IAdsPlc
|
||||
{
|
||||
#region IConnectionContext
|
||||
|
||||
public int RetryConnectIntervalMs => 1000;
|
||||
public int MaxRetryConnectCount => 5;
|
||||
public bool EnableCheckConnection => true;
|
||||
public virtual string Address { get; }
|
||||
public bool IsAscii { get; }
|
||||
public string NewLine { get; }
|
||||
public bool EnableLog { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region IConnectable
|
||||
public event Action<string> OnCommunicationError;
|
||||
public event Action<string> OnAsciiDataReceived;
|
||||
public event Action<byte[]> OnBinaryDataReceived;
|
||||
|
||||
#endregion
|
||||
|
||||
public event Action OnDisconnected;
|
||||
|
||||
bool IAdsPlc.CheckIsConnected()
|
||||
{
|
||||
return Connection.IsConnected;
|
||||
}
|
||||
|
||||
bool IConnection.IsConnected
|
||||
{
|
||||
get
|
||||
{
|
||||
return Connection.IsConnected;
|
||||
}
|
||||
}
|
||||
|
||||
bool IConnection.Connect()
|
||||
{
|
||||
Connect(out _);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IConnection.Disconnect()
|
||||
{
|
||||
Disconnect(out _);
|
||||
return true;
|
||||
}
|
||||
|
||||
public FsmConnection Connection { get; set; } = new FsmConnection();
|
||||
|
||||
|
||||
//public bool IsCommunicationError
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return _isCommunicationError;
|
||||
// }
|
||||
//}
|
||||
|
||||
//private bool _isCommunicationError;
|
||||
|
||||
private OperateResult connect;
|
||||
public SiemensS7Net siemensTcpNet = null;
|
||||
private SiemensPLCS siemensPLCSelected = SiemensPLCS.S1500;
|
||||
private string _plcType;
|
||||
|
||||
private Dictionary<string, int> _nameHandleMap = new Dictionary<string, int>();
|
||||
|
||||
private bool _isTargetConnected;
|
||||
|
||||
public AlarmEventItem AlarmConnectFailed { get; set; }
|
||||
public AlarmEventItem AlarmCommunicationError { get; set; }
|
||||
public event Action OnConnected;
|
||||
|
||||
public TcAds(string module, XmlElement node, string ioModule = "")
|
||||
{
|
||||
var attrModule = node.GetAttribute("module");
|
||||
Module = string.IsNullOrEmpty(attrModule) ? module : attrModule;
|
||||
|
||||
Name = node.GetAttribute("id");
|
||||
|
||||
Address = SC.GetStringValue($"{Module}.SiemensIP");
|
||||
_plcType = SC.GetStringValue($"{Module}.SiemensType");
|
||||
}
|
||||
|
||||
public bool Initialize()
|
||||
{
|
||||
AlarmConnectFailed = SubscribeAlarm($"{Module}.{Name}.ConnectionError", $"Can not connect with {Address}", null);
|
||||
AlarmCommunicationError = SubscribeAlarm($"{Module}.{Name}.CommunicationError", $"Can not Communication {Address}", null);
|
||||
|
||||
Connection = new FsmConnection();
|
||||
Connection.Initialize(100, this, this);
|
||||
|
||||
Connection.OnConnected += Connection_OnConnected;
|
||||
Connection.OnDisconnected += Connection_OnDisconnected;
|
||||
Connection.OnError += Connection_OnError;
|
||||
|
||||
ConnectionManager.Instance.Subscribe($"{Module}.{Name}", this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IConnectable.CheckIsConnected()
|
||||
{
|
||||
return siemensTcpNet != null && siemensTcpNet.IsConnected;
|
||||
}
|
||||
|
||||
public bool Connect(out string reason)
|
||||
{
|
||||
var ipAddr = ParseAdsIPAddr(Address);
|
||||
siemensPLCSelected = (SiemensPLCS)Enum.Parse(typeof(SiemensPLCS), _plcType);
|
||||
siemensTcpNet = new SiemensS7Net(siemensPLCSelected);
|
||||
siemensTcpNet.IpAddress = ipAddr.Item1;// _ipAddress;
|
||||
siemensTcpNet.Port = ipAddr.Item2; // int.Parse(_port);
|
||||
siemensTcpNet.ConnectTimeOut = 1;
|
||||
siemensTcpNet.ReceiveTimeOut = 1000;
|
||||
|
||||
try
|
||||
{
|
||||
if (siemensPLCSelected != SiemensPLCS.S200Smart &&
|
||||
siemensPLCSelected != SiemensPLCS.S200)
|
||||
{
|
||||
siemensTcpNet.Rack = 0;
|
||||
siemensTcpNet.Slot = 0;
|
||||
|
||||
siemensTcpNet.ConnectionType = 1;
|
||||
siemensTcpNet.LocalTSAP = 258;
|
||||
}
|
||||
|
||||
connect = siemensTcpNet.ConnectServer();
|
||||
if (!siemensTcpNet.IsConnected)
|
||||
{
|
||||
//_isCommunicationError = true;
|
||||
//IsConnect = true;
|
||||
//EV.PostInfoLog(Module, "PLC Connection Successful!");
|
||||
}
|
||||
else
|
||||
{
|
||||
//_isCommunicationError = false;
|
||||
}
|
||||
|
||||
//return connect.IsSuccess;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_isTargetConnected = false;
|
||||
//_isCommunicationError = true;
|
||||
reason = ex.Message;
|
||||
return false;
|
||||
}
|
||||
|
||||
_isTargetConnected = true;
|
||||
reason = string.Empty;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Disconnect(out string reason)
|
||||
{
|
||||
reason = string.Empty;
|
||||
siemensTcpNet.ConnectClose();
|
||||
siemensTcpNet = null;
|
||||
connect = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void Connection_OnError(string obj)
|
||||
{
|
||||
AlarmConnectFailed.Set();
|
||||
}
|
||||
|
||||
private void Connection_OnDisconnected()
|
||||
{
|
||||
EV.PostInfoLog(Module, $"Disconnect from PLC {Address}");
|
||||
|
||||
ResetAlarm();
|
||||
}
|
||||
|
||||
private void Connection_OnConnected()
|
||||
{
|
||||
EV.PostInfoLog(Module, $"Connected with PLC {Address}");
|
||||
|
||||
ResetAlarm();
|
||||
}
|
||||
|
||||
public void Monitor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Terminate()
|
||||
{
|
||||
Connection.Terminate();
|
||||
}
|
||||
|
||||
private Tuple<string, int> ParseAdsIPAddr(string addr)
|
||||
{
|
||||
if (addr == null)
|
||||
throw (new Exception("PM.SiemensIP is not exist in sc.data!"));
|
||||
|
||||
Regex reg = new Regex(@"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?):(\d{1,5})$");
|
||||
if (!reg.IsMatch(addr))
|
||||
throw (new Exception($@"{Module}.SiemensIP '{addr}' is invalid!"));
|
||||
|
||||
var item = addr.Split(':');
|
||||
return Tuple.Create(item[0], int.Parse(item[1]));
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
ResetAlarm();
|
||||
|
||||
Connection.InvokeReset();
|
||||
}
|
||||
|
||||
public bool Read(string variableName, out object data, string type, int length, out string reason)
|
||||
{
|
||||
data = null;
|
||||
reason = string.Empty;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool WriteArrayElement(string variableName, int index, object data, out string reason)
|
||||
{
|
||||
reason = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool SendBinaryData(byte[] data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool SendAsciiData(string data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool BulkReadRenderResult(string Adrress, ushort length, out byte[] data)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (siemensTcpNet == null)
|
||||
{
|
||||
data = null;
|
||||
return false;
|
||||
}
|
||||
OperateResult<byte[]> read = siemensTcpNet.Read(Adrress, length);// ushort.Parse(lengthTextBox.Text));
|
||||
if (read.IsSuccess)
|
||||
{
|
||||
data = read.Content;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (!_isCommunicationError)
|
||||
// EV.PostAlarmLog("PLC", $"Communication error with Siemens PLC , {read.Message}");
|
||||
//_isCommunicationError = true;
|
||||
data = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// EV.PostAlarmLog("", "Read Failed:" + ex.Message);
|
||||
}
|
||||
|
||||
data = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool BulkWriteByteRenderResult(string Adrress, byte[] data)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (siemensTcpNet == null)
|
||||
{
|
||||
data = null;
|
||||
return false;
|
||||
}
|
||||
OperateResult write = siemensTcpNet.Write(Adrress, data);
|
||||
if (!write.IsSuccess)
|
||||
{
|
||||
//if (!_isCommunicationError)
|
||||
//EV.PostWarningLog("PLC", $"Communication error with Siemens PLC , {write.Message}");
|
||||
//_isCommunicationError = true;
|
||||
}
|
||||
return write.IsSuccess;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// EV.PostAlarmLog("", "Read Failed:" + ex.Message);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user