This commit is contained in:
gongxh
2022-05-09 08:59:35 +08:00
parent 64238fee13
commit b39357f27e
7 changed files with 370 additions and 264 deletions

View File

@@ -33,6 +33,26 @@ namespace CleanMachine.Model.BAS
private string remarks4; private string remarks4;
private string remarks5; private string remarks5;
public ushort bitCode
{
get
{
int index = int.Parse(this.warningCode.Replace("bit", ""));
ushort num = 1;
num = (ushort)(num << index);
return num;
}
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>

View File

@@ -21,7 +21,7 @@
<!--<add key="LeadSQLite" value="Data Source=|DataDirectory|\\clearMac.db;Pooling=true;FailIfMissing=false"/>--> <!--<add key="LeadSQLite" value="Data Source=|DataDirectory|\\clearMac.db;Pooling=true;FailIfMissing=false"/>-->
<add key="LeadSQLite" value="Data Source=DataBase/clearMac.db"/> <add key="LeadSQLite" value="Data Source=DataBase/clearMac.db"/>
<!--串口名称--> <!--串口名称-->
<add key="PortName" value="COM2"/> <add key="PortName" value="COM3"/>
<!--串口波特率--> <!--串口波特率-->
<add key="BaudRate" value="9600"/> <add key="BaudRate" value="9600"/>
<!--串口数据位--> <!--串口数据位-->

View File

@@ -171,6 +171,7 @@ namespace CleanMachineHMI.FrmUserControl
} }
//加载当前工作信息 //加载当前工作信息
LoadCurrentWorkingTray(); LoadCurrentWorkingTray();
Thread th1 = new Thread(MainDtlRunTh) Thread th1 = new Thread(MainDtlRunTh)
{ {
IsBackground = true IsBackground = true
@@ -630,6 +631,7 @@ namespace CleanMachineHMI.FrmUserControl
kcmb_SheetType.SelectedIndex = 0; kcmb_SheetType.SelectedIndex = 0;
ktb_IR.Text = ""; ktb_IR.Text = "";
kdtp_RecordDate.Text = ""; kdtp_RecordDate.Text = "";
kdtp_RecordDate.Checked = false; kdtp_RecordDate.Checked = false;
ktb_CompleteNum.Text = "0"; ktb_CompleteNum.Text = "0";

View File

@@ -126,6 +126,46 @@ namespace CleanMachineHMI
//public static List<PlcItem> PlcItemMd_Y_List { get; set; }=new List<PlcItem>(); //public static List<PlcItem> PlcItemMd_Y_List { get; set; }=new List<PlcItem>();
public static List<WarningLog> CheckWarng(ushort id, string PlcItem)
{
var result = new List<WarningLog>();
var list = BasWarningMd_List.FindAll(m => m.PlcItemCode == PlcItem);
foreach (var wag in list)
{
if ((id & wag.bitCode) > 0)
{
result.Add(new WarningLog()
{
WarningCode = wag.WarningCode,
WarningName = wag.WarningName,
WarningType = wag.WarningType,
WarningMessage = wag.WarningMessage,
WarningTime = DateTime.Now,
PlcItemCode = PlcItem,
WaringStatus = 0,
WarningHandleResult = 0,
CreateBy = 1,
CreateTime = DateTime.Now,
UpdateBy = 1,
UpdateTime = DateTime.Now,
DataVersion = 0,
});
}
}
return result;
}
public static List<Warning> BasWarningMd_List { get; set; } public static List<Warning> BasWarningMd_List { get; set; }
public static List<WarningLog> CmWarningLogMd_List { get; set; } public static List<WarningLog> CmWarningLogMd_List { get; set; }

View File

@@ -2,7 +2,7 @@
#if DEBUG #if DEBUG
//#define USE_LOCAL_TCP_DEBUG #define USE_LOCAL_TCP_DEBUG
#endif #endif
//启用心跳检查 //启用心跳检查
@@ -60,6 +60,15 @@ namespace CleanMachineHMI
#endregion #endregion
private PlcOperationHelper()
{
_synchronization = SynchronizationContext.Current;
}
private SynchronizationContext _synchronization;
private byte slaveAddress = byte.Parse(ConfigurationManager.AppSettings["SlaveAddress"]); private byte slaveAddress = byte.Parse(ConfigurationManager.AppSettings["SlaveAddress"]);
@@ -99,24 +108,29 @@ namespace CleanMachineHMI
public List<PlcItem> PlcItemMd_Y_List { get; set; } = new List<PlcItem>(); public List<PlcItem> PlcItemMd_Y_List { get; set; } = new List<PlcItem>();
public void StartRead() //public void StartRead()
{ //{
Thread th = new Thread(RefreshPlcItem) // Thread th = new Thread(RefreshPlcItem)
{ // {
IsBackground = true // IsBackground = true
}; // };
th.Start(); // th.Start();
} //}
// public System.Threading.AutoResetEvent thEvent = new System.Threading.AutoResetEvent(false);
private void RefreshPlcItem() private void RefreshPlcItem()
{ {
while (Global.SysThIsRunFlag) while (Global.SysThIsRunFlag)
{ {
RefreshPlcItem_M(); RefreshPlcItem_M();
Instance.RefreshPlcItem_D(); RefreshPlcItem_D();
Instance.RefreshPlcItem_X(); RefreshPlcItem_X();
Instance.RefreshPlcItem_Y(); RefreshPlcItem_Y();
// thEvent.Set();
// ShowWarningMsg(); // ShowWarningMsg();
Thread.Sleep(100); Thread.Sleep(100);
} }
@@ -308,7 +322,7 @@ namespace CleanMachineHMI
if (item.PlcItemDataLength == 2) if (item.PlcItemDataLength == 2)
{ {
ushort[] tmp_1 = new ushort[] { readBytArr_D[plcItemDeviationAddress], readBytArr_D[plcItemDeviationAddress + 1] }; // ushort[] tmp_1 = new ushort[] { readBytArr_D[plcItemDeviationAddress], readBytArr_D[plcItemDeviationAddress + 1] };
#region 方法一 :Short数组转换为int数据 20201014 孙亚龙 #region 方法一 :Short数组转换为int数据 20201014 孙亚龙
////低位 short 的字节数组。 ////低位 short 的字节数组。
@@ -335,7 +349,32 @@ namespace CleanMachineHMI
} }
} }
} }
HandleWaringLog(tmpReadAlarmBytArr_D); string priStr = "D";
int index = 10;
Global.CmWarningLogMd_List.Clear();
for (var i = 0; i < 9; i++)
{
var plcitem = $"{priStr}{index + i}";
if (tmpReadAlarmBytArr_D[i] != 0)
{
var wanglist = Global.CheckWarng(tmpReadAlarmBytArr_D[i], plcitem);
Global.CmWarningLogMd_List.AddRange(wanglist);
}
}
if (Global.CmWarningLogMd_List.Count() > 0)
{
Global.ShowMainFrmAlarmMsg(true, EventArgs.Empty);
}
else
{
Global.ShowMainFrmAlarmMsg(false, EventArgs.Empty);
}
// HandleWaringLog(tmpReadAlarmBytArr_D);
} }
#if RELEASE #if RELEASE
} }
@@ -346,6 +385,11 @@ namespace CleanMachineHMI
#endif #endif
} }
//报警信息记录 //报警信息记录
private void HandleWaringLog(ushort[] tmpReadAlarmBytArr_D) private void HandleWaringLog(ushort[] tmpReadAlarmBytArr_D)
{ {

View File

@@ -85,16 +85,16 @@ namespace CleanMachineHMI.frmChild
kryptonButton1.Enabled = false; kryptonButton1.Enabled = false;
try try
{ {
Task.Run(async delegate //Task.Run(async delegate
{ //{
if (PlcOperationHelper.Instance.WritePlcItem("AlarmPopUpMsg", "0", PlcItemTypeDesc.D)) if (PlcOperationHelper.Instance.WritePlcItem("AlarmPopUpMsg", "0", PlcItemTypeDesc.D))
{ {
LogHelper.WriteLog($"清空PLC报警提示变量成功!", LogTypeEum.Run); LogHelper.WriteLog($"清空PLC报警提示变量成功!", LogTypeEum.Run);
} }
await Task.Delay(500); // await Task.Delay(500);
Global.PopupWarningMsgForm = null; Global.PopupWarningMsgForm = null;
this.Close(); this.Close();
}); //});
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@@ -222,14 +222,14 @@ namespace CleanMachineHMI
isPlcConnStatus = true; isPlcConnStatus = true;
Global.SysThIsRunFlag = true; Global.SysThIsRunFlag = true;
PlcOperationHelper.Instance.StartRead(); // PlcOperationHelper.Instance.StartRead();
//Thread th = new Thread(RefreshPlcItem) Thread th = new Thread(RefreshPlcItem)
//{ {
// IsBackground = true IsBackground = true
//}; };
//th.Start(); th.Start();
//Thread th = new Thread(RefreshPlcItem_M) //Thread th = new Thread(RefreshPlcItem_M)
@@ -597,49 +597,49 @@ namespace CleanMachineHMI
} }
else if (sysRuningTimeLen >= maintainAlarmTime && sysRuningTimeLen < maintainQuitTime) else if (sysRuningTimeLen >= maintainAlarmTime && sysRuningTimeLen < maintainQuitTime)
{ {
BeginInvoke(new Action(() => //BeginInvoke(new Action(() =>
{ //{
pictureBox1.Visible = true; // pictureBox1.Visible = true;
if (!sysAlarmFrmShowFlag) // if (!sysAlarmFrmShowFlag)
{ // {
sysAlarmFrmShowFlag = true; // sysAlarmFrmShowFlag = true;
frmSysExitAlarm frm = new frmSysExitAlarm(); // frmSysExitAlarm frm = new frmSysExitAlarm();
//frm.showMsg = "机器即将于" + (maintainQuitTime - sysRuningTimeLen) + "分钟后退出。"; // //frm.showMsg = "机器即将于" + (maintainQuitTime - sysRuningTimeLen) + "分钟后退出。";
frm.showMsg = $"The machine will exit in {(maintainQuitTime - sysRuningTimeLen)} minutes."; // frm.showMsg = $"The machine will exit in {(maintainQuitTime - sysRuningTimeLen)} minutes.";
frm.TopLevel = true; // frm.TopLevel = true;
frm.ShowDialog(); // frm.ShowDialog();
} // }
})); //}));
} }
else if (sysRuningTimeLen >= maintainQuitTime) else if (sysRuningTimeLen >= maintainQuitTime)
{ {
BeginInvoke(new Action(() => //BeginInvoke(new Action(() =>
{ //{
pictureBox1.Visible = true; // pictureBox1.Visible = true;
string sql = "SELECT 1 FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0"; // string sql = "SELECT 1 FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0";
DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0]; // DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0];
if (dt != null && dt.Rows.Count > 0) // if (dt != null && dt.Rows.Count > 0)
{ // {
if (!sysAlarmFrmShowFlag) // if (!sysAlarmFrmShowFlag)
{ // {
sysAlarmFrmShowFlag = true; // sysAlarmFrmShowFlag = true;
frmSysExitAlarm frm = new frmSysExitAlarm(); // frmSysExitAlarm frm = new frmSysExitAlarm();
frm.showMsg = $"The machine maintenance time has exceeded: [{(maintainQuitTime - sysRuningTimeLen)}] minutes, please complete the current operation tray as soon as possible, and carry out equipment maintenance !!!!!!"; // frm.showMsg = $"The machine maintenance time has exceeded: [{(maintainQuitTime - sysRuningTimeLen)}] minutes, please complete the current operation tray as soon as possible, and carry out equipment maintenance !!!!!!";
frm.TopLevel = true; // frm.TopLevel = true;
frm.ShowDialog(); // frm.ShowDialog();
} // }
} // }
else // else
{ // {
string sqlUpdateParam = $@"update SYS_PARAMETER set PARAMETER_VALUE = '1' WHERE PARAMETER_CODE = 'MaintainFlag'"; // string sqlUpdateParam = $@"update SYS_PARAMETER set PARAMETER_VALUE = '1' WHERE PARAMETER_CODE = 'MaintainFlag'";
LeadDbHelperSQLite.ExecuteSql(sqlUpdateParam); // LeadDbHelperSQLite.ExecuteSql(sqlUpdateParam);
PlcOperationHelper.Instance.WritePlcItem("StopSys", "True", PlcItemTypeDesc.M); // PlcOperationHelper.Instance.WritePlcItem("StopSys", "True", PlcItemTypeDesc.M);
PlcOperationHelper.Instance.WritePlcItem("StopSys", "False", PlcItemTypeDesc.M); // PlcOperationHelper.Instance.WritePlcItem("StopSys", "False", PlcItemTypeDesc.M);
PlcOperationHelper.Instance.WritePlcItem("ResetSys", "True", PlcItemTypeDesc.M); // PlcOperationHelper.Instance.WritePlcItem("ResetSys", "True", PlcItemTypeDesc.M);
PlcOperationHelper.Instance.WritePlcItem("ResetSys", "False", PlcItemTypeDesc.M); // PlcOperationHelper.Instance.WritePlcItem("ResetSys", "False", PlcItemTypeDesc.M);
Environment.Exit(0); // Environment.Exit(0);
} // }
})); //}));
} }
string sqlUpdateRunTimeLen = $@"UPDATE SYS_PARAMETER set PARAMETER_VALUE = '{sysRuningTimeLen}' WHERE PARAMETER_CODE = 'SysRuningTimeLen'"; string sqlUpdateRunTimeLen = $@"UPDATE SYS_PARAMETER set PARAMETER_VALUE = '{sysRuningTimeLen}' WHERE PARAMETER_CODE = 'SysRuningTimeLen'";
LeadDbHelperSQLite.ExecuteSql(sqlUpdateRunTimeLen); LeadDbHelperSQLite.ExecuteSql(sqlUpdateRunTimeLen);