Exemple #1
0
        private void HandleAGV(AGV agv)
        {
            Thread t = new Thread(() =>
            {
                while (agv.tcpClient.Connected)
                {
                    try
                    {
                        agv.odmX     = agv.clientBinaryReader.ReadInt16();
                        agv.odmY     = agv.clientBinaryReader.ReadInt16();
                        agv.odmAngle = agv.clientBinaryReader.ReadInt16();

                        //Console.WriteLine($"X = {agv.odmX}, Y = {agv.odmY}, Angle = {agv.odmAngle}");
                    }
                    catch (Exception ex)
                    {
                        //Console.WriteLine(ex);
                        break;
                    }

                    if (agv.isRunning)
                    {
                        if (agv.Route.Count > 1)
                        {
                            QRCode qr = agv.Route[1];
                            if (new Rectangle((int)(qr.X - 50), (int)(qr.Y - 50), 100, 100).Contains((int)(agv.odmX), (int)(agv.odmY)))
                            {
                                agv.Route.RemoveAt(0);
                            }
                        }
                        else
                        {
                            QRCode qr = agv.Route[0];
                            if (new Rectangle((int)(qr.X - 50), (int)(qr.Y - 50), 100, 100).Contains((int)(agv.odmX), (int)(agv.odmY)))
                            {
                                agv.Route.RemoveAt(0);
                            }
                            agv.isRunning = false;
                        }
                    }
                }
                Console.WriteLine($"\r\nClient {agv.hostName} is Disconnected!");
                AGVList.Remove(agv);
                AGVCount--;
            });

            t.IsBackground = true;
            t.Start();
        }