using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; using AGV_WPF_Global; using System.Data.OleDb; using System.Xml.Serialization; using System.IO; using System.Threading.Tasks; using AGV_WPF.Models; using HslCommunication; using AGV_WPF.Tools; using System.Diagnostics; namespace AGV_WPF { public partial class DispatchSystem : Form { DataTable dtConfig = new DataTable(); HslCommunication.OperateResult result; int HeartBitCount = 1; private delegate void InvokeDelegate(); Dictionary checkPosDic = new Dictionary(); Dictionary AGVIDWithPosByCheckPos = new Dictionary(); Dictionary AGVIDWithRouteByCheckPos = new Dictionary(); Dictionary DBWithByteValue = new Dictionary(); private static object portLock = new object(); Stopwatch sw = new Stopwatch(); Dictionary dicReleaseArea = new Dictionary(); public int CurCFDRoute = -1; Dictionary InitOK = new Dictionary(); List CFDRoutes = new List(); int index = 0; int CFDWaitTimes = 15; int CFDCheckTimes = 0; Dictionary> dicCheck = new Dictionary>(); DataTable DtTraffic = new DataTable(); List listTra = new List(); byte PLCHeartBitCount = 0; bool HeartBitFlag = true; OperateResult PLCResult; bool IsPLCChangeOff = false; DataTable LineDt = new DataTable(); bool DockingOK = false; public DispatchSystem() { InitializeComponent(); } private void DispatchSystem_Load(object sender, EventArgs e) { LoadConfig(); this.FormClosing += new FormClosingEventHandler(DispatchSystem_FormClosing); Thread thread2 = new Thread(HeartBit); thread2.Start(); Thread thread = new Thread(Analzye); thread.Start(); } void DispatchSystem_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = true; } /// /// 加载配置 /// public void LoadConfig() { sw.Restart(); tabControl1.TabPages.Clear(); 物料设置ToolStripMenuItem.DropDownItems.Clear(); checkPosDic.Clear(); AGVIDWithPosByCheckPos.Clear(); DBWithByteValue.Clear(); HeartBitCount = 1; XmlSerializer deserializer1 = new XmlSerializer(GlobalPara.gs_configInfo.GetType()); try { using (TextReader tr = new StreamReader("CConfig.xml")) { GlobalPara.gs_configInfo = (AGV_WPF.Tools.CConfigData)deserializer1.Deserialize(tr); } } catch (Exception ex) { } string currPath = System.AppDomain.CurrentDomain.BaseDirectory; string dataPath = currPath + @"data"; string dataFile = dataPath + @"\基础配置表.xls"; try { string confStr1 = @"Provider=Microsoft.ACE.OLEDB.12.0;"; string confStr2 = @"Persist Security Info=false;"; string confStr3 = @"Data Source=" + dataFile + ";"; string confStr4 = @"Extended Properties=" + "'Excel 12.0;HDR=YES;IMEX=1'"; string connStr = confStr1 + confStr2 + confStr3 + confStr4; OleDbConnection oleDC = new OleDbConnection(connStr); OleDbDataAdapter oleDDA1 = new OleDbDataAdapter("Select * From [参数配置$]", oleDC); oleDDA1.Fill(dtConfig); OleDbDataAdapter oleDDA2 = new OleDbDataAdapter("Select * From [物料类型$]", oleDC); DataTable temp = new DataTable(); oleDDA2.Fill(temp); if (temp.Rows.Count > 0) { for (int i = 0; i < temp.Rows.Count; i++) { ToolStripMenuItem tsm = new ToolStripMenuItem(temp.Rows[i][1].ToString()); 物料设置ToolStripMenuItem.DropDownItems.Add(tsm); tsm.Font = new Font("黑体", 15); if (GlobalPara.gs_configInfo.CurrentMatName == temp.Rows[i][1].ToString()) { tsm.CheckState = CheckState.Checked; } tsm.Click += new EventHandler(tsm_Click); } } tabControl1.DrawMode = TabDrawMode.Normal; tabControl1.SizeMode = TabSizeMode.Fixed; tabControl1.DrawItem += new DrawItemEventHandler(tabControl1_DrawItem); GlobalPara.s7 = new HslCommunication.Profinet.Siemens.SiemensS7Net(HslCommunication.Profinet.Siemens.SiemensPLCS.S1500, dtConfig.Rows[0][1].ToString()); GlobalPara.s7.Rack = (byte)Convert.ToInt16(dtConfig.Rows[2][1].ToString()); GlobalPara.s7.Slot = (byte)Convert.ToInt16(dtConfig.Rows[3][1].ToString()); GlobalPara.s7.ConnectTimeOut = 10; GlobalPara.s7.ReceiveTimeOut = 10; result = GlobalPara.s7.ConnectServer(); sw.Stop(); Console.WriteLine("配置初始化总共花费{0}s.", sw.Elapsed.TotalSeconds); sw.Restart(); InitView(); sw.Stop(); Console.WriteLine("界面初始化总共花费{0}s.", sw.Elapsed.TotalSeconds); } catch (System.Exception ex) { MessageBox.Show(ex.StackTrace); } } void tsm_Click(object sender, EventArgs e) { for (int i = 0; i < 物料设置ToolStripMenuItem.DropDownItems.Count; i++) { if (((ToolStripMenuItem)物料设置ToolStripMenuItem.DropDownItems[i]).Text == ((ToolStripMenuItem)sender).Text && ((ToolStripMenuItem)sender).CheckState == CheckState.Checked) { return; } ((ToolStripMenuItem)物料设置ToolStripMenuItem.DropDownItems[i]).CheckState = CheckState.Unchecked; } ((ToolStripMenuItem)sender).Checked = true; GlobalPara.gs_configInfo.CurrentMatName = ((ToolStripMenuItem)sender).Text; XmlSerializer serializer2 = new XmlSerializer(GlobalPara.gs_configInfo.GetType()); using (TextWriter tw = new StreamWriter("CConfig.xml")) { serializer2.Serialize(tw, GlobalPara.gs_configInfo); } this.DispatchSystem_Load(null, null); } void tsm_CheckedChanged(object sender, EventArgs e) { //throw new NotImplementedException(); } void tsm_CheckStateChanged(object sender, EventArgs e) { //throw new NotImplementedException(); } /// /// 界面初始化 /// /// public void InitView() { string currPath = System.AppDomain.CurrentDomain.BaseDirectory; string dataPath = currPath + @"data\"; string dataFile = dataPath + GlobalPara.gs_configInfo.CurrentMatName + ".xls"; if (false == File.Exists(dataFile)) { DirectoryInfo di = new DirectoryInfo(dataPath); foreach (FileInfo f in di.GetFiles()) { if (f.Name != "基础配置表" && f.Extension.Contains(".xls")) { GlobalPara.gs_configInfo.CurrentMatName = f.Name.Replace(".xls", ""); for (int i = 0; i < 物料设置ToolStripMenuItem.DropDownItems.Count; i++) { if (物料设置ToolStripMenuItem.DropDownItems[i].Text == GlobalPara.gs_configInfo.CurrentMatName) { ((ToolStripMenuItem)物料设置ToolStripMenuItem.DropDownItems[i]).CheckState = CheckState.Checked; } } dataFile = f.FullName; break; } } } try { string confStr1 = @"Provider=Microsoft.ACE.OLEDB.12.0;"; string confStr2 = @"Persist Security Info=false;"; string confStr3 = @"Data Source=" + dataFile + ";"; string confStr4 = @"Extended Properties=" + "'Excel 12.0;HDR=YES;IMEX=1'"; string connStr = confStr1 + confStr2 + confStr3 + confStr4; OleDbConnection oleDC = new OleDbConnection(connStr); OleDbDataAdapter oleDDA2 = new OleDbDataAdapter("Select * From [线体信息$]", oleDC); oleDDA2.Fill(LineDt); Dictionary listThread = new Dictionary(); for (int i = 0; i < LineDt.Rows.Count; i++) { string lineName = LineDt.Rows[i]["线体名称"].ToString(); TabPage tb = new TabPage(lineName); tb.Font = new System.Drawing.Font("楷体", tb.Font.Size + 5); oleDDA2 = new OleDbDataAdapter("Select * From [" + lineName + "$]", oleDC); DataTable temp2 = new DataTable(); temp2.TableName = lineName; oleDDA2.Fill(temp2); if (LineDt.Rows[i]["判断点"] != null && !string.IsNullOrEmpty(LineDt.Rows[i]["判断点"].ToString()) && LineDt.Rows[i]["判断点"].ToString() != "0") { if (!checkPosDic.ContainsKey(int.Parse(LineDt.Rows[i]["判断点"].ToString()))) { checkPosDic.Add(int.Parse(LineDt.Rows[i]["判断点"].ToString()), lineName); } } int X = 10, Y = 10; List