|
|
@ -182,61 +182,73 @@ namespace InjectionPC |
|
|
|
|
|
|
|
#region 连接PLC
|
|
|
|
|
|
|
|
if (CreateServer()) |
|
|
|
try |
|
|
|
{ |
|
|
|
if (ConnectServer(strHostIP, "Kepware.KEPServerEX.V6")) |
|
|
|
if (CreateServer()) |
|
|
|
{ |
|
|
|
Connected = true; |
|
|
|
if (ConnectServer(strHostIP, "Kepware.KEPServerEX.V6")) |
|
|
|
{ |
|
|
|
Connected = true; |
|
|
|
|
|
|
|
#region 创建组
|
|
|
|
#region 创建组
|
|
|
|
|
|
|
|
opcGroups = opcServer.OPCGroups; |
|
|
|
opcGroup1 = opcGroups.Add("Mould"); |
|
|
|
SetGroupProperty(opcGroup1, 500); |
|
|
|
opcGroup2 = opcGroups.Add("Break"); |
|
|
|
SetGroupProperty(opcGroup2, 500); |
|
|
|
opcGroups = opcServer.OPCGroups; |
|
|
|
opcGroup1 = opcGroups.Add("Mould"); |
|
|
|
SetGroupProperty(opcGroup1, 500); |
|
|
|
opcGroup2 = opcGroups.Add("Break"); |
|
|
|
SetGroupProperty(opcGroup2, 500); |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 创建项
|
|
|
|
#region 创建项
|
|
|
|
|
|
|
|
opcItems1 = opcGroup1.OPCItems; |
|
|
|
opcItems1.DefaultIsActive = true; |
|
|
|
opcItems1 = opcGroup1.OPCItems; |
|
|
|
opcItems1.DefaultIsActive = true; |
|
|
|
|
|
|
|
PLCMouldBLL PLCbll = new PLCMouldBLL(); |
|
|
|
PLCBreakBLL bbll = new PLCBreakBLL(); |
|
|
|
PLCMouldBLL PLCbll = new PLCMouldBLL(); |
|
|
|
PLCBreakBLL bbll = new PLCBreakBLL(); |
|
|
|
|
|
|
|
DataTable PLCdt = PLCbll.SearchMould(Program.station); |
|
|
|
if (PLCdt != null && PLCdt.Rows.Count > 0) |
|
|
|
{ |
|
|
|
opcItemm1 = new OPCItem[PLCdt.Rows.Count]; |
|
|
|
for (int i = 0; i < PLCdt.Rows.Count; i++) |
|
|
|
DataTable PLCdt = PLCbll.SearchMould(Program.station); |
|
|
|
if (PLCdt != null && PLCdt.Rows.Count > 0) |
|
|
|
{ |
|
|
|
opcItemm1[i] = opcItems1.AddItem(PLCdt.Rows[i]["Address"].ToString(), i); |
|
|
|
opcItemm1 = new OPCItem[PLCdt.Rows.Count]; |
|
|
|
for (int i = 0; i < PLCdt.Rows.Count; i++) |
|
|
|
{ |
|
|
|
opcItemm1[i] = opcItems1.AddItem(PLCdt.Rows[i]["Address"].ToString(), i); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Thread.Sleep(200); |
|
|
|
Thread.Sleep(200); |
|
|
|
|
|
|
|
opcGroup1.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(opcGroup1_DataChange); |
|
|
|
opcGroup1.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(opcGroup1_DataChange); |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
MessageBox.Show("连接到OPC服务器失败!", "提示", MessageBoxButtons.OK); |
|
|
|
Connected = false; |
|
|
|
LogHelper.WriteLog("连接到OPC服务器失败!"); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
MessageBox.Show("连接到OPC服务器失败!", "提示", MessageBoxButtons.OK); |
|
|
|
MessageBox.Show("创建OPC服务失败!", "提示", MessageBoxButtons.OK); |
|
|
|
Connected = false; |
|
|
|
LogHelper.WriteLog("连接到OPC服务器失败!"); |
|
|
|
LogHelper.WriteLog("创建OPC服务失败!"); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
catch(Exception ex) |
|
|
|
{ |
|
|
|
MessageBox.Show("创建OPC服务失败!", "提示", MessageBoxButtons.OK); |
|
|
|
Connected = false; |
|
|
|
LogHelper.WriteLog("创建OPC服务失败!"); |
|
|
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
@ -2437,8 +2449,8 @@ namespace InjectionPC |
|
|
|
} |
|
|
|
|
|
|
|
//if (bll.Add_Info_New(md, Program.tableName) == false)
|
|
|
|
if (SaveBarCode(md, Program.tableName,false, "1") == false) |
|
|
|
{ |
|
|
|
if (SaveBarCode(md, Program.tableName, false, "0") == false) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@ -3454,11 +3466,12 @@ namespace InjectionPC |
|
|
|
if (result == DialogResult.OK) |
|
|
|
{ |
|
|
|
if (UnCompletePrintBox("切换手动打印","all") == false) return; |
|
|
|
|
|
|
|
opcGroup1.DataChange -= new DIOPCGroupEvent_DataChangeEventHandler(opcGroup1_DataChange); |
|
|
|
cboxHandBox.Enabled = true; |
|
|
|
opcServer.OPCGroups.RemoveAll(); |
|
|
|
opcServer.Disconnect(); |
|
|
|
serialPort1.Close(); |
|
|
|
|
|
|
|
label23.Enabled = true; |
|
|
|
label23.BackColor = System.Drawing.Color.DeepSkyBlue; |
|
|
|
//if (ConfigurationManager.AppSettings["StationMode"].ToString() == "1")
|
|
|
@ -3488,61 +3501,72 @@ namespace InjectionPC |
|
|
|
|
|
|
|
cboxHandBox.Enabled = false; |
|
|
|
#region 连接PLC
|
|
|
|
|
|
|
|
if (CreateServer()) |
|
|
|
try |
|
|
|
{ |
|
|
|
if (ConnectServer(strHostIP, "Kepware.KEPServerEX.V6")) |
|
|
|
if (CreateServer()) |
|
|
|
{ |
|
|
|
Connected = true; |
|
|
|
if (ConnectServer(strHostIP, "Kepware.KEPServerEX.V6")) |
|
|
|
{ |
|
|
|
Connected = true; |
|
|
|
|
|
|
|
#region 创建组
|
|
|
|
#region 创建组
|
|
|
|
|
|
|
|
opcGroups = opcServer.OPCGroups; |
|
|
|
opcGroup1 = opcGroups.Add("Mould"); |
|
|
|
SetGroupProperty(opcGroup1, 500); |
|
|
|
opcGroups = opcServer.OPCGroups; |
|
|
|
opcGroup1 = opcGroups.Add("Mould"); |
|
|
|
SetGroupProperty(opcGroup1, 500); |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 创建项
|
|
|
|
#region 创建项
|
|
|
|
|
|
|
|
opcItems1 = opcGroup1.OPCItems; |
|
|
|
opcItems1.DefaultIsActive = true; |
|
|
|
opcItems1 = opcGroup1.OPCItems; |
|
|
|
opcItems1.DefaultIsActive = true; |
|
|
|
|
|
|
|
PLCMouldBLL PLCbll = new PLCMouldBLL(); |
|
|
|
PLCBreakBLL bbll = new PLCBreakBLL(); |
|
|
|
PLCMouldBLL PLCbll = new PLCMouldBLL(); |
|
|
|
PLCBreakBLL bbll = new PLCBreakBLL(); |
|
|
|
|
|
|
|
DataTable PLCdt = PLCbll.SearchMould(Program.station); |
|
|
|
if (PLCdt != null && PLCdt.Rows.Count > 0) |
|
|
|
{ |
|
|
|
opcItemm1 = new OPCItem[PLCdt.Rows.Count]; |
|
|
|
for (int i = 0; i < PLCdt.Rows.Count; i++) |
|
|
|
DataTable PLCdt = PLCbll.SearchMould(Program.station); |
|
|
|
if (PLCdt != null && PLCdt.Rows.Count > 0) |
|
|
|
{ |
|
|
|
opcItemm1[i] = opcItems1.AddItem(PLCdt.Rows[i]["Address"].ToString(), i); |
|
|
|
opcItemm1 = new OPCItem[PLCdt.Rows.Count]; |
|
|
|
for (int i = 0; i < PLCdt.Rows.Count; i++) |
|
|
|
{ |
|
|
|
opcItemm1[i] = opcItems1.AddItem(PLCdt.Rows[i]["Address"].ToString(), i); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Thread.Sleep(200); |
|
|
|
Thread.Sleep(200); |
|
|
|
|
|
|
|
opcGroup1.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(opcGroup1_DataChange); |
|
|
|
opcGroup1.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(opcGroup1_DataChange); |
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
MessageBox.Show("连接到OPC服务器失败!", "提示", MessageBoxButtons.OK); |
|
|
|
Connected = false; |
|
|
|
LogHelper.WriteLog("连接到OPC服务器失败!"); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
MessageBox.Show("连接到OPC服务器失败!", "提示", MessageBoxButtons.OK); |
|
|
|
MessageBox.Show("创建OPC服务失败!", "提示", MessageBoxButtons.OK); |
|
|
|
Connected = false; |
|
|
|
LogHelper.WriteLog("连接到OPC服务器失败!"); |
|
|
|
LogHelper.WriteLog("创建OPC服务失败!"); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
catch(Exception ex) |
|
|
|
{ |
|
|
|
MessageBox.Show("创建OPC服务失败!", "提示", MessageBoxButtons.OK); |
|
|
|
Connected = false; |
|
|
|
LogHelper.WriteLog("创建OPC服务失败!"); |
|
|
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
@ -3568,6 +3592,7 @@ namespace InjectionPC |
|
|
|
label13.BackColor = System.Drawing.Color.DeepSkyBlue; |
|
|
|
label23.Enabled = false; |
|
|
|
label23.BackColor = System.Drawing.Color.Gray; |
|
|
|
textBox2.Text = ""; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|