Exemplo n.º 1
0
        private void stationThread()
        {
            List <Track> list;

            while (true)
            {
                for (int i = 0; i < stationList1.Count; i++)
                {
                    Station s = stationList1[i];
                    if ((s.OccupiedCar != null) && (s.Next != ""))
                    {
                        if (stationDic[s.Next].OccupiedCar == null)
                        {
                            list = adjList.FindWay(adjList.Find(s), adjList.Find(stationDic[s.Next]));
                            Track track = new Track();
                            foreach (Track t in list)
                            {
                                track.TrackPointList.AddRange(t.TrackPointList);
                            }
                            s.OccupiedCar.run(track);
                            stationDic[s.Next].OccupiedCar = s.OccupiedCar;
                            s.OccupiedCar = null;
                        }
                    }
                }
                Thread.Sleep(500);
            }
        }
Exemplo n.º 2
0
        public byte planRoadTable(byte carID, Station startStation, Station targetStation, Station endStation, AdjacencyList adj, SerialPort sp, Dictionary <string, Station> stationDic)
        {
            List <Track> list1   = adj.FindWay(adj.Find(startStation), adj.Find(targetStation));
            List <Track> list2   = adj.FindWay(adj.Find(targetStation), adj.Find(stationDic["F32"]));
            List <Track> list3   = adj.FindWay(adj.Find(stationDic["F32"]), adj.Find(endStation));
            List <byte>  command = new List <byte>();

            for (int i = 0; i < list1.Count; ++i)
            {
                if (list1[i].CarAction != null)
                {
                    string station = list1[i].CarAction.Substring(0, list1[i].CarAction.IndexOf('G'));
                    command.Add((byte)stationDic[station].CardID);
                    switch (list1[i].CarAction.Substring(list1[i].CarAction.Length - 1, 1))
                    {
                    case "L":
                        command.Add((byte)(0x50));
                        break;

                    case "R":
                        command.Add((byte)(0x51));
                        break;

                    case "S":
                        command.Add((byte)(0x52));
                        break;
                    }
                }
            }
            command.Add((byte)stationDic[targetStation.Name].CardID);
            command.Add((byte)(0x53));
            for (int i = 0; i < list2.Count; ++i)
            {
                if (list2[i].CarAction != null)
                {
                    string station = list2[i].CarAction.Substring(0, list2[i].CarAction.IndexOf('G'));
                    command.Add((byte)stationDic[station].CardID);
                    switch (list2[i].CarAction.Substring(list2[i].CarAction.Length - 1, 1))
                    {
                    case "L":
                        command.Add((byte)(0x50));
                        break;

                    case "R":
                        command.Add((byte)(0x51));
                        break;

                    case "S":
                        command.Add((byte)(0x52));
                        break;
                    }
                }
            }
            command.Add((byte)stationDic["F32"].CardID);
            command.Add((byte)(0x53));
            for (int i = 1; i < list3.Count; ++i)
            {
                if (list3[i].CarAction != null)
                {
                    string station = list3[i].CarAction.Substring(0, list3[i].CarAction.IndexOf('G'));
                    command.Add((byte)stationDic[station].CardID);
                    switch (list3[i].CarAction.Substring(list3[i].CarAction.Length - 1, 1))
                    {
                    case "L":
                        command.Add((byte)(0x50));
                        break;

                    case "R":
                        command.Add((byte)(0x51));
                        break;

                    case "S":
                        command.Add((byte)(0x52));
                        break;
                    }
                }
            }
            command.Add((byte)stationDic[endStation.Name].CardID);
            command.Add((byte)(0x53));
            if (command.Count >= 4 && command.Count <= 20)
            {
                byte CardCount = (byte)(command.Count >> 1);
                command.Insert(0, CardCount);
                command.Insert(0, CardCount);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)(carID));
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)(CardCount * 2 + 4));
                command.Insert(0, (byte)0xe6);
                command.Add(checksum(command));
                command.Insert(0, (byte)0x68);
                byte[] roadTable = new byte[command.Count];
                command.CopyTo(roadTable);

                //for (int j = 0; j < roadTable.Length; ++j)
                //{
                //    Console.Write(roadTable[j] + " ");
                //}
                sp.Write(roadTable, 0, roadTable.Length);

                return(CardCount);
            }
            else if (command != null && 20 < command.Count && command.Count <= 40)
            {
                byte total       = (byte)(command.Count >> 1);
                byte CardAccount = (byte)(command.Count >> 1);
                command.Insert(0, (byte)10);
                command.Insert(0, total);
                command.Insert(0, (byte)0);
                command.Insert(0, carID);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)(24));
                command.Insert(0, (byte)0xe6);
                byte csum = checksum(command, 28);
                command.Insert(0, (byte)0x68);
                byte[] roadTable = new byte[30];
                command.CopyTo(0, roadTable, 0, 29);
                roadTable[29] = (byte)(csum);

                //for (int j = 0; j < 30; ++j)
                //{
                //    Console.Write(roadTable[j] + " ");
                //}
                //Console.WriteLine();
                //roadTable[12] = (byte)0x50;
                //roadTable[18] = (byte)0x50;
                //roadTable[26] = (byte)0x50;
                //roadTable[28] = (byte)0x50;
                sp.Write(roadTable, 0, 30);
                Thread.Sleep(5000);
                command.RemoveRange(0, 29);
                CardAccount = (byte)(command.Count / 2);
                command.Insert(0, CardAccount);
                command.Insert(0, total);
                command.Insert(0, (byte)0x0a);
                command.Insert(0, carID);//bug
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)(CardAccount * 2 + 4));
                command.Insert(0, (byte)0xe6);
                command.Add(checksum(command));
                command.Insert(0, (byte)0x68);
                roadTable = new byte[command.Count];
                command.CopyTo(roadTable);
                //for (int j = 0; j < roadTable.Length; ++j)
                //{
                //    Console.Write(roadTable[j] + " ");
                //}
                sp.Write(roadTable, 0, roadTable.Length);

                return(total);
            }
            else if (command != null && 56 < command.Count && command.Count <= 84)
            {
                byte total       = (byte)(command.Count >> 1);
                byte CardAccount = (byte)(command.Count >> 1);
                command.Insert(0, (byte)14);
                command.Insert(0, total);
                command.Insert(0, (byte)0);
                command.Insert(0, carID);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)(32));
                command.Insert(0, (byte)0xe6);
                //command.Add(checksum(command));
                byte csum = checksum(command, 36);
                command.Insert(0, (byte)0x68);
                byte[] roadTable = new byte[38];
                command.CopyTo(0, roadTable, 0, 37);
                roadTable[37] = csum;
                for (int j = 0; j < 38; ++j)
                {
                    Console.Write(roadTable[j] + " ");
                }
                Console.WriteLine();
                sp.Write(roadTable, 0, 38);
                command.RemoveRange(0, 37);
                Console.WriteLine();
                command.Insert(0, (byte)14);
                command.Insert(0, total);
                command.Insert(0, (byte)0x26);
                command.Insert(0, carID);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)(32));
                command.Insert(0, (byte)0xe6);
                //command.Add(checksum(command));
                csum = checksum(command, 36);
                command.Insert(0, (byte)0x68);
                roadTable = new byte[38];
                command.CopyTo(0, roadTable, 0, 37);
                roadTable[37] = csum;
                for (int j = 0; j < 38; ++j)
                {
                    Console.Write(roadTable[j] + " ");
                }
                Console.WriteLine();
                sp.Write(roadTable, 0, 38);
                command.RemoveRange(0, 37);
                CardAccount = (byte)(command.Count >> 1);
                command.Insert(0, CardAccount);
                command.Insert(0, total);
                command.Insert(0, (byte)0x4c);
                command.Insert(0, carID);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)(CardAccount * 2 + 4));
                command.Insert(0, (byte)0xe6);
                command.Add(checksum(command));
                command.Insert(0, (byte)0x68);
                roadTable = new byte[command.Count];
                command.CopyTo(roadTable);
                for (int j = 0; j < roadTable.Length; ++j)
                {
                    Console.Write(roadTable[j] + " ");
                }
                sp.Write(roadTable, 0, roadTable.Length);
                return(0);
            }
            return(0);
        }
