This commit is contained in:
gongxh
2022-05-10 15:21:13 +08:00
parent 8f9e5a8ee2
commit f9f8e587d1
22 changed files with 1216 additions and 831 deletions

View File

@@ -182,15 +182,16 @@ namespace CleanMachineHMI
public static bool SysThIsRunFlag { get; set; }
#region 委托事件
//定义一个委托类型的事件
public static event EventHandler<EventArgs> OnShowX_Y_Status;
public static bool eventLock = false;
public static void ShowX_Y_Status(object sender, EventArgs e)
{
if (!eventLock)
{
OnShowX_Y_Status?.Invoke(sender, e);
}
}
//public static event EventHandler<EventArgs> OnShowX_Y_Status;
//public static void ShowX_Y_Status(object sender, EventArgs e)
//{
// if (!eventLock)
// {
// OnShowX_Y_Status?.Invoke(sender, e);
// }
//}
//定义一个委托类型的事件
public static event EventHandler<EventArgs> OnShowSensorStatus;
public static void ShowSensorStatus(object sender, EventArgs e)
@@ -200,7 +201,7 @@ namespace CleanMachineHMI
OnShowSensorStatus?.Invoke(sender, e);
}
}
//定义一个委托类型的事件
// 定义一个委托类型的事件
public static event EventHandler<EventArgs> OnShowMainFrmAlarmMsg;
public static bool eventAlarmLock = false;
public static void ShowMainFrmAlarmMsg(object sender, EventArgs e)

View File

@@ -79,8 +79,31 @@ namespace CleanMachineHMI
}
public delegate void ShowX_Y_Status(IEnumerable<PlcItem> plcItem);
public event ShowX_Y_Status OnShowX_Y_Status;
private void PostShowX_Y_Status(object data)
{
var _data = data as IEnumerable<PlcItem>;
OnShowX_Y_Status?.Invoke(_data);
}
public void DoShowX_Y_Status(IEnumerable<PlcItem> plcItem)
{
if (_synchronization != null)
{
_synchronization.Post(this.PostShowX_Y_Status, plcItem);
// OnShowX_Y_Status?.Invoke(plcItem);
}
}
@@ -98,11 +121,7 @@ namespace CleanMachineHMI
{
get
{
return this._isConn;
}
set { this._isConn = value; }
}
@@ -144,7 +163,7 @@ namespace CleanMachineHMI
{
while (Global.SysThIsRunFlag)
{
var haschange=false;
var haschange = false;
RefreshPlcItem_M(ref haschange);
RefreshPlcItem_D(ref haschange);
RefreshPlcItem_X(ref haschange);
@@ -176,17 +195,17 @@ namespace CleanMachineHMI
{
switch (plcitem.PlcItemDataType)
{
case 0:
case PlcItemTypeDesc.M:
PlcItemMd_M_List.Add(plcitem);
break;
case 1:
case PlcItemTypeDesc.D:
PlcItemMd_D_List.Add(plcitem);
break;
case 2:
case PlcItemTypeDesc.X:
PlcItemMd_X_List.Add(plcitem);
break;
case 3:
case PlcItemTypeDesc.Y:
PlcItemMd_Y_List.Add(plcitem);
break;
}
@@ -338,6 +357,7 @@ namespace CleanMachineHMI
try
{
#endif
ushort[] tmpReadAlarmBytArr_D = master.ReadHoldingRegisters(slaveAddress, 4106, 50);
ushort[] readBytArr_D = master.ReadHoldingRegisters(slaveAddress, 4505, 50);
if (readBytArr_D.Length > 0 && tmpReadAlarmBytArr_D.Length > 0)
@@ -396,8 +416,10 @@ namespace CleanMachineHMI
if (item.PlcItemValue != value)
{
haschange = true;
item.PlcItemValue = value;
}
item.PlcItemValue = value;
}
@@ -789,6 +811,7 @@ namespace CleanMachineHMI
try
{
#endif
List<PlcItem> changeItems = new List<PlcItem>();
bool[] readBytArr_X = master.ReadInputs(slaveAddress, 1024, 50);
if (readBytArr_X.Length > 0)
//if(true)
@@ -810,7 +833,9 @@ namespace CleanMachineHMI
{
haschange = true;
item.PlcItemValue = value;
Global.ShowX_Y_Status(item, new EventArgs());
// this.DoShowX_Y_Status(item);
changeItems.Add(item);
// Global.ShowX_Y_Status(item, new EventArgs());
Global.ShowSensorStatus(item, new EventArgs());
}
@@ -826,6 +851,8 @@ namespace CleanMachineHMI
}
}
this.DoShowX_Y_Status(changeItems);
}
}
#if RELEASE
@@ -843,6 +870,9 @@ namespace CleanMachineHMI
try
{
#endif
List<PlcItem> changeItems = new List<PlcItem>();
bool[] readBytArr_Y = master.ReadCoils(slaveAddress, 1280, 50);
if (readBytArr_Y.Length > 0)
//if(true)
@@ -863,22 +893,19 @@ namespace CleanMachineHMI
{
if (item.PlcItemValue != value)
{
haschange=true;
haschange = true;
item.PlcItemValue = value;
Global.ShowX_Y_Status(item, new EventArgs());
changeItems.Add(item);
// this.DoShowX_Y_Status(item);
// Global.ShowX_Y_Status(item, new EventArgs());
}
}
//Random r = new Random();
//item.PlcItemValue = r.Next(0, 2) == 0 ? "False" : "True";
}
}
this.DoShowX_Y_Status(changeItems);
}
}
#if RELEASE
@@ -900,7 +927,7 @@ namespace CleanMachineHMI
{
return null;
}
if (item.PlcItemDataType == 1)
if (item.PlcItemDataType == PlcItemTypeDesc.D)
{
if (string.IsNullOrEmpty(item.PlcItemValue))
@@ -1157,23 +1184,5 @@ namespace CleanMachineHMI
public enum PlcItemTypeDesc
{
/// <summary>
/// M 类型布尔变量
/// </summary>
M,
/// <summary>
/// D 类型整数变量
/// </summary>
D,
/// <summary>
/// X 类型布尔变量
/// </summary>
X,
/// <summary>
/// Y 类型布尔变量
/// </summary>
Y
}
}