修改读取逻辑
This commit is contained in:
@@ -32,6 +32,8 @@
|
|||||||
<add key="ParityMsg" value="2"/>
|
<add key="ParityMsg" value="2"/>
|
||||||
|
|
||||||
<add key="ModbusPattern" value="0" />
|
<add key="ModbusPattern" value="0" />
|
||||||
|
|
||||||
|
<add key="SlaveAddress" value="1" />
|
||||||
<!--托盘序列号前缀-->
|
<!--托盘序列号前缀-->
|
||||||
<add key="PalletIndexPrefix" value="Pallet"/>
|
<add key="PalletIndexPrefix" value="Pallet"/>
|
||||||
<!--托盘序列号生成日期-->
|
<!--托盘序列号生成日期-->
|
||||||
|
|||||||
@@ -78,9 +78,9 @@ namespace CleanMachineHMI.FrmUserControl
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Global.PlcItemMd_X_List != null && Global.PlcItemMd_X_List.Count > 0)
|
if (PlcOperationHelper.Instance.PlcItemMd_X_List != null && PlcOperationHelper.Instance.PlcItemMd_X_List.Count > 0)
|
||||||
{
|
{
|
||||||
List<PlcItem> tempLst = Global.PlcItemMd_X_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
List<PlcItem> tempLst = PlcOperationHelper.Instance.PlcItemMd_X_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
||||||
foreach (PlcItem item in tempLst)
|
foreach (PlcItem item in tempLst)
|
||||||
{
|
{
|
||||||
BeginInvoke(new Action(() =>
|
BeginInvoke(new Action(() =>
|
||||||
@@ -95,9 +95,9 @@ namespace CleanMachineHMI.FrmUserControl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Global.PlcItemMd_Y_List != null && Global.PlcItemMd_Y_List.Count > 0)
|
if (PlcOperationHelper.Instance.PlcItemMd_Y_List != null && PlcOperationHelper.Instance.PlcItemMd_Y_List.Count > 0)
|
||||||
{
|
{
|
||||||
List<PlcItem> tempLst = Global.PlcItemMd_Y_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
List<PlcItem> tempLst = PlcOperationHelper.Instance.PlcItemMd_Y_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
||||||
foreach (PlcItem item in tempLst)
|
foreach (PlcItem item in tempLst)
|
||||||
{
|
{
|
||||||
BeginInvoke(new Action(() =>
|
BeginInvoke(new Action(() =>
|
||||||
|
|||||||
@@ -149,11 +149,11 @@ namespace CleanMachineHMI.FrmUserControl
|
|||||||
List<PlcItem> tmpMdList;
|
List<PlcItem> tmpMdList;
|
||||||
if (!string.IsNullOrEmpty(ktb_plcMsg.Text.Trim()))
|
if (!string.IsNullOrEmpty(ktb_plcMsg.Text.Trim()))
|
||||||
{
|
{
|
||||||
tmpMdList = Global.PlcItemMdList.FindAll(x => x.PlcItemCode.Contains(ktb_plcMsg.Text.Trim()) || x.PlcItemName.Contains(ktb_plcMsg.Text.Trim()));
|
tmpMdList = PlcOperationHelper.Instance. PlcItemMdList.FindAll(x => x.PlcItemCode.Contains(ktb_plcMsg.Text.Trim()) || x.PlcItemName.Contains(ktb_plcMsg.Text.Trim()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tmpMdList = Global.PlcItemMdList;
|
tmpMdList = PlcOperationHelper.Instance.PlcItemMdList;
|
||||||
}
|
}
|
||||||
if (tmpMdList != null && tmpMdList.Count > 0)
|
if (tmpMdList != null && tmpMdList.Count > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -117,14 +117,14 @@ namespace CleanMachineHMI
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static List<PlcItem> PlcItemMdList { get; set; } = new List<PlcItem>();
|
//public static List<PlcItem> PlcItemMdList { get; set; } = new List<PlcItem>();
|
||||||
public static List<PlcItem> PlcItemMd_D_List { get; set; } = new List<PlcItem>();
|
//public static List<PlcItem> PlcItemMd_D_List { get; set; } = new List<PlcItem>();
|
||||||
|
|
||||||
public static List<PlcItem> PlcItemMd_M_List { get; set; }=new List<PlcItem>();
|
//public static List<PlcItem> PlcItemMd_M_List { get; set; }=new List<PlcItem>();
|
||||||
|
|
||||||
public static List<PlcItem> PlcItemMd_X_List { get; set; }=new List<PlcItem>();
|
//public static List<PlcItem> PlcItemMd_X_List { get; set; }=new List<PlcItem>();
|
||||||
|
|
||||||
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<Warning> BasWarningMd_List { get; set; }
|
public static List<Warning> BasWarningMd_List { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ using System.Diagnostics;
|
|||||||
using System.IO.Ports;
|
using System.IO.Ports;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace CleanMachineHMI
|
namespace CleanMachineHMI
|
||||||
@@ -60,7 +61,7 @@ namespace CleanMachineHMI
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
private byte slaveAddress = 1;
|
private byte slaveAddress = byte.Parse(ConfigurationManager.AppSettings["SlaveAddress"]);
|
||||||
|
|
||||||
|
|
||||||
private bool _isConn = false;
|
private bool _isConn = false;
|
||||||
@@ -85,13 +86,77 @@ namespace CleanMachineHMI
|
|||||||
#else
|
#else
|
||||||
private static SerialPort port;
|
private static SerialPort port;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public List<PlcItem> PlcItemMdList { get; set; } = new List<PlcItem>();
|
||||||
|
public List<PlcItem> PlcItemMd_D_List { get; set; } = new List<PlcItem>();
|
||||||
|
|
||||||
|
public List<PlcItem> PlcItemMd_M_List { get; set; } = new List<PlcItem>();
|
||||||
|
|
||||||
|
public List<PlcItem> PlcItemMd_X_List { get; set; } = new List<PlcItem>();
|
||||||
|
|
||||||
|
public List<PlcItem> PlcItemMd_Y_List { get; set; } = new List<PlcItem>();
|
||||||
|
|
||||||
|
|
||||||
|
public void StartRead()
|
||||||
|
{
|
||||||
|
Thread th = new Thread(RefreshPlcItem)
|
||||||
|
{
|
||||||
|
IsBackground = true
|
||||||
|
};
|
||||||
|
th.Start();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshPlcItem()
|
||||||
|
{
|
||||||
|
while (Global.SysThIsRunFlag)
|
||||||
|
{
|
||||||
|
RefreshPlcItem_M();
|
||||||
|
Instance.RefreshPlcItem_D();
|
||||||
|
Instance.RefreshPlcItem_X();
|
||||||
|
Instance.RefreshPlcItem_Y();
|
||||||
|
// ShowWarningMsg();
|
||||||
|
Thread.Sleep(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化PLC
|
/// 初始化PLC
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool PlcInit()
|
public bool PlcInit(IEnumerable<PlcItem> items)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
foreach (var plcitem in items)
|
||||||
|
{
|
||||||
|
switch (plcitem.PlcItemDataType)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
PlcItemMd_M_List.Add(plcitem);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
PlcItemMd_D_List.Add(plcitem);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
PlcItemMd_X_List.Add(plcitem);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
PlcItemMd_Y_List.Add(plcitem);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
PlcItemMdList.Add(plcitem);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -103,6 +168,7 @@ namespace CleanMachineHMI
|
|||||||
Parity paritymsg = (Parity)int.Parse(ConfigurationManager.AppSettings["ParityMsg"]);
|
Parity paritymsg = (Parity)int.Parse(ConfigurationManager.AppSettings["ParityMsg"]);
|
||||||
int modbusPattern = int.Parse(ConfigurationManager.AppSettings["ModbusPattern"]);
|
int modbusPattern = int.Parse(ConfigurationManager.AppSettings["ModbusPattern"]);
|
||||||
|
|
||||||
|
|
||||||
//string portname = GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'PortName'")[0]["PARAMETER_VALUE"].ToString();
|
//string portname = GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'PortName'")[0]["PARAMETER_VALUE"].ToString();
|
||||||
//int baudrate = Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'BaudRate'")[0]["PARAMETER_VALUE"]);
|
//int baudrate = Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'BaudRate'")[0]["PARAMETER_VALUE"]);
|
||||||
//int databits = Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'DataBits'")[0]["PARAMETER_VALUE"]);
|
//int databits = Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'DataBits'")[0]["PARAMETER_VALUE"]);
|
||||||
@@ -176,9 +242,9 @@ namespace CleanMachineHMI
|
|||||||
bool[] readBytArr_M1 = master.ReadCoils(slaveAddress, 2048, 50);
|
bool[] readBytArr_M1 = master.ReadCoils(slaveAddress, 2048, 50);
|
||||||
if (readBytArr_M.Length > 0 && readBytArr_M1.Length > 0)
|
if (readBytArr_M.Length > 0 && readBytArr_M1.Length > 0)
|
||||||
{
|
{
|
||||||
if (Global.PlcItemMd_M_List != null && Global.PlcItemMd_M_List.Count > 0)
|
if (PlcItemMd_M_List != null && PlcItemMd_M_List.Count > 0)
|
||||||
{
|
{
|
||||||
foreach (PlcItem item in Global.PlcItemMd_M_List)
|
foreach (PlcItem item in PlcItemMd_M_List)
|
||||||
{
|
{
|
||||||
if (Convert.ToInt32(item.PlcItemPriAddress) >= 200)
|
if (Convert.ToInt32(item.PlcItemPriAddress) >= 200)
|
||||||
{
|
{
|
||||||
@@ -223,9 +289,9 @@ namespace CleanMachineHMI
|
|||||||
ushort[] readBytArr_D = master.ReadHoldingRegisters(slaveAddress, 4505, 50);
|
ushort[] readBytArr_D = master.ReadHoldingRegisters(slaveAddress, 4505, 50);
|
||||||
if (readBytArr_D.Length > 0 && tmpReadAlarmBytArr_D.Length > 0)
|
if (readBytArr_D.Length > 0 && tmpReadAlarmBytArr_D.Length > 0)
|
||||||
{
|
{
|
||||||
if (Global.PlcItemMd_D_List != null && Global.PlcItemMd_D_List.Count > 0)
|
if (PlcItemMd_D_List != null && PlcItemMd_D_List.Count > 0)
|
||||||
{
|
{
|
||||||
foreach (PlcItem item in Global.PlcItemMd_D_List)
|
foreach (PlcItem item in PlcItemMd_D_List)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress))
|
if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress))
|
||||||
{
|
{
|
||||||
@@ -239,6 +305,7 @@ namespace CleanMachineHMI
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
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] };
|
||||||
@@ -627,9 +694,9 @@ namespace CleanMachineHMI
|
|||||||
if (readBytArr_X.Length > 0)
|
if (readBytArr_X.Length > 0)
|
||||||
//if(true)
|
//if(true)
|
||||||
{
|
{
|
||||||
if (Global.PlcItemMd_X_List != null && Global.PlcItemMd_X_List.Count > 0)
|
if (PlcItemMd_X_List != null && PlcItemMd_X_List.Count > 0)
|
||||||
{
|
{
|
||||||
foreach (PlcItem item in Global.PlcItemMd_X_List)
|
foreach (PlcItem item in PlcItemMd_X_List)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress))
|
if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress))
|
||||||
{
|
{
|
||||||
@@ -666,9 +733,9 @@ namespace CleanMachineHMI
|
|||||||
if (readBytArr_Y.Length > 0)
|
if (readBytArr_Y.Length > 0)
|
||||||
//if(true)
|
//if(true)
|
||||||
{
|
{
|
||||||
if (Global.PlcItemMd_Y_List != null && Global.PlcItemMd_Y_List.Count > 0)
|
if (PlcItemMd_Y_List != null && PlcItemMd_Y_List.Count > 0)
|
||||||
{
|
{
|
||||||
foreach (PlcItem item in Global.PlcItemMd_Y_List)
|
foreach (PlcItem item in PlcItemMd_Y_List)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress))
|
if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress))
|
||||||
{
|
{
|
||||||
@@ -696,9 +763,11 @@ namespace CleanMachineHMI
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public object ReadPlcItem(string plcItemCode)
|
public object ReadPlcItem(string plcItemCode)
|
||||||
{
|
{
|
||||||
PlcItem item = Global.PlcItemMdList.Find(x => x.PlcItemCode == plcItemCode);
|
PlcItem item = PlcItemMdList.Find(x => x.PlcItemCode == plcItemCode);
|
||||||
if (item == null)
|
if (item == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -744,7 +813,7 @@ namespace CleanMachineHMI
|
|||||||
{
|
{
|
||||||
case PlcItemTypeDesc.M:
|
case PlcItemTypeDesc.M:
|
||||||
|
|
||||||
PlcItem item_M = Global.PlcItemMd_M_List.Find(x => x.PlcItemCode == plcItemCode);
|
PlcItem item_M = PlcItemMd_M_List.Find(x => x.PlcItemCode == plcItemCode);
|
||||||
if (item_M == null)
|
if (item_M == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -759,7 +828,7 @@ namespace CleanMachineHMI
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PlcItemTypeDesc.D:
|
case PlcItemTypeDesc.D:
|
||||||
PlcItem item_D = Global.PlcItemMd_D_List.Find(x => x.PlcItemCode == plcItemCode);
|
PlcItem item_D = PlcItemMd_D_List.Find(x => x.PlcItemCode == plcItemCode);
|
||||||
if (item_D == null)
|
if (item_D == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -774,7 +843,7 @@ namespace CleanMachineHMI
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PlcItemTypeDesc.X:
|
case PlcItemTypeDesc.X:
|
||||||
PlcItem item_X = Global.PlcItemMd_X_List.Find(x => x.PlcItemCode == plcItemCode);
|
PlcItem item_X = PlcItemMd_X_List.Find(x => x.PlcItemCode == plcItemCode);
|
||||||
if (item_X == null)
|
if (item_X == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -789,7 +858,7 @@ namespace CleanMachineHMI
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PlcItemTypeDesc.Y:
|
case PlcItemTypeDesc.Y:
|
||||||
PlcItem item_Y = Global.PlcItemMd_Y_List.Find(x => x.PlcItemCode == plcItemCode);
|
PlcItem item_Y = PlcItemMd_Y_List.Find(x => x.PlcItemCode == plcItemCode);
|
||||||
if (item_Y == null)
|
if (item_Y == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -828,7 +897,7 @@ namespace CleanMachineHMI
|
|||||||
switch (itemType)
|
switch (itemType)
|
||||||
{
|
{
|
||||||
case PlcItemTypeDesc.M:
|
case PlcItemTypeDesc.M:
|
||||||
PlcItem item_M = Global.PlcItemMd_M_List.Find(x => x.PlcItemCode == plcItemCode);
|
PlcItem item_M = PlcItemMd_M_List.Find(x => x.PlcItemCode == plcItemCode);
|
||||||
if (item_M == null)
|
if (item_M == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -836,7 +905,7 @@ namespace CleanMachineHMI
|
|||||||
master.WriteSingleCoil(slaveAddress, Convert.ToUInt16(item_M.PlcItemModbusAddress), bool.Parse(writeValue));
|
master.WriteSingleCoil(slaveAddress, Convert.ToUInt16(item_M.PlcItemModbusAddress), bool.Parse(writeValue));
|
||||||
return true;
|
return true;
|
||||||
case PlcItemTypeDesc.Y:
|
case PlcItemTypeDesc.Y:
|
||||||
PlcItem item_Y = Global.PlcItemMd_Y_List.Find(x => x.PlcItemCode == plcItemCode);
|
PlcItem item_Y = PlcItemMd_Y_List.Find(x => x.PlcItemCode == plcItemCode);
|
||||||
if (item_Y == null)
|
if (item_Y == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -844,7 +913,7 @@ namespace CleanMachineHMI
|
|||||||
master.WriteSingleCoil(slaveAddress, Convert.ToUInt16(item_Y.PlcItemModbusAddress), bool.Parse(writeValue));
|
master.WriteSingleCoil(slaveAddress, Convert.ToUInt16(item_Y.PlcItemModbusAddress), bool.Parse(writeValue));
|
||||||
return true;
|
return true;
|
||||||
case PlcItemTypeDesc.D:
|
case PlcItemTypeDesc.D:
|
||||||
PlcItem item_D = Global.PlcItemMd_D_List.Find(x => x.PlcItemCode == plcItemCode);
|
PlcItem item_D = PlcItemMd_D_List.Find(x => x.PlcItemCode == plcItemCode);
|
||||||
if (item_D == null)
|
if (item_D == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -146,10 +146,10 @@ namespace CleanMachineHMI
|
|||||||
lstMoitor_Y.Clear();
|
lstMoitor_Y.Clear();
|
||||||
|
|
||||||
#region PLC X数据类型变量
|
#region PLC X数据类型变量
|
||||||
if (Global.PlcItemMd_X_List != null && Global.PlcItemMd_X_List.Count > 0)
|
if (PlcOperationHelper.Instance.PlcItemMd_X_List != null && PlcOperationHelper.Instance.PlcItemMd_X_List.Count > 0)
|
||||||
{
|
{
|
||||||
//List<BasPlcItemMd> tempLst = AppConfig.PlcItemMd_X_List.FindAll(x => x.PlcItemName != "备用").OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
//List<BasPlcItemMd> tempLst = AppConfig.PlcItemMd_X_List.FindAll(x => x.PlcItemName != "备用").OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
||||||
List<PlcItem> tempLst = Global.PlcItemMd_X_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
List<PlcItem> tempLst = PlcOperationHelper.Instance.PlcItemMd_X_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
||||||
int dataSum = tempLst.Count;
|
int dataSum = tempLst.Count;
|
||||||
int rowNum;
|
int rowNum;
|
||||||
if (dataSum % 2 == 0)
|
if (dataSum % 2 == 0)
|
||||||
@@ -262,10 +262,10 @@ namespace CleanMachineHMI
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region PLC Y数据类型变量
|
#region PLC Y数据类型变量
|
||||||
if (Global.PlcItemMd_Y_List != null && Global.PlcItemMd_Y_List.Count > 0)
|
if (PlcOperationHelper.Instance.PlcItemMd_Y_List != null && PlcOperationHelper.Instance.PlcItemMd_Y_List.Count > 0)
|
||||||
{
|
{
|
||||||
//List<BasPlcItemMd> tempLst = AppConfig.PlcItemMd_Y_List.FindAll(x => x.PlcItemName != "备用").OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
//List<BasPlcItemMd> tempLst = AppConfig.PlcItemMd_Y_List.FindAll(x => x.PlcItemName != "备用").OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
||||||
List<PlcItem> tempLst = Global.PlcItemMd_Y_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
List<PlcItem> tempLst = PlcOperationHelper.Instance.PlcItemMd_Y_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
||||||
int dataSum = tempLst.Count;
|
int dataSum = tempLst.Count;
|
||||||
//int dataSum = AppConfig.PlcItemMd_Y_List.Count;
|
//int dataSum = AppConfig.PlcItemMd_Y_List.Count;
|
||||||
int rowNum;
|
int rowNum;
|
||||||
|
|||||||
@@ -166,9 +166,9 @@ namespace CleanMachineHMI
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Global.PlcItemMd_X_List != null && Global.PlcItemMd_X_List.Count > 0)
|
if (PlcOperationHelper.Instance.PlcItemMd_X_List != null && PlcOperationHelper.Instance.PlcItemMd_X_List.Count > 0)
|
||||||
{
|
{
|
||||||
List<PlcItem> tempLst = Global.PlcItemMd_X_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
List<PlcItem> tempLst = PlcOperationHelper.Instance.PlcItemMd_X_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
||||||
foreach (PlcItem item in tempLst)
|
foreach (PlcItem item in tempLst)
|
||||||
{
|
{
|
||||||
Invoke(new Action(() =>
|
Invoke(new Action(() =>
|
||||||
@@ -183,9 +183,9 @@ namespace CleanMachineHMI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Global.PlcItemMd_Y_List != null && Global.PlcItemMd_Y_List.Count > 0)
|
if (PlcOperationHelper.Instance.PlcItemMd_Y_List != null && PlcOperationHelper.Instance.PlcItemMd_Y_List.Count > 0)
|
||||||
{
|
{
|
||||||
List<PlcItem> tempLst = Global.PlcItemMd_Y_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
List<PlcItem> tempLst = PlcOperationHelper.Instance.PlcItemMd_Y_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
||||||
foreach (PlcItem item in tempLst)
|
foreach (PlcItem item in tempLst)
|
||||||
{
|
{
|
||||||
Invoke(new Action(() =>
|
Invoke(new Action(() =>
|
||||||
@@ -220,7 +220,7 @@ namespace CleanMachineHMI
|
|||||||
string plcItemNameAddress = pic.Name.Replace("picb_", "");
|
string plcItemNameAddress = pic.Name.Replace("picb_", "");
|
||||||
if (plcItemNameAddress.StartsWith("M"))
|
if (plcItemNameAddress.StartsWith("M"))
|
||||||
{
|
{
|
||||||
PlcItem tmpPlc = Global.PlcItemMd_M_List.First(x => x.PlcItemPriAddress == plcItemNameAddress.Replace("M", ""));
|
PlcItem tmpPlc = PlcOperationHelper.Instance.PlcItemMd_M_List.First(x => x.PlcItemPriAddress == plcItemNameAddress.Replace("M", ""));
|
||||||
if (tmpPlc != null)
|
if (tmpPlc != null)
|
||||||
{
|
{
|
||||||
ttp.SetToolTip(pic, tmpPlc.PlcItemName);
|
ttp.SetToolTip(pic, tmpPlc.PlcItemName);
|
||||||
@@ -228,7 +228,7 @@ namespace CleanMachineHMI
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PlcItem tmpPlc = Global.PlcItemMd_X_List.First(x => x.PlcItemPriAddress == Convert.ToInt32(plcItemNameAddress.Replace("X", ""), 10).ToString());
|
PlcItem tmpPlc = PlcOperationHelper.Instance.PlcItemMd_X_List.First(x => x.PlcItemPriAddress == Convert.ToInt32(plcItemNameAddress.Replace("X", ""), 10).ToString());
|
||||||
if (tmpPlc != null)
|
if (tmpPlc != null)
|
||||||
{
|
{
|
||||||
ttp.SetToolTip(pic, tmpPlc.PlcItemName);
|
ttp.SetToolTip(pic, tmpPlc.PlcItemName);
|
||||||
|
|||||||
@@ -152,26 +152,26 @@ namespace CleanMachineHMI
|
|||||||
SwitchFrmMenu = new dlgSwitchFrmMenu(AddFrmMenuPage);
|
SwitchFrmMenu = new dlgSwitchFrmMenu(AddFrmMenuPage);
|
||||||
|
|
||||||
var plcitems = new CleanMachine.BLL.BAS.PlcItemBLL().GetList("");
|
var plcitems = new CleanMachine.BLL.BAS.PlcItemBLL().GetList("");
|
||||||
foreach (var plcitem in plcitems)
|
//foreach (var plcitem in plcitems)
|
||||||
{
|
//{
|
||||||
switch (plcitem.PlcItemDataType)
|
// switch (plcitem.PlcItemDataType)
|
||||||
{
|
// {
|
||||||
case 0:
|
// case 0:
|
||||||
Global.PlcItemMd_M_List.Add(plcitem);
|
// Global.PlcItemMd_M_List.Add(plcitem);
|
||||||
break;
|
// break;
|
||||||
|
|
||||||
case 1:
|
// case 1:
|
||||||
Global.PlcItemMd_D_List.Add(plcitem);
|
// Global.PlcItemMd_D_List.Add(plcitem);
|
||||||
break;
|
// break;
|
||||||
case 2:
|
// case 2:
|
||||||
Global.PlcItemMd_X_List.Add(plcitem);
|
// Global.PlcItemMd_X_List.Add(plcitem);
|
||||||
break;
|
// break;
|
||||||
case 3:
|
// case 3:
|
||||||
Global.PlcItemMd_Y_List.Add(plcitem);
|
// Global.PlcItemMd_Y_List.Add(plcitem);
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
Global.PlcItemMdList.Add(plcitem);
|
// Global.PlcItemMdList.Add(plcitem);
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -211,7 +211,10 @@ namespace CleanMachineHMI
|
|||||||
//GlobalHelper.PlcItemMdList.AddRange(GlobalHelper.PlcItemMd_Y_List);
|
//GlobalHelper.PlcItemMdList.AddRange(GlobalHelper.PlcItemMd_Y_List);
|
||||||
//}
|
//}
|
||||||
InitWarningMsg();
|
InitWarningMsg();
|
||||||
bool isInitStatus = PlcOperationHelper.Instance.PlcInit();
|
bool isInitStatus = PlcOperationHelper.Instance.PlcInit(plcitems);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (isInitStatus)
|
if (isInitStatus)
|
||||||
{
|
{
|
||||||
label3Professional.Text = this.T("串口打开成功,PLC连接成功!", "label3Professional_Success");
|
label3Professional.Text = this.T("串口打开成功,PLC连接成功!", "label3Professional_Success");
|
||||||
@@ -219,11 +222,14 @@ namespace CleanMachineHMI
|
|||||||
isPlcConnStatus = true;
|
isPlcConnStatus = true;
|
||||||
|
|
||||||
Global.SysThIsRunFlag = true;
|
Global.SysThIsRunFlag = true;
|
||||||
Thread th = new Thread(RefreshPlcItem)
|
PlcOperationHelper.Instance.StartRead();
|
||||||
{
|
|
||||||
IsBackground = true
|
|
||||||
};
|
//Thread th = new Thread(RefreshPlcItem)
|
||||||
th.Start();
|
//{
|
||||||
|
// IsBackground = true
|
||||||
|
//};
|
||||||
|
//th.Start();
|
||||||
|
|
||||||
|
|
||||||
//Thread th = new Thread(RefreshPlcItem_M)
|
//Thread th = new Thread(RefreshPlcItem_M)
|
||||||
@@ -250,11 +256,11 @@ namespace CleanMachineHMI
|
|||||||
//};
|
//};
|
||||||
//th3.Start();
|
//th3.Start();
|
||||||
|
|
||||||
//Thread th4 = new Thread(MainThRunFunc)
|
Thread th4 = new Thread(MainThRunFunc)
|
||||||
//{
|
{
|
||||||
// IsBackground = true
|
IsBackground = true
|
||||||
//};
|
};
|
||||||
//th4.Start();
|
th4.Start();
|
||||||
|
|
||||||
LogHelper.WriteLog($"串口打开成功,PLC连接成功!", LogTypeEum.Run);
|
LogHelper.WriteLog($"串口打开成功,PLC连接成功!", LogTypeEum.Run);
|
||||||
}
|
}
|
||||||
@@ -292,7 +298,7 @@ namespace CleanMachineHMI
|
|||||||
|
|
||||||
private void ShowWarningMsg()
|
private void ShowWarningMsg()
|
||||||
{
|
{
|
||||||
PlcItem item = Global.PlcItemMd_D_List.FirstOrDefault(x => x.PlcItemCode == "AlarmPopUpMsg");
|
PlcItem item = PlcOperationHelper.Instance.PlcItemMd_D_List.FirstOrDefault(x => x.PlcItemCode == "AlarmPopUpMsg");
|
||||||
char[] tmpCharArr = Convert.ToString(Convert.ToInt32(item.PlcItemValue), 2).PadLeft(16, '0').Reverse().ToArray();
|
char[] tmpCharArr = Convert.ToString(Convert.ToInt32(item.PlcItemValue), 2).PadLeft(16, '0').Reverse().ToArray();
|
||||||
if (tmpCharArr.Contains('1'))
|
if (tmpCharArr.Contains('1'))
|
||||||
{
|
{
|
||||||
@@ -397,56 +403,56 @@ namespace CleanMachineHMI
|
|||||||
LeadDbHelperSQLite.ExecuteSql(sql2);
|
LeadDbHelperSQLite.ExecuteSql(sql2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void SetPlcItem(List<PlcItem> PlcItemMdList, DataRow item)
|
//private void SetPlcItem(List<PlcItem> PlcItemMdList, DataRow item)
|
||||||
{
|
//{
|
||||||
if (PlcItemMdList != null)
|
// if (PlcItemMdList != null)
|
||||||
{
|
// {
|
||||||
PlcItem md = PlcItemMdList.Find(x => x.PlcItemCode == item["PLC_ITEM_CODE"].ToString());
|
// PlcItem md = PlcItemMdList.Find(x => x.PlcItemCode == item["PLC_ITEM_CODE"].ToString());
|
||||||
if (md != null)
|
// if (md != null)
|
||||||
{
|
// {
|
||||||
md.PlcItemId = int.Parse(item["PLC_ITEM_ID"].ToString());
|
// md.PlcItemId = int.Parse(item["PLC_ITEM_ID"].ToString());
|
||||||
md.PlcItemCode = item["PLC_ITEM_CODE"].ToString();
|
// md.PlcItemCode = item["PLC_ITEM_CODE"].ToString();
|
||||||
md.PlcItemName = item["PLC_ITEM_NAME"].ToString();
|
// md.PlcItemName = item["PLC_ITEM_NAME"].ToString();
|
||||||
md.PlcItemType = Convert.ToInt32(item["PLC_ITEM_TYPE"].ToString());
|
// md.PlcItemType = Convert.ToInt32(item["PLC_ITEM_TYPE"].ToString());
|
||||||
md.PlcItemDataType = Convert.ToInt32(item["PLC_ITEM_DATA_TYPE"].ToString());
|
// md.PlcItemDataType = Convert.ToInt32(item["PLC_ITEM_DATA_TYPE"].ToString());
|
||||||
md.PlcItemPriAddress = item["PLC_ITEM_PRI_ADDRESS"].ToString();
|
// md.PlcItemPriAddress = item["PLC_ITEM_PRI_ADDRESS"].ToString();
|
||||||
md.PlcItemModbusAddress = item["PLC_ITEM_MODBUS_ADDRESS"].ToString();
|
// md.PlcItemModbusAddress = item["PLC_ITEM_MODBUS_ADDRESS"].ToString();
|
||||||
md.PlcItemDeviationAddress = item["PLC_ITEM_DEVIATION_ADDRESS"] == null ? "" : item["PLC_ITEM_DEVIATION_ADDRESS"].ToString();
|
// md.PlcItemDeviationAddress = item["PLC_ITEM_DEVIATION_ADDRESS"] == null ? "" : item["PLC_ITEM_DEVIATION_ADDRESS"].ToString();
|
||||||
md.PlcItemDataLength = Convert.ToInt32(item["PLC_ITEM_DATA_LENGTH"]);
|
// md.PlcItemDataLength = Convert.ToInt32(item["PLC_ITEM_DATA_LENGTH"]);
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
PlcItemMdList.Add(new PlcItem
|
// PlcItemMdList.Add(new PlcItem
|
||||||
{
|
// {
|
||||||
PlcItemId = int.Parse(item["PLC_ITEM_ID"].ToString()),
|
// PlcItemId = int.Parse(item["PLC_ITEM_ID"].ToString()),
|
||||||
PlcItemCode = item["PLC_ITEM_CODE"].ToString(),
|
// PlcItemCode = item["PLC_ITEM_CODE"].ToString(),
|
||||||
PlcItemName = item["PLC_ITEM_NAME"].ToString(),
|
// PlcItemName = item["PLC_ITEM_NAME"].ToString(),
|
||||||
PlcItemType = Convert.ToInt32(item["PLC_ITEM_TYPE"].ToString()),
|
// PlcItemType = Convert.ToInt32(item["PLC_ITEM_TYPE"].ToString()),
|
||||||
PlcItemDataType = Convert.ToInt32(item["PLC_ITEM_DATA_TYPE"].ToString()),
|
// PlcItemDataType = Convert.ToInt32(item["PLC_ITEM_DATA_TYPE"].ToString()),
|
||||||
PlcItemPriAddress = item["PLC_ITEM_PRI_ADDRESS"].ToString(),
|
// PlcItemPriAddress = item["PLC_ITEM_PRI_ADDRESS"].ToString(),
|
||||||
PlcItemModbusAddress = item["PLC_ITEM_MODBUS_ADDRESS"].ToString(),
|
// PlcItemModbusAddress = item["PLC_ITEM_MODBUS_ADDRESS"].ToString(),
|
||||||
PlcItemDeviationAddress = item["PLC_ITEM_DEVIATION_ADDRESS"] == null ? "" : item["PLC_ITEM_DEVIATION_ADDRESS"].ToString(),
|
// PlcItemDeviationAddress = item["PLC_ITEM_DEVIATION_ADDRESS"] == null ? "" : item["PLC_ITEM_DEVIATION_ADDRESS"].ToString(),
|
||||||
PlcItemDataLength = Convert.ToInt32(item["PLC_ITEM_DATA_LENGTH"]),
|
// PlcItemDataLength = Convert.ToInt32(item["PLC_ITEM_DATA_LENGTH"]),
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
PlcItemMdList = new List<PlcItem>();
|
// PlcItemMdList = new List<PlcItem>();
|
||||||
PlcItemMdList.Add(new PlcItem
|
// PlcItemMdList.Add(new PlcItem
|
||||||
{
|
// {
|
||||||
PlcItemId = int.Parse(item["PLC_ITEM_ID"].ToString()),
|
// PlcItemId = int.Parse(item["PLC_ITEM_ID"].ToString()),
|
||||||
PlcItemCode = item["PLC_ITEM_CODE"].ToString(),
|
// PlcItemCode = item["PLC_ITEM_CODE"].ToString(),
|
||||||
PlcItemName = item["PLC_ITEM_NAME"].ToString(),
|
// PlcItemName = item["PLC_ITEM_NAME"].ToString(),
|
||||||
PlcItemType = Convert.ToInt32(item["PLC_ITEM_TYPE"].ToString()),
|
// PlcItemType = Convert.ToInt32(item["PLC_ITEM_TYPE"].ToString()),
|
||||||
PlcItemDataType = Convert.ToInt32(item["PLC_ITEM_DATA_TYPE"].ToString()),
|
// PlcItemDataType = Convert.ToInt32(item["PLC_ITEM_DATA_TYPE"].ToString()),
|
||||||
PlcItemPriAddress = item["PLC_ITEM_PRI_ADDRESS"].ToString(),
|
// PlcItemPriAddress = item["PLC_ITEM_PRI_ADDRESS"].ToString(),
|
||||||
PlcItemModbusAddress = item["PLC_ITEM_MODBUS_ADDRESS"].ToString(),
|
// PlcItemModbusAddress = item["PLC_ITEM_MODBUS_ADDRESS"].ToString(),
|
||||||
PlcItemDeviationAddress = item["PLC_ITEM_DEVIATION_ADDRESS"] == null ? "" : item["PLC_ITEM_DEVIATION_ADDRESS"].ToString(),
|
// PlcItemDeviationAddress = item["PLC_ITEM_DEVIATION_ADDRESS"] == null ? "" : item["PLC_ITEM_DEVIATION_ADDRESS"].ToString(),
|
||||||
PlcItemDataLength = Convert.ToInt32(item["PLC_ITEM_DATA_LENGTH"]),
|
// PlcItemDataLength = Convert.ToInt32(item["PLC_ITEM_DATA_LENGTH"]),
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
private void timer_Tick(object sender, EventArgs e)
|
private void timer_Tick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -675,6 +681,7 @@ namespace CleanMachineHMI
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
PlcOperationHelper.Instance.HeartbeatDetection();
|
PlcOperationHelper.Instance.HeartbeatDetection();
|
||||||
|
ShowWarningMsg();
|
||||||
#endregion
|
#endregion
|
||||||
#if RELEASE
|
#if RELEASE
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user