添加编译指令

This commit is contained in:
gongxh
2022-01-18 20:20:10 +08:00
parent a7ef9c7b54
commit 89f1bb0536
5 changed files with 707 additions and 640 deletions

View File

@@ -2832,7 +2832,12 @@ namespace CleanMachineHMI.FrmUserControl
}
//自动模式下,打印结束操控 M231 交替 别名: PrintFinish
/// <summary>
/// 自动模式下,打印结束操控 M231 交替 别名: PrintFinish
/// 打印不成功时候按这个重新向PLC发这个指令
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void kryptonButton7_Click(object sender, EventArgs e)
{
if (isManualStatus())

View File

@@ -135,8 +135,10 @@ namespace CleanMachineHMI
}
public void RefreshPlcItem_M()
{
#if !DEBUG
try
{
#endif
bool[] readBytArr_M = master.ReadCoils(slaveAddress, 2248, 50);
bool[] readBytArr_M1 = master.ReadCoils(slaveAddress, 2048, 50);
if (readBytArr_M.Length > 0 && readBytArr_M1.Length > 0)
@@ -170,16 +172,20 @@ namespace CleanMachineHMI
}
}
}
#if !DEBUG
}
catch (Exception ex)
{
LogHelper.WriteLog($"读取M 类型PLC变量时发生异常:【{ex.Message}】", LogTypeEum.Err);
}
#endif
}
public void RefreshPlcItem_D()
{
#if !DEBUG
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)
@@ -231,18 +237,22 @@ namespace CleanMachineHMI
}
HandleWaringLog(tmpReadAlarmBytArr_D);
}
#if !DEBUG
}
catch (Exception ex)
{
LogHelper.WriteLog($"读取D 类型PLC变量时发生异常:【{ex.Message}】", LogTypeEum.Err);
}
#endif
}
//报警信息记录
private void HandleWaringLog(ushort[] tmpReadAlarmBytArr_D)
{
#if !DEBUG
try
{
#endif
int index = 10;
string priStr = "D";
string priWarnCode = "bit";
@@ -565,17 +575,21 @@ namespace CleanMachineHMI
//frmMainNew.Show_ptb_Alarm(false);
GlobalHelper.ShowMainFrmAlarmMsg(false, EventArgs.Empty);
}
#if !DEBUG
}
catch (Exception ex)
{
LogHelper.WriteLog($"处理设备报警信息时发生异常:【{ex.Message}】", LogTypeEum.Err);
}
#endif
}
public void RefreshPlcItem_X()
{
#if !DEBUG
try
{
#endif
bool[] readBytArr_X = master.ReadInputs(slaveAddress, 1024, 50);
if (readBytArr_X.Length > 0)
//if(true)
@@ -600,17 +614,21 @@ namespace CleanMachineHMI
}
}
}
#if !DEBUG
}
catch (Exception ex)
{
LogHelper.WriteLog($"读取X 类型PLC变量时发生异常:【{ex.Message}】", LogTypeEum.Err);
}
#endif
}
public void RefreshPlcItem_Y()
{
#if !DEBUG
try
{
#endif
bool[] readBytArr_Y = master.ReadCoils(slaveAddress, 1280, 50);
if (readBytArr_Y.Length > 0)
//if(true)
@@ -635,17 +653,21 @@ namespace CleanMachineHMI
}
}
}
#if !DEBUG
}
catch (Exception ex)
{
LogHelper.WriteLog($"读取Y 类型PLC变量时发生异常:【{ex.Message}】", LogTypeEum.Err);
}
#endif
}
public object ReadPlcItem(string plcItemCode, PlcItemTypeDesc itemType)
{
#if !DEBUG
try
{
#endif
object retObj;
switch (itemType)
{
@@ -714,6 +736,7 @@ namespace CleanMachineHMI
break;
}
return retObj;
#if !DEBUG
}
catch (Exception ex)
{
@@ -721,12 +744,15 @@ namespace CleanMachineHMI
LogHelper.WriteLog($"读取【{itemType.ToString()}】类型PLC变量【{plcItemCode}】时发生异常:【{ex.Message}】", LogTypeEum.Err);
return null;
}
#endif
}
public bool WritePlcItem(string plcItemCode, string writeValue, PlcItemTypeDesc itemType)
{
#if !DEBUG
try
{
#endif
switch (itemType)
{
case PlcItemTypeDesc.M:
@@ -758,12 +784,14 @@ namespace CleanMachineHMI
default:
return false;
}
#if !DEBUG
}
catch (Exception ex)
{
LogHelper.WriteLog($"写入【{itemType.ToString()}】类型PLC变量【{plcItemCode}】的值【{writeValue}】时发生异常:【{ex.Message}】", LogTypeEum.Err);
LogHelper.WriteLog($"写入【{itemType}】类型PLC变量【{plcItemCode}】的值【{writeValue}】时发生异常:【{ex.Message}】", LogTypeEum.Err);
return false;
}
#endif
}
private int wcsToPlcHeartDataNew = 0;
private DateTime HeartbeatTime = new DateTime();
@@ -774,8 +802,10 @@ namespace CleanMachineHMI
/// </summary>
public void HeartbeatDetection()
{
#if !DEBUG
try
{
#endif
int wcsToPlcHeartData = Convert.ToInt32(ReadPlcItem("PlcHeartbeatWriteData", PlcItemTypeDesc.D) == null ? 0 : ReadPlcItem("PlcHeartbeatWriteData", PlcItemTypeDesc.D));
int plcToWcsHeartData = Convert.ToInt32(ReadPlcItem("PlcHeartbeatReadData", PlcItemTypeDesc.D) == null ? 0 : ReadPlcItem("PlcHeartbeatReadData", PlcItemTypeDesc.D));
if (wcsToPlcHeartData == 0 && plcToWcsHeartData == 0)
@@ -829,8 +859,6 @@ namespace CleanMachineHMI
WritePlcItem("PlcHeartbeatWriteData", wcsToPlcHeartDataNew.ToString(), PlcItemTypeDesc.D);
}
#if USE_LOCAL_TCP_DEBUG
#else
@@ -848,11 +876,14 @@ namespace CleanMachineHMI
ReConnNum++;
}
#endif
#if !DEBUG
}
catch
catch (Exception ex)
{
}
#endif
}
}