Exemplo n.º 3
0
        private void button9_Click(object sender, EventArgs e)//启动
        {
            Station temp1 = new Station();
            Station temp2 = new Station();
            string  str1;
            string  str2;
            string  str3;
            string  str4;

            if (button7.Text == "AGV1")
            {
                aTimer1 = new System.Timers.Timer(1000000);
                //aTimer1.BeginInit();
                aTimer1.Elapsed  += new ElapsedEventHandler(OnTimedEvent1);
                aTimer1.Interval  = 10;
                aTimer1.AutoReset = true;
                aTimer1.Enabled   = true;//只有Timer类 可以触发自身事件
                if (textBox7.Text == "等待")
                {
                    CurvePoint1   = null;
                    index1        = 0;
                    textBox7.Text = "工作";
                    str1          = textBox1.Text;
                    str2          = textBox13.Text;
                    foreach (AdjacencyList.Vertex ver in Adj.items)
                    {
                        if (str1 == ver.data.name)
                        {
                            temp1 = ver.data;
                            break;
                        }
                    }
                    foreach (AdjacencyList.Vertex ver in Adj.items)
                    {
                        if (str2 == ver.data.name)
                        {
                            temp2 = ver.data;
                            break;
                        }
                    }
                    List <Track> shortPath = Adj.FindWay(Adj.Find(temp1), Adj.Find(temp2));
                    if (temp2 != Start)
                    {
                        shortPath.AddRange(Adj.FindWay(Adj.Find(temp2), Adj.Find(Start)));
                    }
                    List <Point> temp    = new List <Point>();
                    List <Point> TempAll = new List <Point>();
                    foreach (Track m in shortPath)
                    {
                        temp = m.TrackPointList;
                        TempAll.AddRange(temp);
                    }
                    CurvePoint1 = TempAll.ToArray();
                    index1      = 0;
                    aTimer1.Start();
                    Pen blkPen = new Pen(Color.Black, 1);
                    dc1 = this.CreateGraphics();
                    try
                    {
                        dc1.DrawCurve(blkPen, CurvePoint1, 0.1f);
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine(ex.Message);
                    }
                }
            }

            if (button7.Text == "AGV2")
            {
                aTimer2           = new System.Timers.Timer(10000);
                aTimer2.Elapsed  += new ElapsedEventHandler(OnTimedEvent2);
                aTimer2.Interval  = 10;
                aTimer2.AutoReset = true;
                aTimer2.Enabled   = true;//只有Timer类 可以触发自身事件
                if (textBox8.Text == "等待")
                {
                    textBox8.Text = "工作";
                    str3          = textBox2.Text;
                    str4          = textBox14.Text;
                    foreach (AdjacencyList.Vertex ver in Adj.items)
                    {
                        if (str3 == ver.data.name)
                        {
                            temp1 = ver.data;
                        }
                    }
                    foreach (AdjacencyList.Vertex ver in Adj.items)
                    {
                        if (str4 == ver.data.name)
                        {
                            temp2 = ver.data;
                        }
                    }
                    List <Track> shortPath = Adj.FindWay(Adj.Find(temp1), Adj.Find(temp2));
                    List <Point> temp      = new List <Point>();
                    List <Point> TempAll   = new List <Point>();
                    foreach (Track m in shortPath)
                    {
                        temp = m.TrackPointList;
                        TempAll.AddRange(temp);
                    }
                    CurvePoint2 = TempAll.ToArray();
                    index2      = 0;
                    Pen blkPen = new Pen(Color.Black, 1);
                    dc2 = this.CreateGraphics();
                    try
                    {
                        dc2.DrawCurve(blkPen, CurvePoint1, 0.1f);
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine(ex.Message);
                    }
                }
            }
        }