public void InitPLC() { try { OpcPlc opcPlc = new OpcPlc(); OperateOpcAndSoft.plc = opcPlc; } catch { } }
private void InitPLC() { try { OpcPlc opcPlc = new OpcPlc(); OperateOpcAndSoft.plc = opcPlc; } catch (Exception ex) { if ( MessageBox.Show("初始化PLC出现错误!是否退出查明原因?" + Environment.NewLine + ex.Message, "错误", MessageBoxButtons.YesNo) == DialogResult.Yes) { System.Environment.Exit(1); } } //////Thread.Sleep(1000); DialogResult = DialogResult.OK; this.BeginInvoke(new Action(Close)); }
private void timer2_Elapsed_1(object sender, System.Timers.ElapsedEventArgs e) { try { LineBoxStatus hanglineboxstatus; LineBoxStatus lineboxstatus; if (OperateOpcAndSoft.plc != null) { //hanglineboxstatus = opert.SubLineStatus(); //if (hanglineboxstatus != null && hanglineboxstatus.status == 1) //{ // if (hanglineboxstatus.lineboxcode.ToString() != labblockbox.Text) // { // try // { // SortingFault.SaveFaultBoxStatus(hanglineboxstatus.lineboxcode,hanglineboxstatus.status); // OperationLog operationLog = OperationLog.NewOperationLog(); // operationLog.OPERATIONCODE = "挂烟"; // operationLog.OPERATIONNAME = hanglineboxstatus.lineboxcode.ToString(); // operationLog.Save(); // } // catch // { } // labblockbox.Text = hanglineboxstatus.lineboxcode.ToString(); // labblockbox.ForeColor = Color.Red; // labboxstatus.ForeColor = Color.Red; // labblockname.ForeColor = Color.Red; // if (SortingLineTaskDetail.GetSortingLineBoxCigNumber(hanglineboxstatus.lineboxcode) == 1) // { // labblockname.Text = SortingLineTaskDetail.GetSortingLineBoxCigName(hanglineboxstatus.lineboxcode); // } // else // { // labblockname.Text = "混仓品牌"; // } // if (hanglineboxstatus.status == 1) // { // labboxstatus.Text = "挂烟"; // } // Thread thread = new Thread(new ParameterizedThreadStart(PlayHangSound)); // thread.Start(hanglineboxstatus); // } //} lineboxstatus = opert.GetLineBoxException(); if (lineboxstatus != null) { if (lineboxstatus.lineboxcode.ToString() != labblockbox.Text) { try { SortingFault.SaveFaultBoxStatus(lineboxstatus.lineboxcode, lineboxstatus.status, lineboxstatus.putnum); OperationLog operationLog = OperationLog.NewOperationLog(); if (lineboxstatus.status == 8) { operationLog.OPERATIONCODE = "卡烟"; //发送当前已打出的条烟到数码管 //SendTaskPutNiLight(lineboxstatus.lineboxcode); //Thread thread = new Thread(new ParameterizedThreadStart(SendTaskPutNiLight)); //thread.Start(lineboxstatus.lineboxcode); } if (lineboxstatus.status == 4) { operationLog.OPERATIONCODE = "缺烟"; } if (lineboxstatus.status == 16) { operationLog.OPERATIONCODE = "挂烟"; } operationLog.OPERATIONNAME = lineboxstatus.lineboxcode.ToString(); operationLog.Save(); } catch { } labblockbox.Text = lineboxstatus.lineboxcode.ToString(); labblockbox.ForeColor = Color.Red; labboxstatus.ForeColor = Color.Red; labblockname.ForeColor = Color.Red; if (SortingLineTaskDetail.GetSortingLineBoxCigNumber(lineboxstatus.lineboxcode) == 1) { labblockname.Text = SortingLineTaskDetail.GetSortingLineBoxCigName(lineboxstatus.lineboxcode); } else { labblockname.Text = "混仓品牌"; } if (lineboxstatus.status == 4) { labboxstatus.Text = "缺烟"; } if (lineboxstatus.status == 8) { labboxstatus.Text = "卡烟"; } if (lineboxstatus.status == 16) { labboxstatus.Text = "挂烟"; } Thread thread1 = new Thread(new ParameterizedThreadStart(PlayBlockSound)); thread1.Start(lineboxstatus); //发送当前已打出的条烟到数码管 SendTaskPutNiLight(lineboxstatus.lineboxcode); } } //if (hanglineboxstatus == null && lineboxstatus == null) if (lineboxstatus == null && labboxstatus.Text != "正常") { SortingFault.SaveFaultBoxStatus(0, 0, 0); labboxstatus.Text = "正常"; labboxstatus.ForeColor = Color.Green; labblockbox.Text = "无"; labblockbox.ForeColor = Color.Green; labblockname.Text = "无"; labblockname.ForeColor = Color.Green; Nixielight ni = new Nixielight(); ni.SendNull(); } } else { try { OpcPlc opcPlc = new OpcPlc(); OperateOpcAndSoft.plc = opcPlc; } catch { } } } catch (Exception ex) { try { OperationLog operationLog = OperationLog.NewOperationLog(); operationLog.OPERATIONCODE = "出现异常"; operationLog.OPERATIONNAME = ex.Message; operationLog.Save(); } catch (Exception) { } } }