View File

@@ -484,8 +484,10 @@ namespace CleanMachineHMI
long lastTick = DateTime.Now.Ticks;
while (GlobalHelper.SysThIsRunFlag)
{
#if !DEBUG
try
{
#endif
#region 定时器运行函数
//当前托报废率超过10%,则提示
string sql_CurrPalletmsg = $@"SELECT * FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0";
@@ -642,11 +644,14 @@ namespace CleanMachineHMI
PlcOperationHelper.Instance.HeartbeatDetection();
#endregion
#if !DEBUG
}
catch (Exception ex)
{
LogHelper.WriteLog($"定时器运行函数发生异常:【{ex.Message}】", LogTypeEum.Err);
}
#endif
Thread.Sleep(1000);
}
}

View File

@@ -28,9 +28,10 @@ namespace LeadDataBaseUtility
public static int ExecuteSql(string sql)
{
int affectedRows = 0;
#if !DEBUG
try
{
#endif
using (SQLiteConnection conn = new SQLiteConnection(connectionString))
{
conn.Open();
@@ -41,12 +42,14 @@ namespace LeadDataBaseUtility
}
conn.Close();
}
#if !DEBUG
}
catch (Exception e)
{
LogHelper.WriteLog($"数据库运行异常:【{e.Message}】。SQL语句:【{sql}】。", LogTypeEum.DbErr);
}
#endif
return affectedRows;
}
/// <summary>
@@ -59,17 +62,21 @@ namespace LeadDataBaseUtility
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
{
DataSet ds = new DataSet();
#if !DEBUG
try
{
#endif
connection.Open();
SQLiteDataAdapter command = new SQLiteDataAdapter(SQLString, connection);
command.Fill(ds, "ds");
connection.Close();
#if !DEBUG
}
catch (Exception e)
{
LogHelper.WriteLog($"数据库运行异常:【{e.Message}】。SQL语句:【{SQLString}】。", LogTypeEum.DbErr);
}
#endif
return ds;
}
}
@@ -84,8 +91,10 @@ namespace LeadDataBaseUtility
{
using (SQLiteCommand cmd = new SQLiteCommand(SQLString, connection))
{
#if !DEBUG
try
{
#endif
connection.Open();
object obj = cmd.ExecuteScalar();
if ((Equals(obj, null)) || (Equals(obj, System.DBNull.Value)))
@@ -98,6 +107,7 @@ namespace LeadDataBaseUtility
connection.Close();
return obj;
}
#if !DEBUG
}
catch (System.Data.SQLite.SQLiteException e)
{
@@ -105,6 +115,7 @@ namespace LeadDataBaseUtility
LogHelper.WriteLog($"数据库运行异常:【{e.Message}】。SQL语句:【{SQLString}】。", LogTypeEum.DbErr);
return null;
}
#endif
}
}
}

View File

@@ -36,6 +36,14 @@ namespace NX_LogUtility
}
public static class LogHelper
{
private readonly static System.Collections.Concurrent.BlockingCollection<string> messages = new System.Collections.Concurrent.BlockingCollection<string>();
#region 记录日志为文本文档形式
/// <summary>
/// 记录日志类
@@ -75,9 +83,10 @@ namespace NX_LogUtility
Task.Run(() =>
{
#if !DEBUG
try
{
#endif
lock (lockobj)
{
if (!Directory.Exists(strDir))//如果日志文件存放的文件夹不存在,就新建一个文件夹。
@@ -104,18 +113,24 @@ namespace NX_LogUtility
sw.Close();
fs.Close();
}
#if !DEBUG
}
catch (Exception)
{
;
}
finally
{
#endif
if (sw != null)
sw.Close();
if (fs != null)
fs.Close();
#if !DEBUG
}
#endif
});