Exemplo n.º 1
0
        private void HomeScreenForm_Load(object sender, EventArgs e)
        {
            DashboardForm dashboardForm = new DashboardForm();

            Initial_Form(dashboardForm);
            pnMain.Controls.Add(dashboardForm);
            dashboardForm.BringToFront();
            dashboardForm.Show();
        }
Exemplo n.º 2
0
        private void dashoardToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Thread.Sleep(200);
            DashboardForm dashboardForm = new DashboardForm();

            Initial_Form(dashboardForm);
            pnMain.Controls.Add(dashboardForm);
            dashboardForm.BringToFront();
            dashboardForm.Show();
        }
Exemplo n.º 3
0
        //  public static System.Windows.Forms.Timer timerToSendPath2Again;
        public static void GetDataRecieve()
        {
            int rxBufferSize = 18;

            byte[] rxBuffer    = new byte[rxBufferSize];
            int    rxByteCount = Communication.SerialPort.Read(rxBuffer, 0, rxBufferSize);

            // add to a list of bytes received
            for (int i = 0; i < rxByteCount; i++)
            {
                bytesReceived.Add(rxBuffer[i]);
            }

            int  startIndex   = 0;
            byte functionCode = new byte();

            // check header
            if (bytesReceived.Count < 3)
            {
                return;
            }
            for (int i = 0; i < bytesReceived.Count - 3; i++)
            {
                if (bytesReceived[i] == 0xAA && bytesReceived[i + 1] == 0xFF)
                {
                    startIndex   = i;
                    functionCode = bytesReceived[i + 2];

                    if (functionCode == 0xA0)
                    {
                        // waitting for receive enough frame data of this function code
                        if (bytesReceived.Count - startIndex < PIDInfoReceivePacketSize)
                        {
                            return;
                        }

                        // put data in an array
                        byte[] data = new byte[PIDInfoReceivePacketSize];
                        for (int j = 0; j < PIDInfoReceivePacketSize; j++)
                        {
                            data[j] = bytesReceived[startIndex + j];
                        }

                        PIDInfoReceivePacket receiveFrame = PIDInfoReceivePacket.FromArray(data);

                        // check sum
                        //   ushort crc = 0;
                        //   for (int j = 0; j < PIDInfoReceivePacketSize - 4; j++)
                        //      crc += data[j];
                        // if (crc != receiveFrame.CheckSum) continue;

                        bytesReceived.RemoveRange(0, startIndex + PIDInfoReceivePacketSize - 1);

                        // update AGV info to lists of AGVs (real-time mode)
                        // if (receiveFrame.Header[0] == 0xAA && receiveFrame.Header[1] == 0xFF && receiveFrame.EndOfFrame[0] == 0x0D && receiveFrame.EndOfFrame[1] == 0x0A)

                        speed = receiveFrame.Velocity;
                        //dk_Speed = receiveFrame.UdkVelocity;
                        line = receiveFrame.LinePos;
                        var agv = AGV.ListAGV.Find(a => a.ID == receiveFrame.AGVID);
                        if (agv == null)
                        {
                            continue;
                        }
                        //udk_LinePos = receiveFrame.UdkLinePos;
                        //if(receiveFrame.CurrentNode >=0 || receiveFrame.CurrentNode <= 56)
                        agv.CurrentNode           = receiveFrame.CurrentNode;
                        agv.CurrentOrient         = receiveFrame.currentOrient;
                        agv.Velocity              = receiveFrame.Velocity;
                        agv.DistanceToCurrentNode = receiveFrame.distanceToPreNode;
                        //Display.UpdateComStatus("receive", agv.ID, "Receive AGV Information", Color.Green);
                    }
                    if (functionCode == 0xE0)      //Xac nhan chay xong Path1
                    {
                        // waitting for receive enough frame data of this function code
                        if (bytesReceived.Count - startIndex < PathCompleteReceivePacketSize)
                        {
                            return;
                        }

                        // put data in an array
                        byte[] data = new byte[PathCompleteReceivePacketSize];
                        for (int j = 0; j < PathCompleteReceivePacketSize; j++)
                        {
                            data[j] = bytesReceived[startIndex + j];
                        }

                        PathCompleteRecievePacket receiveFrame = PathCompleteRecievePacket.FromArray(data);
                        bytesReceived.RemoveRange(0, startIndex + PathCompleteReceivePacketSize - 1);

                        Debug.Write("PathRun_Completed");
                        AGV agv = AGV.ListAGV[0];
                        agv.PathCopmpleted = 1;
                        Debug.WriteLine("PathComplete = 1");
                        FlagPath1Complete++;
                        if (FlagPath1Complete == 1)
                        {
                            Display.UpdateComStatus("receive", agv.ID, " AGV Complete Path 1", Color.Green);
                        }
                    }
                    if (functionCode == 0xE1)      //Xac nhan chay xong Path2
                    {
                        // waitting for receive enough frame data of this function code
                        if (bytesReceived.Count - startIndex < PathCompleteReceivePacketSize)
                        {
                            return;
                        }

                        // put data in an array
                        byte[] data = new byte[PathCompleteReceivePacketSize];
                        for (int j = 0; j < PathCompleteReceivePacketSize; j++)
                        {
                            data[j] = bytesReceived[startIndex + j];
                        }

                        PathCompleteRecievePacket receiveFrame = PathCompleteRecievePacket.FromArray(data);
                        bytesReceived.RemoveRange(0, startIndex + PathCompleteReceivePacketSize - 1);

                        Debug.Write("PathRun_Completed");
                        AGV agv = AGV.ListAGV[0];
                        agv.PathCopmpleted = 3;
                        Debug.WriteLine("PathComplete = 3");
                        FlagPath2Complete++;
                        if (FlagPath2Complete == 1)
                        {
                            Display.UpdateComStatus("receive", agv.ID, " AGV Complete Path 2", Color.Green);
                        }
                    }
                    if (functionCode == 0xC1)        // ACK Speed
                    {
                        if (bytesReceived.Count - startIndex < PathCompleteReceivePacketSize)
                        {
                            return;
                        }

                        // put data in an array
                        byte[] data = new byte[PathCompleteReceivePacketSize];
                        for (int j = 0; j < PathCompleteReceivePacketSize; j++)
                        {
                            data[j] = bytesReceived[startIndex + j];
                        }

                        PathCompleteRecievePacket receiveFrame = PathCompleteRecievePacket.FromArray(data);
                        bytesReceived.RemoveRange(0, startIndex + PathCompleteReceivePacketSize - 1);

                        if (DashboardForm.timerToSendSpeedAgain.Enabled == true)
                        {
                            DashboardForm.timerToSendSpeedAgain.Stop();
                        }
                        Display.UpdateComStatus("receive", receiveFrame.AGVID, " ACK Speed", Color.Green);
                    }

                    else if (functionCode == 0xD0)       //NAK Speed
                    {
                        if (bytesReceived.Count - startIndex < PathCompleteReceivePacketSize)
                        {
                            return;
                        }

                        // put data in an array
                        byte[] data = new byte[PathCompleteReceivePacketSize];
                        for (int j = 0; j < PathCompleteReceivePacketSize; j++)
                        {
                            data[j] = bytesReceived[startIndex + j];
                        }

                        PathCompleteRecievePacket receiveFrame = PathCompleteRecievePacket.FromArray(data);
                        bytesReceived.RemoveRange(0, startIndex + PathCompleteReceivePacketSize - 1);
                        Display.UpdateComStatus("receive", receiveFrame.AGVID, " NAK Speed", Color.Red);
                        //   if (DashboardForm.timerToSendSpeedAgain.Enabled == true)
                        //     DashboardForm.timerToSendSpeedAgain.Stop();
                        DashboardForm.sendSpeedFrame();
                    }
                    if (functionCode == 0xC2)       //ACK Line
                    {
                        if (bytesReceived.Count - startIndex < PathCompleteReceivePacketSize)
                        {
                            return;
                        }

                        // put data in an array
                        byte[] data = new byte[PathCompleteReceivePacketSize];
                        for (int j = 0; j < PathCompleteReceivePacketSize; j++)
                        {
                            data[j] = bytesReceived[startIndex + j];
                        }

                        PathCompleteRecievePacket receiveFrame = PathCompleteRecievePacket.FromArray(data);
                        bytesReceived.RemoveRange(0, startIndex + PathCompleteReceivePacketSize - 1);

                        if (DashboardForm.timerToSendLineAgain.Enabled == true)
                        {
                            DashboardForm.timerToSendLineAgain.Stop();
                        }
                        Display.UpdateComStatus("receive", receiveFrame.AGVID, " ACK Line", Color.Green);
                    }

                    else if (functionCode == 0xD1)       //NAK Line
                    {
                        if (bytesReceived.Count - startIndex < PathCompleteReceivePacketSize)
                        {
                            return;
                        }

                        // put data in an array
                        byte[] data = new byte[PathCompleteReceivePacketSize];
                        for (int j = 0; j < PathCompleteReceivePacketSize; j++)
                        {
                            data[j] = bytesReceived[startIndex + j];
                        }

                        PathCompleteRecievePacket receiveFrame = PathCompleteRecievePacket.FromArray(data);
                        bytesReceived.RemoveRange(0, startIndex + PathCompleteReceivePacketSize - 1);

                        // if (DashboardForm.timerToSendLineAgain.Enabled == true)
                        //     DashboardForm.timerToSendLineAgain.Stop();
                        DashboardForm.sendLineFrame();
                        Display.UpdateComStatus("receive", receiveFrame.AGVID, " NAK Line", Color.Red);
                    }
                    if (functionCode == 0xC3)       //ACK Path
                    {
                        if (bytesReceived.Count - startIndex < PathCompleteReceivePacketSize)
                        {
                            return;
                        }

                        // put data in an array
                        byte[] data = new byte[PathCompleteReceivePacketSize];
                        for (int j = 0; j < PathCompleteReceivePacketSize; j++)
                        {
                            data[j] = bytesReceived[startIndex + j];
                        }

                        PathCompleteRecievePacket receiveFrame = PathCompleteRecievePacket.FromArray(data);
                        bytesReceived.RemoveRange(0, startIndex + PathCompleteReceivePacketSize - 1);
                        FlagPath1Complete = 0;
                        FlagPath2Complete = 0;
                        if (AGV.ListAGV[0].PathCopmpleted == 1)
                        {
                            AGV.ListAGV[0].PathCopmpleted = 2;
                            //if (DashboardForm.timerToSendPathAgain.Enabled == true)
                            //   DashboardForm.timerToSendPathAgain.Stop();
                        }
                        else if (AGV.ListAGV[0].PathCopmpleted == 0)
                        {
                            AGV.ListAGV[0].Tasks[0].Status = "Doing";
                            AGV.ListAGV[0].Status          = "Running";
                            //  if (DashboardForm.timerToSendPathAgain.Enabled == true)
                            //    DashboardForm.timerToSendPathAgain.Stop();
                        }
                        Debug.WriteLine("AcK Path");
                        Display.UpdateComStatus("receive", receiveFrame.AGVID, " ACK Path", Color.Green);
                    }
                    else if (functionCode == 0xD2)       //NAK Path
                    {
                        if (bytesReceived.Count - startIndex < PathCompleteReceivePacketSize)
                        {
                            return;
                        }

                        // put data in an array
                        byte[] data = new byte[PathCompleteReceivePacketSize];
                        for (int j = 0; j < PathCompleteReceivePacketSize; j++)
                        {
                            data[j] = bytesReceived[startIndex + j];
                        }

                        PathCompleteRecievePacket receiveFrame = PathCompleteRecievePacket.FromArray(data);
                        bytesReceived.RemoveRange(0, startIndex + PathCompleteReceivePacketSize - 1);

                        if (AGV.ListAGV[0].PathCopmpleted == 1)
                        {
                            AGV.ListAGV[0].PathCopmpleted = 1;
                        }
                        else if (AGV.ListAGV[0].PathCopmpleted == 0)
                        {
                            AGV.ListAGV[0].PathCopmpleted = 0;
                            //  DashboardForm.timerToSendPathAgain.Stop();
                            // Task currentTask = AGV.ListAGV[0].Tasks[0];
                            //  currentTask.Status = "Waiting";
                            // AGV.ListAGV[0].PathCopmpleted = 0;
                        }
                        Debug.WriteLine("NAK Path");
                        Display.UpdateComStatus("receive", receiveFrame.AGVID, " NAK Path", Color.Red);
                    }
                }
            }
        }