private void BgwLoad_DoWork(object sender, DoWorkEventArgs e) { siemensTcpNet = new SiemensS7Net(SiemensPLCS.S1200) { IpAddress = plcIp, Rack = byte.Parse("0"), Slot = byte.Parse("0") }; OperateResult result = siemensTcpNet.ConnectServer(); if (!result.IsSuccess) { SetTag(this);//调用方法 MessageBox.Show("PLC连接失败,请检查PLC网络"); Close(); return; } list = new List <Model_Data>(); list = BLL_Data.GetData(pno); if (list.Count <= 0) { MessageBox.Show("请先接收数据!"); } else { try { index = list.Where(item => item.LabelingStatus == "0").Min(item => item.ID) - 1; } catch { MessageBox.Show("已接收数据中都已完成"); return; } count = int.Parse(list[index].PackageNum); Display(); siemensTcpNet.Write(db, (short)0); BgwReadPlc.RunWorkerAsync(); } }
private void BgwLoad_DoWork(object sender, DoWorkEventArgs e) { siemensTcpNet = new SiemensS7Net(SiemensPLCS.S1500) { IpAddress = plcIp, Rack = byte.Parse("0"), Slot = byte.Parse("0") }; deriction = ConfigurationManager.AppSettings["Deriction"].ToString().ToLower(); OperateResult result = siemensTcpNet.ConnectServer(); if (!result.IsSuccess) { X = this.Width; //获取窗体的宽度 Y = this.Height; //获取窗体的高度 SetTag(this); //调用方法 MessageBox.Show("PLC连接失败,请检查PLC网络"); Close(); return; } list = new List <Model_Data>(); list = BLL_Data.GetData(pno); if (list.Count <= 0) { MessageBox.Show("请先接收数据!"); } else { index = list.Where(item => item.LabelingStatus == "0").Min(item => item.ID) - 1; count = int.Parse(list[index].PackageNum); Display(); siemensTcpNet.Write(db, (short)0); BgwReadPlc.RunWorkerAsync(); } }
private void w_NormalDisplay_FormClosed(object sender, FormClosedEventArgs e) { BgwReadPlc.CancelAsync(); FormS.IsOpen = false; }
private void BGReadPlc_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { Thread.Sleep(readTime); BgwReadPlc.RunWorkerAsync(); }