|
@@ -53,7 +53,23 @@ namespace CyberX8_Simulator.Devices
|
|
|
/// <summary>
|
|
|
/// 定时器
|
|
|
/// </summary>
|
|
|
- private PeriodicJob _periodicJob;
|
|
|
+ private PeriodicJob _periodicJob;
|
|
|
+
|
|
|
+ //delegate
|
|
|
+ #region Delegate
|
|
|
+ public delegate void VariableValueChanged(object obj);
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 事件
|
|
|
+ /// <summary>
|
|
|
+ /// 变量变更事件
|
|
|
+ /// </summary>
|
|
|
+ public event VariableValueChanged OnDIVariableValueChanged;
|
|
|
+ public event VariableValueChanged OnAIVariableValueChanged;
|
|
|
+ public event VariableValueChanged OnDOVariableValueChanged;
|
|
|
+ public event VariableValueChanged OnAOVariableValueChanged;
|
|
|
+ #endregion
|
|
|
+
|
|
|
public WagoSocketSimulator(int port):base(port)
|
|
|
{
|
|
|
SimulatorCommManager.Instance.OnUpdateVariableValueChanged += UpdataDataCausedByOtherModule;
|
|
@@ -193,6 +209,10 @@ namespace CyberX8_Simulator.Devices
|
|
|
#region 公共方法
|
|
|
public void UpdataDOBytes(string name,int value)
|
|
|
{
|
|
|
+ if (OnDOVariableValueChanged != null)
|
|
|
+ {
|
|
|
+ OnDOVariableValueChanged(name);
|
|
|
+ }
|
|
|
if (DONameIndexDic.ContainsKey(name))
|
|
|
{
|
|
|
if (DONameIndexDic[name] < DOBytes.Length)
|
|
@@ -203,6 +223,11 @@ namespace CyberX8_Simulator.Devices
|
|
|
}
|
|
|
public void UpdataDIBytes(string name, int value)
|
|
|
{
|
|
|
+ if (OnDIVariableValueChanged != null)
|
|
|
+ {
|
|
|
+ OnDIVariableValueChanged(name);
|
|
|
+ }
|
|
|
+
|
|
|
if (DINameIndexDic.ContainsKey(name))
|
|
|
{
|
|
|
if (DINameIndexDic[name] < DIBytes.Length)
|
|
@@ -213,6 +238,10 @@ namespace CyberX8_Simulator.Devices
|
|
|
}
|
|
|
public void UpdataAOShorts(string name, int value)
|
|
|
{
|
|
|
+ if (OnAOVariableValueChanged != null)
|
|
|
+ {
|
|
|
+ OnAOVariableValueChanged(name);
|
|
|
+ }
|
|
|
if (AONameIndexDic.ContainsKey(name))
|
|
|
{
|
|
|
string hexValue = value.ToString("X2");
|
|
@@ -232,6 +261,10 @@ namespace CyberX8_Simulator.Devices
|
|
|
}
|
|
|
public void UpdataAIShorts(string name, int value)
|
|
|
{
|
|
|
+ if (OnAIVariableValueChanged != null)
|
|
|
+ {
|
|
|
+ OnAIVariableValueChanged(name);
|
|
|
+ }
|
|
|
if (AINameIndexDic.ContainsKey(name))
|
|
|
{
|
|
|
string hexValue = value.ToString("X2");
|