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