Пример #1
0
        public bool GetDevicesList(PlanControl planControl)
        {
            this.planControl = planControl;
            if (!Global_Object.ServerAlive())
            {
                return(false);
            }
            try
            {
                workerLoadDevice = new BackgroundWorker();
                workerLoadDevice.WorkerSupportsCancellation = true;
                workerLoadDevice.WorkerReportsProgress      = true;
                workerLoadDevice.DoWork             += WorkerLoadDevice_DoWork;
                workerLoadDevice.ProgressChanged    += WorkerLoadDevice_ProgressChanged;
                workerLoadDevice.RunWorkerCompleted += WorkerLoadDevice_RunWorkerCompleted;
                workerLoadDevice.RunWorkerAsync();

                return(true);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                return(false);
            }
        }
 public void Destroy()
 {
     // Global_Object.onFlagDoorBusy = false;
     robot.robotBahaviorAtGate = RobotBahaviorAtReadyGate.IDLE;
     if (ds != null)
     {
         ds.LampSetStateOff(DoorType.DOOR_FRONT);
         ds.setDoorBusy(false);
         ds.removeListCtrlDoorBack();
     }
     Global_Object.setGateStatus(order.gate, false);
     ProRunStopW     = false;
     robot.orderItem = null;
     robot.SwitchToDetectLine(false);
     robot.robotTag = RobotStatus.IDLE;
     robot.ReleaseWorkingZone();
     order.status = StatusOrderResponseCode.ROBOT_ERROR;
     //robot.prioritLevel.OnAuthorizedPriorityProcedure = false;
     ProRun = false;
     UpdateInformationInProc(this, ProcessStatus.F);
     order.status      = StatusOrderResponseCode.ROBOT_ERROR;
     selectHandleError = SelectHandleError.CASE_ERROR_EXIT;
     this.robot.DestroyRegistrySolvedForm();
     procedureStatus          = ProcedureStatus.PROC_KILLED;
     order.endTimeProcedure   = DateTime.Now;
     order.totalTimeProcedure = order.endTimeProcedure.Subtract(order.startTimeProcedure).TotalMinutes;
     // RestoreOrderItem();
 }
Пример #3
0
 public override void Draw()
 {
     Width  = Global_Object.LengthBetweenPoints(props._oriMousePos, props._desMousePos);
     Height = Width * rate;
     if (Height > 40)
     {
         Height = 40;
     }
     props._start.X = 0;
     props._start.Y = Height;
     props._end.X   = Width;
     props._end.Y   = Height;
     //Control point
     props.xDiff    = props._desMousePos.X - props._oriMousePos.X;
     props.yDiff    = props._desMousePos.Y - props._oriMousePos.Y;
     controlPoint.X = Width / 2;
     controlPoint.Y = -Height / 1.5;
     //Middle point of curve path
     //-----------Middle point-------------
     props._middle.X = (1 - t) * (1 - t) * (1 - t) * props._start.X + 3 * (1 - t) * (1 - t) * t * props._start.X + 3 * (1 - t) * t * t * controlPoint.X + t * t * t * props._end.X;
     props._middle.Y = (1 - t) * (1 - t) * (1 - t) * props._start.Y + 3 * (1 - t) * (1 - t) * t * props._start.Y + 3 * (1 - t) * t * t * controlPoint.Y + t * t * t * props._end.Y;
     //--------------------------------
     // Point at _start and _end
     props._pointTail.RenderTransform = new TranslateTransform(Width / 2, Height / 2);
     props._pointHead.RenderTransform = new TranslateTransform(-Width / 2, Height / 2);
     //Arrow show direction
     //3 Point of Triangle
     props.arrowPoints[0] = (new Point(props._middle.X - props.sizeArrow, props._middle.Y - props.sizeArrow));
     props.arrowPoints[1] = (new Point(props._middle.X - props.sizeArrow, props._middle.Y + props.sizeArrow));
     props.arrowPoints[2] = (new Point(props._middle.X + props.sizeArrow + 1, props._middle.Y));
     props._arrow.Points  = props.arrowPoints;
     //Position the Path
     bezierSegment.Point1    = props._start;
     bezierSegment.Point2    = controlPoint;
     bezierSegment.Point3    = props._end;
     bezierSegment.IsStroked = true;
     if (props.pathSegments.Count > 0)
     {
         props.pathSegments[0] = bezierSegment;
     }
     else
     {
         props.pathSegments.Add(bezierSegment);
     }
     props.pathFigure.StartPoint = props._start;
     //Render Path
     props.rotate = (Math.Atan2(props.yDiff, props.xDiff) * 180.0 / Math.PI);
     props.myRotateTransform.Angle      = props.rotate;
     props.myTranslate                  = new TranslateTransform(props._oriMousePos.X, props._oriMousePos.Y - (Height));
     props.myTransformGroup.Children[1] = props.myTranslate;
     // SPECIAL POINTS
     props.cornerPoints[0] = CoorPointAtBorder(new Point((0), (Height / 2)));        //mid-left
     props.cornerPoints[1] = CoorPointAtBorder(new Point((0), (0)));                 //top-left
     props.cornerPoints[2] = CoorPointAtBorder(new Point((Width / 2), (0)));         //top-mid
     props.cornerPoints[3] = CoorPointAtBorder(new Point((Width), (0)));             //top-right
     props.cornerPoints[4] = CoorPointAtBorder(new Point((Width), (Height / 2)));    //mid-right
     props.cornerPoints[5] = CoorPointAtBorder(new Point((Width), (Height)));        //bot-right
     props.cornerPoints[6] = CoorPointAtBorder(new Point((Width / 2), (Height)));    //bot-mid
     props.cornerPoints[7] = CoorPointAtBorder(new Point((0), (Height)));            //bot-left
 }
Пример #4
0
        public bool CheckGreenCircle_HighWay() // khi robot bặt vòng tròn xanh. chính nó phải ngưng nếu dò ra có robot nào trong vùng vòng tròn này ngược lại với vòng tròn vàng
        {
            bool onStop = false;
            List <RobotUnity> robotTochList = new List <RobotUnity>();

            foreach (RobotUnity r in RobotUnitylist)
            {
                Point cG = CenterOnLineCv(Center_G); // TRONG TAM CUA NO
                if (r.robotTag == RobotStatus.WORKING)
                {
                    if (FindHeaderInsideCircleArea(MiddleHeaderCv(), cG, r.Radius_G) ||
                        FindHeaderInsideCircleArea(Global_Object.CoorCanvas(properties.pose.Position), cG, r.Radius_G) ||
                        FindHeaderInsideCircleArea(MiddleHeaderCv1(), cG, r.Radius_G))
                    {
                        // tim do ưu tien tai cac diem giao nhau
                        if (checkAllRobotsHasInsideBayIdNear(r))
                        {
                            STATE_SPEED = "GREEN_STOP_HIGHWAY " + r.properties.Label;
                            SetSpeedTraffic(RobotSpeedLevel.ROBOT_SPEED_STOP, true);
                            delay(2000);
                            onStop = true;
                            return(onStop);
                        }
                    }
                }
            }
            return(onStop);
        }
Пример #5
0
        private void ChangeToolTipContent(object sender, ToolTipEventArgs e)
        {
            try
            {
                String OrderStr = "";
                if (orderItem != null)
                {
                    OrderStr = "" + orderItem.typeReq + " / " + orderItem.productDetailName;
                }

                TypeZone typezone = trafficManagementService.GetTypeZone(properties.pose.Position, 0, 200);
                double   angle    = -properties.pose.Angle;
                Point    position = Global_Object.CoorLaser(properties.pose.Position);
                String   statusLaserBack;
                if (resetLaserBack)
                {
                    statusLaserBack = " Passed error laserBack";
                }
                else
                {
                    statusLaserBack = " LaserBack run normal";
                }
                String tooltipStr = "Name: " + properties.Label + Environment.NewLine + "Zone: " + typezone +
                                    Environment.NewLine + " Location: " + position.X.ToString("0.00") + " / " +
                                    position.Y.ToString("0.00") + " / " + angle.ToString("0.00") + Environment.NewLine +
                                    "Place: " + TyprPlaceStr + Environment.NewLine +
                                    "Working Zone: " + robotRegistryToWorkingZone.WorkingZone + "/ " + trafficManagementService.DetermineArea(this.properties.pose.Position, 0, 200) + Environment.NewLine +
                                    "Radius _S" + Radius_S + Environment.NewLine +
                                    "Radius _Y" + Radius_R + Environment.NewLine +
                                    "Radius _B" + Radius_B + Environment.NewLine +
                                    "Speed Set :" + properties.speedInSpecicalArea + Environment.NewLine +
                                    "STATE: " + STATE_SPEED + Environment.NewLine +
                                    "MIDDLE :" + MiddleHeaderCv().X.ToString("0.00") + " /" + MiddleHeaderCv().Y.ToString("0.00") + Environment.NewLine +
                                    "MIDDLE1 :" + MiddleHeaderCv1().X.ToString("0.00") + " /" + MiddleHeaderCv1().Y.ToString("0.00") + Environment.NewLine +
                                    "MIDDLE2 :" + MiddleHeaderCv2().X.ToString("0.00") + " /" + MiddleHeaderCv2().Y.ToString("0.00") + Environment.NewLine +
                                    "ValueR SC:" + valueSC + Environment.NewLine +
                                    "ValueR BigC:" + valueBigC + Environment.NewLine +
                                    "RobotTag:" + robotTag + Environment.NewLine +
                                    "CheckGate: " + robotRegistryToWorkingZone.onRobotwillCheckInsideGate + Environment.NewLine +
                                    "Order: " + OrderStr + Environment.NewLine +
                                    "Battery Level: " + properties.BatteryLevelRb + Environment.NewLine +
                                    "Robots Registry in Ready: " + TrafficRountineConstants.RegIntZone_READY.getNames() + Environment.NewLine +
                                    "Robots Registry in GATE 12: " + TrafficRountineConstants.RegIntZone_GATE12.getNames() + Environment.NewLine +
                                    "Robots Registry in Elevator: " + TrafficRountineConstants.RegIntZone_ELEVATOR.getNames() + Environment.NewLine +
                                    "Robots Registry in Gate3: " + TrafficRountineConstants.RegIntZone_GATE3.getNames() + Environment.NewLine +
                                    "Gate 1: " + Global_Object.getGateStatus((int)DoorId.DOOR_MEZZAMINE_UP) + Environment.NewLine +
                                    "Gate 2: " + Global_Object.getGateStatus((int)DoorId.DOOR_MEZZAMINE_UP_NEW) + Environment.NewLine +
                                    "Robot_BAYID: " + bayId + Environment.NewLine +
                                    "Start_Point_Name: " + StartPointName + Environment.NewLine +
                                    "Start_Point: " + StartPoint.ToString() + Environment.NewLine +
                                    "End_Point_Name: " + EndPointName + Environment.NewLine +
                                    "end_Point: " + EndPoint.ToString() + Environment.NewLine +
                                    "laserBackStatus :" + statusLaserBack + Environment.NewLine
                ;

                border.ToolTip = tooltipStr;
            }
            catch { }
        }
        public virtual Point TopTailCv()//BottomTailCv()
        {
            double AngleW = -properties.pose.AngleW;
            double x      = Global_Object.CoorCanvas(properties.pose.Position).X + Math.Sqrt(Math.Abs(L2Cv) * Math.Abs(L2Cv) + Math.Abs(WSCv / 2) * Math.Abs(WSCv / 2)) * Math.Cos(AngleW + Math.Atan2(WSCv / 2, -L2Cv));
            double y      = Global_Object.CoorCanvas(properties.pose.Position).Y + Math.Sqrt(Math.Abs(L2Cv) * Math.Abs(L2Cv) + Math.Abs(WSCv / 2) * Math.Abs(WSCv / 2)) * Math.Sin(AngleW + Math.Atan2(WSCv / 2, -L2Cv));

            return(new Point(x, y));
        }
        public virtual Point TopHeaderCenterCv(double dc)//BottomHeaderCv()
        {
            double AngleW = -properties.pose.AngleW;
            double x      = Global_Object.CoorCanvas(properties.pose.Position).X + Math.Sqrt(Math.Abs(dc) * Math.Abs(dc) + Math.Abs(WSCv / 2) * Math.Abs(WSCv / 2)) * Math.Cos(AngleW + Math.Atan2(WSCv / 2, dc));
            double y      = Global_Object.CoorCanvas(properties.pose.Position).Y + Math.Sqrt(Math.Abs(dc) * Math.Abs(dc) + Math.Abs(WSCv / 2) * Math.Abs(WSCv / 2)) * Math.Sin(AngleW + Math.Atan2(WSCv / 2, dc));

            return(new Point(x, y));
        }
Пример #8
0
 private void ChangeToolTipContent(object sender, ToolTipEventArgs e)
 {
     ToolTip = "Tên: " + props.NameID +
               "\n Vị trí: " + Global_Object.CoorLaser(props._posision).X.ToString("0.00") + "," + Global_Object.CoorLaser(props._posision).Y.ToString("0.00") +
               " \n Dài: " + Height.ToString("0.00") + "m" +
               " \n Rộng: " + Width.ToString("0.00") + "m" +
               " \n Góc quay: " + props._rotate;
 }
        public virtual Point BottomHeaderCv()//TopHeaderCv()//
        {
            double AngleW = -properties.pose.AngleW;
            double x      = Global_Object.CoorCanvas(properties.pose.Position).X + Math.Sqrt((Math.Abs(L1Cv) * Math.Abs(L1Cv)) + Math.Abs(WSCv / 2) * Math.Abs(WSCv / 2)) * Math.Cos(AngleW + Math.Atan2(-WSCv / 2, L1Cv));
            double y      = Global_Object.CoorCanvas(properties.pose.Position).Y + Math.Sqrt(Math.Abs(L1Cv) * Math.Abs(L1Cv) + Math.Abs(WSCv / 2) * Math.Abs(WSCv / 2)) * Math.Sin(AngleW + Math.Atan2(-WSCv / 2, L1Cv));

            return(new Point(x, y));
        }
Пример #10
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (!Global_Object.ServerAlive())
            {
                return;
            }
            try
            {
                dtPallet pallet = (sender as System.Windows.Controls.Button).DataContext as dtPallet;
                //if (pallet.palletStatus == "F")
                //{
                //    return;
                //}
                pallet.palletStatus = "W";
                string jsonData = JsonConvert.SerializeObject(pallet);

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://" + Properties.Settings.Default.serverIp + ":" + Properties.Settings.Default.serverPort + @"/robot/rest/" + "pallet/updatePalletStatus");
                request.Method      = "POST";
                request.ContentType = "application/json";

                System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                Byte[] byteArray = encoding.GetBytes(jsonData);
                request.ContentLength = byteArray.Length;
                using (Stream dataStream = request.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                    dataStream.Flush();
                }

                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                using (Stream responseStream = response.GetResponseStream())
                {
                    StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                    int          result = 0;
                    int.TryParse(reader.ReadToEnd(), out result);
                    if (result == 1)
                    {
                        //System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageSaveSucced), Global_Object.messageTitileInformation, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (result == -2)
                    {
                        // System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageDuplicated, "Pallets Name"), Global_Object.messageTitileError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        //System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageSaveFail), Global_Object.messageTitileError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                Dispatcher.BeginInvoke(new ThreadStart(() =>
                {
                    stationEditorModel.ReloadListPallets(this.stationShape.props.bufferDb.bufferId);
                }));
            }
            catch (Exception ex)
            {
                logFile.Error(ex.Message);
            }
        }
Пример #11
0
        private void DeletePlan_Click(object sender, RoutedEventArgs e)
        {
            if (!Global_Object.ServerAlive())
            {
                return;
            }
            try
            {
                List <Plan> listPlanDelete = new List <Plan>();
                Plan        plan           = (sender as System.Windows.Controls.Button).DataContext as Plan;
                listPlanDelete.Add(plan);
                string jsonData = JsonConvert.SerializeObject(listPlanDelete);

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://" + Properties.Settings.Default.serverIp + ":" + Properties.Settings.Default.serverPort + @"/robot/rest/" + "plan/deleteListPlan");
                request.Method      = "DELETE";
                request.ContentType = "application/json";

                System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                Byte[] byteArray = encoding.GetBytes(jsonData);
                request.ContentLength = byteArray.Length;
                using (Stream dataStream = request.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                    dataStream.Flush();
                }

                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                using (Stream responseStream = response.GetResponseStream())
                {
                    StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                    int          result = 0;
                    int.TryParse(reader.ReadToEnd(), out result);
                    if (result == 1)
                    {
                        if ((pCalendar.SelectedDate != null) && (TabControlShift.SelectedIndex >= 0) && (TabControlShift.IsLoaded))
                        {
                            //Dispatcher.BeginInvoke(new ThreadStart(() =>
                            //{
                            //    operation_model.CreateListPlansFromShift((DateTime)pCalendar.SelectedDate, TabControlShift.SelectedIndex + 1);
                            //}));
                        }
                    }
                    else if (result == 2)
                    {
                        System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageDeleteUse, "Devices", "Other Screen"), Global_Object.messageTitileWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageDeleteFail), Global_Object.messageTitileError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                logFile.Error(ex.Message);
            }
        }
        public bool FindHeaderIsCloseRiskAreaCv(Point p)
        {
            // return ExtensionService.CalDistance(TopHeader(),p)<properties.DistanceIntersection || ExtensionService.CalDistance(BottomHeader(), p) < properties.DistanceIntersection || ExtensionService.CalDistance(MiddleHeader(), p) < properties.DistanceIntersection ? true:false;
            //Console.WriteLine("Vi tri robot "+ this.properties.NameID+" = " + properties.pose.Position);
            // Console.WriteLine("Vi tien gan " + p.ToString());
            // Console.WriteLine("kHOAN CACH " + ExtensionService.CalDistance(properties.pose.Position, p));
            Point  pp  = Global_Object.CoorCanvas(properties.pose.Position);
            double ddd = ExtensionService.CalDistance(Global_Object.CoorCanvas(properties.pose.Position), p);

            return(ExtensionService.CalDistance(Global_Object.CoorCanvas(properties.pose.Position), p) < 40 ? true : false);
        }
Пример #13
0
 private void OnTimedWaitServerEvent(object sender, ElapsedEventArgs e)
 {
     Application.Current.Dispatcher.Invoke((Action) delegate
     {
         if (Global_Object.ServerAlive())
         {
             mainWindow.stationTimer.Enabled = true;
             serverTimer.Enabled             = false;
             Close();
         }
     });
 }
Пример #14
0
        public Point CoorPointAtBorder(Point pointOnBorder)
        {
            double xDiff = (pointOnBorder.X) - 0;
            double yDiff = (pointOnBorder.Y) - 0;
            double rad1  = (props._rotate * Math.PI) / 180;
            double rad2  = (Math.Atan2(yDiff, xDiff));
            double L     = Global_Object.LengthBetweenPoints(new Point(0, 0), pointOnBorder);
            double x1    = props._posision.X + ((L * Math.Cos(rad1 + rad2)));
            double y1    = props._posision.Y + ((L * Math.Sin(rad1 + rad2)));

            return(new Point(x1, y1));
        }
Пример #15
0
        public Point CoorPointAtBorder(Point pointOnBorder)
        {
            double xDiff = (pointOnBorder.X) - (props._start.X);
            double yDiff = (pointOnBorder.Y) - (props._start.Y);
            double rad1  = (props.rotate * Math.PI) / 180;
            double rad2  = (Math.Atan2(yDiff, xDiff));
            double L     = Global_Object.LengthBetweenPoints(props._start, pointOnBorder);
            double x1    = props._oriMousePos.X + ((L * Math.Cos(rad1 + rad2)));
            double y1    = props._oriMousePos.Y + ((L * Math.Sin(rad1 + rad2)));

            return(new Point(x1, y1));
        }
        private bool make_outpackage_scope(Class cls,IBlockCallBack cb)
        {
            ASBinCode.CodeBlock codeblock = player.swc.blocks[cls.outscopeblockid];

            HeapSlot[]    globaldata = player.genHeapFromCodeBlock(codeblock);
            Global_Object global     = Global_Object.formCodeBlock(codeblock,globaldata,player.swc.classes[0]);

            ASBinCode.rtData.rtObject globalObj = new ASBinCode.rtData.rtObject(global,null);

            ASBinCode.RunTimeScope rtscope = player.callBlock(
                codeblock,globaldata,null,
                null, //player.static_instance[cls.staticClass.classid].objScope,

                step.token,
                cb,
                globalObj,
                RunTimeScopeType.outpackagemember
                );

            if (rtscope == null)
            {
                invokerFrame.endStep(step);
                return(false);
            }

            globalObj.objScope = rtscope;
            player.outpackage_runtimescope.Add(cls.classid,rtscope);
            {
                var slot = new DynamicPropertySlot(globalObj,true,player.swc.FunctionClass.getRtType());
                slot.directSet(player.static_instance[cls.staticClass.classid]);
                global.createproperty(cls.name,slot);
            }
            for (int i = 0; i < player.swc.classes.Count; i++)
            {
                if (player.swc.classes[i].mainClass == cls)
                {
                    if (init_static_class(player.swc.classes[i]))
                    {
                        var slot = new DynamicPropertySlot(globalObj,true,player.swc.FunctionClass.getRtType());
                        slot.directSet(player.static_instance[player.swc.classes[i].staticClass.classid]);
                        global.createproperty(player.swc.classes[i].name,slot);
                    }
                    else
                    {
                        //***出错了
                        invokerFrame.endStep(step);
                        return(false);
                    }
                }
            }

            return(true);
        }
        //giua middle 1 va robot
        public virtual Point MiddleHeaderCv3()
        {
            double PRx = Global_Object.CoorCanvas(properties.pose.Position).X;
            double PRy = Global_Object.CoorCanvas(properties.pose.Position).Y;

            if (L1Cv != 0 && WSCv != 0)
            {
                return(new Point((MiddleHeaderCv1().X + PRx) / 2, (MiddleHeaderCv1().Y + PRy) / 2));
            }
            else
            {
                return(new Point(-1, -1));
            }
        }
        public bool FindHeaderInsideCircleArea(Point pheader, double r)
        {
            Point  ccPoint    = Global_Object.CoorCanvas(properties.pose.Position);
            double leftSideEq = (pheader.X - ccPoint.X) * (pheader.X - ccPoint.X) + (pheader.Y - ccPoint.Y) * (pheader.Y - ccPoint.Y);

            valueSC = Math.Sqrt(leftSideEq) + "";
            if (Math.Sqrt(leftSideEq) <= r)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #19
0
        public override void Draw()
        {
            Width        = Global_Object.LengthBetweenPoints(props._oriMousePos, props._desMousePos);
            props._end.X = Width;
            //Rotate param
            props.xDiff = props._desMousePos.X - props._oriMousePos.X;
            props.yDiff = props._desMousePos.Y - props._oriMousePos.Y;
            //Middle point of straight path
            props._middle.X = (props._start.X + props._end.X) / 2;
            props._middle.Y = (props._start.Y + props._end.Y) / 2;
            // Point at _start and _end
            props._pointHead.RenderTransform = new TranslateTransform(-(Width / 2), 0);
            props._pointTail.RenderTransform = new TranslateTransform((Width / 2), 0);
            //Arrow show direction
            //3 Point of Triangle
            props.arrowPoints[0] = (new Point(props._middle.X - props.sizeArrow, props._middle.Y - props.sizeArrow));
            props.arrowPoints[1] = (new Point(props._middle.X - props.sizeArrow, props._middle.Y + props.sizeArrow));
            props.arrowPoints[2] = (new Point(props._middle.X + props.sizeArrow + 1, props._middle.Y));
            props._arrow.Points  = props.arrowPoints;
            //Position the Path
            lineSegment.Point = props._end;
            if (props.pathSegments.Count > 0)
            {
                props.pathSegments[0] = lineSegment;
            }
            else
            {
                props.pathSegments.Add(lineSegment);
            }
            props.pathFigure.StartPoint = props._start;

            //Render Path
            double angle = (Math.Atan2(props.yDiff, props.xDiff) * 180.0 / Math.PI);

            props.rotate = angle;
            props.myRotateTransform.Angle      = props.rotate;
            props.myTranslate                  = new TranslateTransform(props._oriMousePos.X, props._oriMousePos.Y - (Height / 2));
            props.myTransformGroup.Children[1] = props.myTranslate;
            // SPECIAL POINTS
            props.cornerPoints[0] = CoorPointAtBorder(new Point((0), (Height / 2)));        //mid-left
            props.cornerPoints[1] = CoorPointAtBorder(new Point((0), (0)));                 //top-left
            props.cornerPoints[2] = CoorPointAtBorder(new Point((Width / 2), (0)));         //top-mid
            props.cornerPoints[3] = CoorPointAtBorder(new Point((Width), (0)));             //top-right
            props.cornerPoints[4] = CoorPointAtBorder(new Point((Width), (Height / 2)));    //mid-right
            props.cornerPoints[5] = CoorPointAtBorder(new Point((Width), (Height)));        //bot-right
            props.cornerPoints[6] = CoorPointAtBorder(new Point((Width / 2), (Height)));    //bot-mid
            props.cornerPoints[7] = CoorPointAtBorder(new Point((0), (Height)));            //bot-left
        }
Пример #20
0
        public List <Plan> CheckPlans(int timeWorkId, DateTime selectedDate)
        {
            if (!Global_Object.ServerAlive())
            {
                return(new List <Plan>());
            }
            try
            {
                List <Plan>    returnList = new List <Plan>();
                string         activeDate = selectedDate.Year + "-" + selectedDate.Month.ToString("00.") + "-" + selectedDate.Day.ToString("00.");
                HttpWebRequest request    = (HttpWebRequest)WebRequest.Create(@"http://" + Properties.Settings.Default.serverIp + ":" + Properties.Settings.Default.serverPort + @"/robot/rest/" + "plan/getPlanByShift");
                request.Method      = "POST";
                request.ContentType = @"application/json";
                dynamic postApiBody = new JObject();
                postApiBody.activeDate = activeDate;
                postApiBody.timeWorkId = timeWorkId;
                string jsonData = JsonConvert.SerializeObject(postApiBody);
                System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                Byte[] byteArray = encoding.GetBytes(jsonData);
                request.ContentLength = byteArray.Length;
                using (Stream dataStream = request.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                    dataStream.Flush();
                }
                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                using (Stream responseStream = response.GetResponseStream())
                {
                    StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                    string       result = reader.ReadToEnd();

                    dynamic listplan = JsonConvert.DeserializeObject(result);
                    foreach (dynamic item in listplan)
                    {
                        Plan tempPlan = new Plan(item);
                        AddPlan(tempPlan, returnList);
                    }
                    return(returnList);
                }
            }
            catch (Exception ex)
            {
                logFile.Error(ex.Message);
                return(null);
            }
        }
Пример #21
0
        private void Btn_deletePlanPallet_Click(object sender, RoutedEventArgs e)
        {
            if (System.Windows.Forms.MessageBox.Show
                (
                    String.Format(Global_Object.messageDeleteConfirm, "Plans"),
                    Global_Object.messageTitileWarning, MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes
                )
            {
                try
                {
                    List <dtTempPlan> listToDetele = new List <dtTempPlan>();
                    if (DataGridPlan.SelectedItems.Count > 0)
                    {
                        foreach (dtPlan plan in DataGridPlan.SelectedItems)
                        {
                            listToDetele.Add(new dtTempPlan(plan));
                        }
                        string  jsonData    = JsonConvert.SerializeObject(listToDetele);
                        string  contentJson = Global_Object.RequestDataAPI(jsonData, "plan/deleteListPlan", Global_Object.RequestMethod.DELETE);
                        dynamic response    = JsonConvert.DeserializeObject(contentJson);

                        if (response != null)
                        {
                            if (response == 1)
                            {
                                System.Windows.MessageBox.Show("Plans deleted successfully!");
                                model.ReloadListPlan((DateTime)dp_planManagement.SelectedDate);
                            }
                            else
                            {
                                System.Windows.MessageBox.Show("Cannot Delete!");
                            }
                        }
                    }
                    else
                    {
                        System.Windows.MessageBox.Show("Nothing to delete!");
                    }
                }
                catch (Exception ex)
                {
                    logFile.Error(ex.Message);
                }
            }
        }
        public void DisposeProcedure()
        {
            if (proRegistryInRobot.pBM != null)
            {
                proRegistryInRobot.pBM.Destroy();
                //proRegistryInRobot.pBM = null;
            }

            if (proRegistryInRobot.pMR != null)
            {
                Global_Object.onFlagRobotComingGateBusy = false;
                Global_Object.setGateStatus(proRegistryInRobot.pMR.order.gate, false);
                //Global_Object.onFlagDoorBusy = false;
                proRegistryInRobot.pMR.Destroy();
                // proRegistryInRobot.pMR = null;
            }
            if (proRegistryInRobot.pFB != null)
            {
                Global_Object.onFlagRobotComingGateBusy = false;
                //  Global_Object.onFlagDoorBusy = false;
                proRegistryInRobot.pFB.Destroy();
                // proRegistryInRobot.pFB = null;
            }
            if (proRegistryInRobot.pFM != null)
            {
                Global_Object.onFlagRobotComingGateBusy = false;
                proRegistryInRobot.pFM.Destroy();
                // proRegistryInRobot.pFB = null;
            }
            if (proRegistryInRobot.pBR != null)
            {
                Global_Object.onFlagRobotComingGateBusy = false;
                proRegistryInRobot.pBR.Destroy();
                // proRegistryInRobot.pBR = null;
            }
            if (proRegistryInRobot.pRC != null)
            {
                proRegistryInRobot.pRC.Destroy();
                // proRegistryInRobot.pRC = null;
            }
            if (proRegistryInRobot.pRR != null)
            {
                proRegistryInRobot.pRR.Destroy();
                // proRegistryInRobot.pRR = null;
            }
        }
Пример #23
0
        public bool CheckInBuffer(bool turnon)
        {
            bool onstop = false;

            if (turnon)
            {
                if (RobotUnitylist.Count > 0)
                {
                    foreach (RobotUnity r in RobotUnitylist)
                    {
                        String lableR = r.properties.Label;
                        if (r.robotTag == RobotStatus.WORKING)
                        {
                            Point thCV  = TopHeaderCv();
                            Point mdCV0 = MiddleHeaderCv();
                            Point mdCV1 = MiddleHeaderCv1();
                            Point mdCV2 = MiddleHeaderCv2();
                            Point mdCV3 = MiddleHeaderCv3();
                            Point bhCV  = BottomHeaderCv();
                            Point Rp    = Global_Object.CoorCanvas(this.properties.pose.Position);
                            // bool onTouch= FindHeaderIntersectsFullRiskArea(this.TopHeader()) | FindHeaderIntersectsFullRiskArea(this.MiddleHeader()) | FindHeaderIntersectsFullRiskArea(this.BottomHeader());
                            // bool onTouch = r.FindHeaderIntersectsFullRiskAreaCv(thCV) | r.FindHeaderIntersectsFullRiskAreaCv(mdCV) | r.FindHeaderIntersectsFullRiskAreaCv(bhCV);
                            bool onTouchR = r.FindHeaderInsideCircleArea(Rp, r.Radius_S);
                            bool onTouch0 = r.FindHeaderInsideCircleArea(mdCV0, r.Radius_S);
                            bool onTouch1 = r.FindHeaderInsideCircleArea(mdCV1, r.Radius_S);
                            bool onTouch2 = r.FindHeaderInsideCircleArea(mdCV2, r.Radius_S);
                            bool onTouch3 = r.FindHeaderInsideCircleArea(mdCV3, r.Radius_S);

                            if (onTouch1)
                            {
                                //  robotLogOut.ShowTextTraffic(r.properties.Label+" => CheckIntersection");
                                if (r.onFlagSafeSmallcircle || r.onFlagSafeYellowcircle || r.onFlagSafeOrgancircle)
                                {
                                    STATE_SPEED = "CHECKINT_BUFFER_SECTION_STOP " + r.properties.Label;
                                    SetSpeedTraffic(RobotSpeedLevel.ROBOT_SPEED_STOP, true);
                                    delay(2000);
                                    onstop = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            return(onstop);
        }
Пример #24
0
        public int CheckSafeDistance() // KIểm tra khoản cách an toàn/ nếu đang trong vùng close với robot khác thì giảm tốc độ, chuyển sang chế độ dò risk area
        {
            int iscloseDistance = 0;

            foreach (RobotUnity r in RobotUnitylist)
            {
                if (r.onFlagSupervisorTraffic)
                {
                    Point rP = MiddleHeaderCv();
                    // bool onFound = r.FindHeaderIsCloseRiskArea(this.properties.pose.Position);
                    bool onFound = r.FindHeaderIsCloseRiskAreaCv(rP);

                    if (onFound)
                    {
                        // if robot in list is near but add in risk list robot
                        //     robotLogOut.ShowTextTraffic(r.properties.Label + "- Intersection");

                        if (!RobotUnityRiskList.ContainsKey(r.properties.NameId))
                        {
                            RobotUnityRiskList.Add(r.properties.NameId, r);
                        }
                        // reduce speed robot control
                        iscloseDistance = 2;
                    }
                    else
                    {
                        // if robot in list is far but before registe in list, must remove in list
                        RemoveRiskList(r.properties.NameId);
                        double rd = ExtensionService.CalDistance(Global_Object.CoorCanvas(this.properties.pose.Position), Global_Object.CoorCanvas(r.properties.pose.Position));
                        if (rd < DistanceToSetSlowDown && rd > 60)
                        {
                            iscloseDistance = 1;
                        }
                        else
                        {
                            iscloseDistance = 0;
                        }
                    }
                }
            }
            return(iscloseDistance);
        }
        private void Btn_login_Click(object sender, RoutedEventArgs e)
        {
            //this.DialogResult = true;
            //this.Close();
            if (string.IsNullOrEmpty(this.tb_userName.Text) || this.tb_userName.Text.Trim() == "")
            {
                System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageValidate, "User Name", "User Name"), Global_Object.messageTitileWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.tb_userName.Focus();
                return;
            }

            if (string.IsNullOrEmpty(this.tb_password.Password) || this.tb_password.Password.Trim() == "")
            {
                System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageValidate, "Password", "Password"), Global_Object.messageTitileWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.tb_password.Focus();
                return;
            }
            try
            {
                dtUser user = new dtUser();
                user.userName     = this.tb_userName.Text;
                user.userPassword = this.tb_password.Password;
                string  jsonData    = JsonConvert.SerializeObject(user);
                string  contentJson = Global_Object.RequestDataAPI(jsonData, "user/getUserInfo", Global_Object.RequestMethod.POST);
                dynamic response    = JsonConvert.DeserializeObject(contentJson);
                user = response.ToObject <dtUser>();
                if (user.userAuthor == 0 || user.userAuthor == 1)
                {
                    this.DialogResult = true;
                    this.Close();
                }
                else
                {
                    lb_warning.Content = "Please try again";
                }
            }
            catch
            {
                lb_warning.Content = "Wrong User Name or Password";
            }
        }
Пример #26
0
 private void Btn_CreatePlanPallet_Click(object sender, RoutedEventArgs e)
 {
     if (!Global_Object.ServerAlive())
     {
         return;
     }
     try
     {
         DateTime       selectedDate = (DateTime)pCalendar.SelectedDate;
         string         activeDate   = selectedDate.Year + "-" + selectedDate.Month.ToString("00.") + "-" + selectedDate.Day.ToString("00.");
         HttpWebRequest request      = (HttpWebRequest)WebRequest.Create(@"http://" + Properties.Settings.Default.serverIp + ":" + Properties.Settings.Default.serverPort + @"/robot/rest/" + "plan/createPlanPallet");
         request.Method      = "POST";
         request.ContentType = @"application/json";
         dynamic postApiBody = new JObject();
         postApiBody.activeDate = activeDate;
         postApiBody.timeWorkId = TabControlShift.SelectedIndex + 1;
         postApiBody.updUsrId   = Global_Object.userLogin;
         string jsonData = JsonConvert.SerializeObject(postApiBody);
         System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
         Byte[] byteArray = encoding.GetBytes(jsonData);
         request.ContentLength = byteArray.Length;
         using (Stream dataStream = request.GetRequestStream())
         {
             dataStream.Write(byteArray, 0, byteArray.Length);
             dataStream.Flush();
         }
         HttpWebResponse response = request.GetResponse() as HttpWebResponse;
         using (Stream responseStream = response.GetResponseStream())
         {
             StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
             string       result = reader.ReadToEnd();
         }
     }
     catch (Exception ex)
     {
         logFile.Error(ex.Message);
     }
 }
Пример #27
0
        public bool CheckYellowCircle() // khi robot bặt vòng tròn vàng. tất cả robot khác ngưng nếu dò ra có robot nào trong vùng vòng tròn này
        {
            bool onstop = false;

            foreach (RobotUnity r in RobotUnitylist)
            {
                // kiểm tra có robot chinh  nó có nằm trong vòng tròn vàng nào không nếu có ngưng
                if (r.onFlagSafeYellowcircle)
                {
                    Point cY  = r.CenterOnLineCv(Center_R); // TRONG TAM ROBOT KHAC
                    Point rP  = Global_Object.CoorCanvas(properties.pose.Position);
                    Point md  = MiddleHeaderCv();
                    Point md1 = MiddleHeaderCv1();
                    Point md2 = MiddleHeaderCv2();
                    Point md3 = MiddleHeaderCv3();
                    if (r.FindHeaderInsideCircleArea(MiddleHeaderCv(), cY, r.Radius_R) ||
                        r.FindHeaderInsideCircleArea(rP, cY, r.Radius_R) ||
                        r.FindHeaderInsideCircleArea(md1, cY, r.Radius_R)
                        )
                    {
                        STATE_SPEED = "YELLOWC_STOP";
                        SetSpeedTraffic(RobotSpeedLevel.ROBOT_SPEED_STOP, true);
                        delay(2000);
                        onstop = true;
                        break;
                    }

                    /*   else
                     * {
                     *     STATE_SPEED = "YELLOWC_NO_NORMAL";
                     *     SetSpeed(RobotSpeedLevel.ROBOT_SPEED_NORMAL,false);
                     * }*/
                }
            }
            return(onstop);
        }
Пример #28
0
        private void Map_MouseMove(object sender, MouseEventArgs e)
        {
            //Get mouse props
            Point mousePos       = e.GetPosition(map);
            var   mouseWasDownOn = (e.Source as FrameworkElement);

            hoveringItemName = mouseWasDownOn.Name;
            //mainWindow.MouseCoor.Content = (mousePos.X- Global_Object.OriginPoint.X).ToString("0.0") + " " + (Global_Object.OriginPoint.Y - mousePos.Y ).ToString("0.0");
            mainWindow.MouseCoor.Content  = (Global_Object.CoorLaser(mousePos).X).ToString("0.00") + " " + (Global_Object.CoorLaser(mousePos).Y).ToString("0.00");
            mainWindow.MouseCoor2.Content = ((mousePos).X).ToString("0.00") + " " + ((mousePos).Y).ToString("0.00");
            //mainWindow.MouseCoor.Content = ((mousePos).X.ToString("0.0") + " " + (mousePos).Y.ToString("0.0"));

            //Console.WriteLine("============================================");
            //Console.WriteLine("MousePos:  (" + mousePos.X + "," + mousePos.Y + ")");
            //Console.WriteLine("CoorLaser:  (" + Global_Object.CoorLaser(mousePos).X.ToString("0.0") + "," + Global_Object.CoorLaser(mousePos).Y.ToString("0.0")+")");
            //Console.WriteLine("CoorCanvas:  ("+ Global_Object.CoorCanvas(Global_Object.CoorLaser(mousePos)).X.ToString("0.0") + "," + Global_Object.CoorCanvas(Global_Object.CoorLaser(mousePos)).Y.ToString("0.0") + ")");
            ////
            // POINT OF VIEW
            //
            if ((mainWindow.drag))
            {
                if (!map.IsMouseCaptured)
                {
                    return;
                }
                Vector moveVector = startPoint - e.GetPosition(mainWindow.clipBorder);
                double xCoor      = originalPoint.X - moveVector.X;
                double yCoor      = originalPoint.Y - moveVector.Y;

                double MapWidthScaled   = (map.Width * scaleTransform.ScaleX);
                double MapHeightScaled  = (map.Height * scaleTransform.ScaleY);
                double ClipBorderWidth  = (mainWindow.clipBorder.ActualWidth);
                double ClipBorderHeight = (mainWindow.clipBorder.ActualHeight);

                double xlim;
                double ylim;
                if (ClipBorderWidth < map.Width)
                {
                    xlim = (map.Width * (scaleTransform.ScaleX - 1)) / 2;
                }
                else
                {
                    xlim = Math.Abs((MapWidthScaled - ClipBorderWidth) / 2);
                }

                if (ClipBorderHeight < map.Height)
                {
                    ylim = (map.Height * (scaleTransform.ScaleY - 1)) / 2;
                }
                else
                {
                    ylim = Math.Abs((MapHeightScaled - ClipBorderHeight) / 2);
                }

                if (ClipBorderWidth > map.Width)
                {
                    if ((xCoor >= (-xlim)) && (xCoor <= (xlim)))
                    {
                        translateTransform.X = xCoor;
                    }
                }
                else
                {
                    if (ClipBorderWidth < MapWidthScaled)
                    {
                        if ((xCoor <= (xlim)) && (xCoor >= -(MapWidthScaled - ClipBorderWidth - xlim)))
                        {
                            translateTransform.X = xCoor;
                        }
                    }
                    else
                    {
                        if ((xCoor >= (xlim)) && (xCoor <= -(MapWidthScaled - ClipBorderWidth - xlim)))
                        {
                            translateTransform.X = xCoor;
                        }
                    }
                }
                if (ClipBorderHeight > map.Height)
                {
                    if ((yCoor >= (-ylim)) && (yCoor <= (ylim)))
                    {
                        translateTransform.Y = yCoor;
                    }
                }
                else
                {
                    if (ClipBorderHeight < MapHeightScaled)
                    {
                        if ((yCoor <= (ylim)) && (yCoor >= -(MapHeightScaled - ClipBorderHeight - ylim)))
                        {
                            translateTransform.Y = yCoor;
                        }
                    }
                    else
                    {
                        if ((yCoor >= (ylim)) && (yCoor <= -(MapHeightScaled - ClipBorderHeight - ylim)))
                        {
                            translateTransform.Y = yCoor;
                        }
                    }
                }
            }
            if (!mainWindow.drag)
            {
                Statectrl_MouseMove(e);
            }
        }
        public StatusOrderResponse ParseData(String dataReq)
        {
            StatusOrderResponse statusOrderResponse = null;

            try
            {
                JObject results = JObject.Parse(dataReq);
                int     typeReq = (int)results["typeReq"];
                #region TYPEREQUEST_FORLIFT_TO_BUFFER
                if (typeReq == (int)TyeRequest.TYPEREQUEST_FORLIFT_TO_BUFFER)
                {
                    int gate = (int)results["gate"];
                    if (Global_Object.getGateStatus(gate))
                    {
                        statusOrderResponse = new StatusOrderResponse()
                        {
                            status = (int)StatusOrderResponseCode.ORDER_STATUS_DOOR_BUSY, content = ""
                        };
                        return(statusOrderResponse);
                    }
                    OrderItem order = new OrderItem();
                    order.typeReq           = (TyeRequest)typeReq;
                    order.userName          = (String)results["userName"];
                    order.productDetailId   = (int)results["productDetailId"];
                    order.productDetailName = (String)results["productDetailName"];
                    order.productId         = (int)results["productId"];
                    order.planId            = (int)results["planId"];
                    order.deviceId          = (int)results["deviceId"];
                    order.timeWorkId        = (int)results["timeWorkId"];
                    order.activeDate        = (string)results["activeDate"];

                    order.gate = (int)results["gate"];
                    // order.palletStatus = (String)results["palletStatus"];
                    dynamic product = new JObject();
                    product.timeWorkId      = order.timeWorkId;
                    product.activeDate      = order.activeDate;
                    product.productId       = order.productId;
                    product.productDetailId = order.productDetailId;

                    // chu y sua
                    product.palletStatus = PalletStatus.P.ToString();
                    order.dataRequest    = product.ToString();
                    order.status         = StatusOrderResponseCode.PENDING;
                    order.dateTime       = (string)DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss tt");

                    int palletId_P = Convert.ToInt32(CreatePlanBuffer(order));

                    if (palletId_P > 0)
                    {
                        /*if (GetFrontLineBuffer(order, true) == null)
                         * {
                         *  statusOrderResponse = new StatusOrderResponse() { status = (int)StatusOrderResponseCode.ORDER_STATUS_RESPONSE_NOACCEPTED, content = "Loai Ma Code trong Buffer" };
                         *  return statusOrderResponse;
                         * }*/
                        //  Global_Object.onFlagDoorBusy = true;
                        Global_Object.setGateStatus(gate, true);
                        order.palletId_P = palletId_P;
                        PendingOrderList.Add(order);
                        OrderedItemList.Add(order);
                        Global_Object.cntForkLiftToBuffer++;
                    }
                    else
                    {
                        statusOrderResponse = new StatusOrderResponse()
                        {
                            status = (int)StatusOrderResponseCode.ORDER_STATUS_RESPONSE_NOACCEPTED, content = "Buffer Đầy ,Vui Lòng Kiểm Tra Lai !"
                        };
                        return(statusOrderResponse);
                    }
                    try
                    {
                        if (gate == (int)DoorId.DOOR_MEZZAMINE_UP)
                        {
                            Global_Object.doorManagementServiceCtrl.DoorMezzamineUp.LampSetStateOn(DoorType.DOOR_FRONT);
                        }
                        if (gate == (int)DoorId.DOOR_MEZZAMINE_UP_NEW)
                        {
                            Global_Object.doorManagementServiceCtrl.DoorMezzamineUpNew.LampSetStateOn(DoorType.DOOR_FRONT);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("control lamp failed" + e);
                    }
                }
                #endregion
                #region TYPEREQUEST_FORLIFT_TO_MACHINE
                if (typeReq == (int)TyeRequest.TYPEREQUEST_FORLIFT_TO_MACHINE)
                {
                    int gate = (int)results["gate"];
                    if (Global_Object.getGateStatus(gate))
                    {
                        statusOrderResponse = new StatusOrderResponse()
                        {
                            status = (int)StatusOrderResponseCode.ORDER_STATUS_DOOR_BUSY, content = ""
                        };
                        return(statusOrderResponse);
                    }
                    Global_Object.setGateStatus(gate, true);
                    //Global_Object.onFlagDoorBusy = true;
                    OrderItem order = new OrderItem();
                    order.typeReq           = (TyeRequest)typeReq;
                    order.userName          = (String)results["userName"];
                    order.productDetailId   = (int)results["productDetailId"];
                    order.productDetailName = (String)results["productDetailName"];
                    order.productId         = (int)results["productId"];
                    order.planId            = (int)results["planId"];
                    order.deviceId          = (int)results["deviceId"];
                    order.timeWorkId        = (int)results["timeWorkId"];
                    order.activeDate        = (string)results["activeDate"];
                    order.gate = (int)results["gate"];
                    // order.palletStatus = (String)results["palletStatus"];
                    dynamic product = new JObject();
                    product.timeWorkId      = order.timeWorkId;
                    product.activeDate      = order.activeDate;
                    product.productId       = order.productId;
                    product.productDetailId = order.productDetailId;

                    // chu y sua
                    product.palletStatus = PalletStatus.P.ToString();
                    order.dataRequest    = product.ToString();
                    order.status         = StatusOrderResponseCode.PENDING;
                    order.dateTime       = (string)DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss tt");
                    DataPallet datapallet = GetLineMachineInfo(order.deviceId);
                    if (datapallet != null)
                    {
                        order.palletAtMachine = datapallet;
                        PendingOrderList.Add(order);
                        OrderedItemList.Add(order);
                    }
                    else
                    {
                        statusOrderResponse = new StatusOrderResponse()
                        {
                            status = (int)StatusOrderResponseCode.ORDER_STATUS_RESPONSE_NOACCEPTED, content = ""
                        };
                        return(statusOrderResponse);
                    }
                    try
                    {
                        if (gate == (int)DoorId.DOOR_MEZZAMINE_UP)
                        {
                            Global_Object.doorManagementServiceCtrl.DoorMezzamineUp.LampSetStateOn(DoorType.DOOR_FRONT);
                        }
                        if (gate == (int)DoorId.DOOR_MEZZAMINE_UP_NEW)
                        {
                            Global_Object.doorManagementServiceCtrl.DoorMezzamineUpNew.LampSetStateOn(DoorType.DOOR_FRONT);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("control lamp failed");
                    }
                }
                #endregion
                #region TYPEREQUEST_BUFFER_TO_MACHINE
                else if (typeReq == (int)TyeRequest.TYPEREQUEST_BUFFER_TO_MACHINE)
                {
                    Console.WriteLine(dataReq);
                    Console.WriteLine("-----------------------------");
                    int len = (int)results["length"];
                    int palletAmountInBuffer = (int)results["palletAmount"];
                    int productDetailId      = (int)results["productDetailId"];
                    int cntOrderReg          = 0;
                    int orderAmount          = 0;
                    foreach (OrderItem ord in PendingOrderList)
                    {
                        if (productDetailId == ord.productDetailId)
                        {
                            if (ord.status == StatusOrderResponseCode.PENDING)
                            {
                                cntOrderReg++;
                            }
                        }
                    }
                    if (cntOrderReg == 0)                // chưa có order với productdetailID nào uoc đăng ký. thêm vào đúng số lượng trong orderlist
                    {
                        if (len <= palletAmountInBuffer) // nếu số lượn yêu cầu nhỏ hơn bằng số pallet có trong buffer add vào orderlist
                        {
                            orderAmount = len;
                        }
                    }
                    else if (cntOrderReg >= palletAmountInBuffer) // số lượng yêu cầu trước đó bằng hoặc hơn số lượng yêu cầu hiện tại. không duoc phép đưa vào thêm
                    {
                        statusOrderResponse = new StatusOrderResponse()
                        {
                            status = (int)StatusOrderResponseCode.ORDER_STATUS_RESPONSE_NOACCEPTED, content = ""
                        };
                        return(statusOrderResponse);
                    }
                    else if (cntOrderReg < palletAmountInBuffer)                 // số lượng yêu cầu hiện tại nhỏ hơn thì phải tính lại số lượng để bổ sung vào thêm
                    {
                        int availableOrder = palletAmountInBuffer - cntOrderReg; // tính số lượng pallet có thể
                        int willOrder      = availableOrder - len;               // số lượng pallet sẽ duoc add thêm vào orederlist
                        if (willOrder >= 0)
                        {
                            orderAmount = len;
                        }
                        else
                        {
                            orderAmount = len - availableOrder;
                        }
                    }
                    for (int i = 0; i < orderAmount; i++)
                    {
                        OrderItem order = new OrderItem();
                        order.typeReq           = (TyeRequest)typeReq;
                        order.userName          = (String)results["userName"];
                        order.productDetailId   = (int)results["productDetailId"];
                        order.productDetailName = (String)results["productDetailName"];
                        order.productId         = (int)results["productId"];
                        // order.planId = (int)results["planId"];
                        order.deviceId   = (int)results["deviceId"];
                        order.timeWorkId = 1;
                        // order.activeDate = (string)DateTime.Now.ToString("yyyy-MM-dd");
                        // order.palletStatus = (String)results["palletStatus"];
                        String  jsonDPst    = (string)results["datapallet"][i];
                        JObject stuffPallet = JObject.Parse(jsonDPst);
                        double  xx          = (double)stuffPallet["line"]["x"];
                        double  yy          = (double)stuffPallet["line"]["y"];
                        double  angle       = (double)stuffPallet["line"]["angle"];
                        int     row         = (int)stuffPallet["pallet"]["row"];
                        int     bay         = (int)stuffPallet["pallet"]["bay"];
                        int     directMain  = (int)stuffPallet["pallet"]["dir_main"];
                        int     directSub   = (int)stuffPallet["pallet"]["dir_sub"];
                        int     directOut   = (int)stuffPallet["pallet"]["dir_out"];
                        int     line_ord    = (int)stuffPallet["pallet"]["line_ord"];
                        order.palletAtMachine = new DataPallet()
                        {
                            linePos = new Pose(xx, yy, angle), row = row, bay = bay, directMain = directMain, directSub = directSub, directOut = directOut, line_ord = line_ord
                        };
                        dynamic product = new JObject();
                        product.timeWorkId = order.timeWorkId;
                        //product.activeDate = "";
                        order.dateTime          = (string)DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss tt");
                        product.productId       = order.productId;
                        product.productDetailId = order.productDetailId;
                        // chu y sua
                        product.palletStatus = PalletStatus.W.ToString(); // W
                        order.dataRequest    = product.ToString();

                        order.status = StatusOrderResponseCode.PENDING;
                        PendingOrderList.Add(order);
                        OrderedItemList.Add(order);
                        Global_Object.cntBufferToMachine++;
                    }
                }
                #endregion
                #region TYPEREQUEST_MACHINE_TO_RETURN
                else if (typeReq == (int)TyeRequest.TYPEREQUEST_PALLET_EMPTY_MACHINE_TO_RETURN)
                {
                    int len = (int)results["length"];

                    for (int i = 0; i < len; i++)
                    {
                        OrderItem order = new OrderItem();
                        order.typeReq    = (TyeRequest)typeReq;
                        order.userName   = (String)results["userName"];
                        order.activeDate = (string)results["activeDate"];
                        order.deviceId   = (int)results["deviceId"];
                        //order.palletStatus = (String)results["palletStatus"];
                        String  jsonDPst    = (string)results["datapallet"][i];
                        JObject stuffPallet = JObject.Parse(jsonDPst);
                        double  xx          = (double)stuffPallet["line"]["x"];
                        double  yy          = (double)stuffPallet["line"]["y"];
                        double  angle       = (double)stuffPallet["line"]["angle"];
                        int     row         = (int)stuffPallet["pallet"]["row"];
                        int     bay         = (int)stuffPallet["pallet"]["bay"];
                        int     directMain  = (int)stuffPallet["pallet"]["dir_main"];
                        int     directSub   = (int)stuffPallet["pallet"]["dir_sub"];
                        int     dir_out     = (int)stuffPallet["pallet"]["dir_out"];
                        int     line_ord    = (int)stuffPallet["pallet"]["line_ord"];
                        order.dateTime        = (string)DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss tt");
                        order.palletAtMachine = new DataPallet()
                        {
                            linePos = new Pose(xx, yy, angle), row = row, bay = bay, directMain = directMain, directSub = directSub, directOut = dir_out, line_ord = line_ord
                        };
                        dynamic product = new JObject();
                        product.palletStatus = PalletStatus.F.ToString();
                        order.dataRequest    = product.ToString();
                        order.status         = StatusOrderResponseCode.PENDING;
                        PendingOrderList.Add(order);
                        OrderedItemList.Add(order);
                    }
                }
                #endregion
                #region TYPEREQUEST_BUFFER_TO_GATE
                else if (typeReq == (int)TyeRequest.TYPEREQUEST_WMS_RETURN_PALLET_BUFFER_TO_GATE)
                {
                    OrderItem order = new OrderItem();
                    order.gate            = (int)DoorId.DOOR_MEZZAMINE_RETURN;
                    order.typeReq         = (TyeRequest)typeReq;
                    order.userName        = (String)results["userName"];
                    order.deviceId        = (int)results["deviceId"];
                    order.productDetailId = (int)results["productDetailId"];
                    order.productId       = (int)results["productId"];
                    order.timeWorkId      = 1;
                    order.activeDate      = (string)results["activeDate"];
                    order.planId          = (int)results["planId"];
                    order.palletId        = (int)results["palletId"];
                    //order.activeDate = (string)results["activeDate"];
                    // order.palletStatus = (String)results["palletStatus"];
                    dynamic product = new JObject();
                    product.timeWorkId      = order.timeWorkId;
                    product.activeDate      = order.activeDate;
                    product.productId       = order.productId;
                    product.productDetailId = order.productDetailId;
                    order.dateTime          = (string)DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss tt");
                    // chu y sua
                    product.palletStatus = PalletStatus.W.ToString();
                    order.dataRequest    = product.ToString();
                    order.status         = StatusOrderResponseCode.PENDING;
                    if (UpdatePalletStatusReturnBufferToGate(order))
                    {
                        PendingOrderList.Add(order);
                        OrderedItemList.Add(order);
                    }
                    else
                    {
                        statusOrderResponse = new StatusOrderResponse()
                        {
                            status = (int)StatusOrderResponseCode.ORDER_STATUS_RESPONSE_NOACCEPTED, content = ""
                        };
                        return(statusOrderResponse);
                    }
                }
                #endregion
                #region TYPEREQUEST_WMS_RETURN_PALLET_BUFFERRETURN
                else if (typeReq == (int)TyeRequest.TYPEREQUEST_MACHINE_TO_BUFFERRETURN)
                {
                    int len = (int)results["length"];
                    for (int i = 0; i < len; i++)
                    {
                        // tạo plan vùng buffer return
                        OrderItem order = new OrderItem();
                        order.typeReq           = (TyeRequest)typeReq;
                        order.userName          = (String)results["userName"];
                        order.productDetailId   = (int)results["productDetailId"];
                        order.productDetailName = (String)results["productDetailName"];
                        order.activeDate        = (string)results["activeDate"];
                        order.productId         = (int)results["productId"];
                        // order.planId = (int)results["planId"];
                        int deviceId = getDeviceId("RETURN_MAIN 0");
                        if (deviceId < 0)
                        {
                            statusOrderResponse = new StatusOrderResponse()
                            {
                                status = (int)StatusOrderResponseCode.ORDER_STATUS_RESPONSE_NOACCEPTED, content = ""
                            };
                            return(statusOrderResponse);
                        }
                        order.deviceId   = deviceId; // Buffer Return
                        order.timeWorkId = 1;
                        String  jsonDPst    = (string)results["datapallet"][i];
                        JObject stuffPallet = JObject.Parse(jsonDPst);
                        double  xx          = (double)stuffPallet["line"]["x"];
                        double  yy          = (double)stuffPallet["line"]["y"];
                        double  angle       = (double)stuffPallet["line"]["angle"];
                        int     row         = (int)stuffPallet["pallet"]["row"];
                        int     bay         = (int)stuffPallet["pallet"]["bay"];
                        int     directMain  = (int)stuffPallet["pallet"]["dir_main"];
                        int     directSub   = (int)stuffPallet["pallet"]["dir_sub"];
                        int     dir_out     = (int)stuffPallet["pallet"]["dir_out"];
                        int     line_ord    = (int)stuffPallet["pallet"]["line_ord"];
                        order.dateTime        = (string)DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss tt");
                        order.palletAtMachine = new DataPallet()
                        {
                            linePos = new Pose(xx, yy, angle), row = row, bay = bay, directMain = directMain, directSub = directSub, directOut = dir_out, line_ord = line_ord
                        };
                        dynamic product = new JObject();
                        product.timeWorkId      = order.timeWorkId;
                        product.activeDate      = order.activeDate;
                        order.dateTime          = (string)DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss tt");
                        product.productId       = order.productId;
                        product.productDetailId = order.productDetailId;
                        // chu y sua
                        product.palletStatus = PalletStatus.P.ToString();
                        order.dataRequest    = product.ToString();
                        order.status         = StatusOrderResponseCode.PENDING;
                        int palletId_P = Convert.ToInt32(CreatePlanBuffer(order));
                        if (palletId_P > 0)
                        {
                            order.palletId_P = palletId_P;
                            PendingOrderList.Add(order);
                            OrderedItemList.Add(order);
                        }
                        else
                        {
                            statusOrderResponse = new StatusOrderResponse()
                            {
                                status = (int)StatusOrderResponseCode.ORDER_STATUS_RESPONSE_NOACCEPTED, content = ""
                            };
                            return(statusOrderResponse);
                        }
                    }
                }
                #endregion
                #region TYPEREQUEST_WMS_RETURN_PALLET_BUFFERRETURN_TO_BUFFER401
                else if (typeReq == (int)TyeRequest.TYPEREQUEST_WMS_RETURN_PALLET_BUFFERRETURN_TO_BUFFER401)
                {
                    OrderItem order = new OrderItem();
                    order.typeReq           = (TyeRequest)typeReq;
                    order.userName          = (String)results["userName"];
                    order.productDetailId   = (int)results["productDetailId"];
                    order.productDetailName = (String)results["productDetailName"];
                    order.productId         = (int)results["productId"];
                    order.planId            = (int)results["planId"];
                    order.deviceId          = (int)results["deviceId"];
                    order.bufferId          = (int)results["bufferId"];
                    order.deviceIdPut       = (int)results["deviceIdPut"];
                    order.bufferIdPut       = (int)results["bufferIdPut"];
                    order.timeWorkId        = 1;
                    order.activeDate        = (string)results["activeDate"];
                    order.palletId          = (int)results["palletId"];
                    // order.activeDate = (string)DateTime.Now.ToString("yyyy-MM-dd");
                    // order.palletStatus = (String)results["palletStatus"];
                    order.status = StatusOrderResponseCode.PENDING;

                    PlanDataRequest planDataRequest_B401 = new PlanDataRequest();
                    planDataRequest_B401.activeDate      = order.activeDate;
                    planDataRequest_B401.deviceId        = order.deviceIdPut;
                    planDataRequest_B401.productDetailId = order.productDetailId;
                    planDataRequest_B401.productId       = order.productId;


                    UpdatePalletRequest updatePalletRequest_BufferReturn = new UpdatePalletRequest();
                    updatePalletRequest_BufferReturn.planId       = order.planId;
                    updatePalletRequest_BufferReturn.palletStatus = "H";
                    updatePalletRequest_BufferReturn.palletId     = order.palletId;

                    bool onUpdateBR = UpdatePalletStatusToHoldBufferReturn_BRB401(updatePalletRequest_BufferReturn);
                    int  palletId_P = CreatePlanBuffer401(planDataRequest_B401);

                    dynamic product_B401 = new JObject();
                    product_B401.timeWorkId      = order.timeWorkId;
                    product_B401.activeDate      = order.activeDate;
                    order.dateTime               = (string)DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss tt");
                    product_B401.productId       = order.productId;
                    product_B401.productDetailId = order.productDetailId;
                    // chu y sua
                    product_B401.palletStatus   = PalletStatus.P.ToString();
                    order.dataRequest_Buffer401 = product_B401.ToString();

                    dynamic product_BR = new JObject();
                    product_BR.timeWorkId      = order.timeWorkId;
                    product_BR.activeDate      = order.activeDate;
                    order.dateTime             = (string)DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss tt");
                    product_BR.productId       = order.productId;
                    product_BR.productDetailId = order.productDetailId;
                    // chu y sua
                    product_BR.palletStatus        = PalletStatus.H.ToString();
                    order.dataRequest_BufferReturn = product_BR.ToString();

                    if (onUpdateBR && palletId_P > 0)
                    {
                        order.palletId_P = palletId_P;
                        PendingOrderList.Add(order);
                        OrderedItemList.Add(order);
                    }
                    else
                    {
                        FreePlanedBuffer(order.dataRequest_Buffer401, order.planId);
                        updatePalletRequest_BufferReturn.palletStatus = "W";
                        UpdatePalletState(updatePalletRequest_BufferReturn);
                    }
                }
                #endregion
                #region TYPEREQUEST_CLEAR
                else if (typeReq == (int)TyeRequest.TYPEREQUEST_CLEAR)
                {
                    String userName = (String)results["userName"];
                    // kiểm tra quy trình và hủy task

                    foreach (OrderItem ord in PendingOrderList)
                    {
                        if (ord.userName.Equals(userName))
                        {
                            PendingOrderList.Remove(ord);
                        }
                    }
                    foreach (OrderItem ord in OrderedItemList)
                    {
                        if (ord.userName.Equals(userName))
                        {
                            if (ord.status == StatusOrderResponseCode.PENDING)
                            {
                                ord.status = StatusOrderResponseCode.DESTROYED;
                            }
                        }
                    }
                }
                #endregion
                #region TYPEREQUEST_OPEN_FRONTDOOR_DELIVERY_PALLET_GATE_1
                else if (typeReq == (int)TyeRequest.TYPEREQUEST_OPEN_FRONTDOOR_DELIVERY_PALLET_GATE_1)
                {
                    // same deviceID forklift
                    try
                    {
                        Global_Object.doorManagementServiceCtrl.DoorMezzamineUpNew.OpenPress(DoorType.DOOR_FRONT);

                        /* if (false == Global_Object.doorManagementServiceCtrl.DoorMezzamineUpNew.getDoorBusy()) {
                         *   Global_Object.doorManagementServiceCtrl.DoorMezzamineUpNew.openDoor(DoorType.DOOR_FRONT);
                         * }*/
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("control door failed");
                        statusOrderResponse = new StatusOrderResponse()
                        {
                            status = (int)StatusOrderResponseCode.ORDER_STATUS_RESPONSE_ERROR_DATA, content = e.Message
                        };
                        return(statusOrderResponse);
                    }
                }
                #endregion
                #region TYPEREQUEST_OPEN_FRONTDOOR_DELIVERY_PALLET_GATE_2
                else if (typeReq == (int)TyeRequest.TYPEREQUEST_OPEN_FRONTDOOR_DELIVERY_PALLET_GATE_2)
                {
                    // same deviceID forklift
                    try
                    {
                        if (false == Global_Object.doorManagementServiceCtrl.DoorMezzamineUp.getDoorBusy())
                        {
                            Global_Object.doorManagementServiceCtrl.DoorMezzamineUp.openDoor(DoorType.DOOR_FRONT);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("control door failed");
                        statusOrderResponse = new StatusOrderResponse()
                        {
                            status = (int)StatusOrderResponseCode.ORDER_STATUS_RESPONSE_ERROR_DATA, content = e.Message
                        };
                        return(statusOrderResponse);
                    }
                }
                #endregion
                #region TYPEREQUEST_CLOSE_FRONTDOOR_DELIVERY_PALLET_GATE_1
                else if (typeReq == (int)TyeRequest.TYPEREQUEST_CLOSE_FRONTDOOR_DELIVERY_PALLET_GATE_1)
                {
                    // same deviceID forklift
                    try
                    {
                        Global_Object.doorManagementServiceCtrl.DoorMezzamineUpNew.closeDoor(DoorType.DOOR_FRONT);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("control door failed");
                        statusOrderResponse = new StatusOrderResponse()
                        {
                            status = (int)StatusOrderResponseCode.ORDER_STATUS_RESPONSE_ERROR_DATA, content = e.Message
                        };
                        return(statusOrderResponse);
                    }
                }
                #endregion
                #region TYPEREQUEST_CLOSE_FRONTDOOR_DELIVERY_PALLET_GATE_2
                else if (typeReq == (int)TyeRequest.TYPEREQUEST_CLOSE_FRONTDOOR_DELIVERY_PALLET_GATE_2)
                {
                    // same deviceID forklift
                    try
                    {
                        Global_Object.doorManagementServiceCtrl.DoorMezzamineUp.closeDoor(DoorType.DOOR_FRONT);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("control door failed");
                        statusOrderResponse = new StatusOrderResponse()
                        {
                            status = (int)StatusOrderResponseCode.ORDER_STATUS_RESPONSE_ERROR_DATA, content = e.Message
                        };
                        return(statusOrderResponse);
                    }
                }
                #endregion
                #region TYPEREQUEST_OPEN_FRONTDOOR_RETURN_PALLET
                else if (typeReq == (int)TyeRequest.TYPEREQUEST_OPEN_FRONTDOOR_RETURN_PALLET)
                {
                    // same deviceID forklift
                    try
                    {
                        if (false == Global_Object.doorManagementServiceCtrl.DoorMezzamineReturn.getDoorBusy())
                        {
                            Global_Object.doorManagementServiceCtrl.DoorMezzamineReturn.openDoor(DoorType.DOOR_FRONT);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("control door failed");
                        statusOrderResponse = new StatusOrderResponse()
                        {
                            status = (int)StatusOrderResponseCode.ORDER_STATUS_RESPONSE_ERROR_DATA, content = e.Message
                        };
                        return(statusOrderResponse);
                    }
                }
                #endregion
                #region TYPEREQUEST_CLOSE_FRONTDOOR_RETURN_PALLET
                else if (typeReq == (int)TyeRequest.TYPEREQUEST_CLOSE_FRONTDOOR_RETURN_PALLET)
                {
                    // same deviceID forklift
                    try
                    {
                        Global_Object.doorManagementServiceCtrl.DoorMezzamineReturn.closeDoor(DoorType.DOOR_FRONT);
                        Global_Object.doorManagementServiceCtrl.DoorMezzamineReturn.LampSetStateOff(DoorType.DOOR_BACK);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("control door failed");
                        statusOrderResponse = new StatusOrderResponse()
                        {
                            status = (int)StatusOrderResponseCode.ORDER_STATUS_RESPONSE_ERROR_DATA, content = e.Message
                        };
                        return(statusOrderResponse);
                    }
                }
                #endregion
                statusOrderResponse = new StatusOrderResponse()
                {
                    status = (int)StatusOrderResponseCode.ORDER_STATUS_RESPONSE_SUCCESS, content = ""
                };
            }
            catch (Exception e)
            {
                statusOrderResponse = new StatusOrderResponse()
                {
                    status = (int)StatusOrderResponseCode.ORDER_STATUS_RESPONSE_ERROR_DATA, content = e.Message
                };
                return(statusOrderResponse);
            }
            try
            {
                String path = Path.Combine(System.IO.Directory.GetCurrentDirectory(), "RecoderDataOrder.txt");
                if (!File.Exists(path))
                {
                    File.Create(path);
                }
                if (File.ReadAllBytes(path).Length > 3000000) // lon 3M thi xoa bot
                {
                    String[] lines = File.ReadAllLines(path);
                    Array.Clear(lines, 0, 615); // xoa bot text 615 vong tuong ung 1M
                }
                File.AppendAllText(path, DateTime.Now.ToString("yyyyMMdd HH:mm:ss tt >> ") + dataReq + Environment.NewLine + "[Response] >> " + (statusOrderResponse.status) + Environment.NewLine);
            }
            catch { }
            return(statusOrderResponse);
        }
        public override void Draw()
        {
            try
            {
                if (properties.IsConnected)
                {
                    if ((agvErr == true) || (flagLostPosition == true))
                    {
                        setColorRobotStatus(RobotStatusColorCode.ROBOT_STATUS_ERROR);
                    }
                    else
                    {
                        setColorRobotStatus(RobotStatusColorCode.ROBOT_STATUS_CONNECT);
                    }
                }
                else
                {
                    if (properties.RequestChargeBattery)
                    {
                        setColorRobotStatus(RobotStatusColorCode.ROBOT_STATUS_CHARGING);
                    }
                    else
                    {
                        setColorRobotStatus(RobotStatusColorCode.ROBOT_STATUS_DISCONNECT);
                    }
                }
                this.border.Dispatcher.BeginInvoke(new System.Threading.ThreadStart(() =>
                {
                    props.rbRotateTransform.Angle = -properties.pose.Angle;
                    Point cPoint      = Global_Object.CoorCanvas(properties.pose.Position);
                    props.rbTranslate = new TranslateTransform(cPoint.X - (border.Width / 2), cPoint.Y - (border.Height / 2));
                    props.rbTransformGroup.Children[1] = props.rbTranslate;
                    //Render Status
                    props.contentRotateTransform.Angle      = (properties.pose.Angle);
                    props.contentTranslate                  = new TranslateTransform(0, 0);
                    props.contentTransformGroup.Children[1] = props.contentTranslate;
                    headerPoint.RenderTransform             = new TranslateTransform(MiddleHeaderCv().X - 2.5, MiddleHeaderCv().Y - 1);
                    headerPoint1.RenderTransform            = new TranslateTransform(MiddleHeaderCv1().X - 2.5, MiddleHeaderCv1().Y - 1);
                    headerPoint2.RenderTransform            = new TranslateTransform(MiddleHeaderCv2().X - 2.5, MiddleHeaderCv2().Y - 1);
                    headerPoint3.RenderTransform            = new TranslateTransform(MiddleHeaderCv3().X - 2.5, MiddleHeaderCv3().Y - 1);


                    PathGeometry pgeometry = new PathGeometry();
                    PathFigure pF          = new PathFigure();
                    pF.StartPoint          = TopHeaderCv();

                    // pF.StartPoint = new Point(TopHeader().X * 10, TopHeader().Y * 10);
                    LineSegment pp = new LineSegment();

                    pF.Segments.Add(new LineSegment()
                    {
                        Point = BottomHeaderCv()
                    });
                    pF.Segments.Add(new LineSegment()
                    {
                        Point = BottomTailCv()
                    });
                    pF.Segments.Add(new LineSegment()
                    {
                        Point = TopTailCv()
                    });
                    pF.Segments.Add(new LineSegment()
                    {
                        Point = TopHeaderCv()
                    });
                    // pF.Segments.Add(new LineSegment() { Point = new Point(BottomHeader().X*10, BottomHeader().Y * 10) });
                    //pF.Segments.Add(new LineSegment() { Point = new Point(BottomTail().X * 10, BottomTail().Y * 10) });
                    //  pF.Segments.Add(new LineSegment() { Point = new Point(TopTail().X * 10, TopTail().Y * 10) });
                    //pF.Segments.Add(new LineSegment() { Point = new Point(TopHeader().X * 10, TopHeader().Y * 10) });
                    pgeometry.Figures.Add(pF);
                    safetyArea.Data = pgeometry;

                    //  props.rbID.Content = properties.pose.Position.X.ToString("0");
                    // props.rbTask.Content = properties.pose.Position.Y.ToString("0");
                    props.rbID.Content = properties.Label;
                    // props.rbTask.Content = properties.pose.Position.Y.ToString("0");

                    smallCircle.Set(cPoint, new Point(0, 0), new Point(Radius_S, Radius_S));

                    Point ccR = CenterOnLineCv(Center_R);
                    redCircle.Set(ccR, new Point(0, 0), new Point(Radius_R, Radius_R));

                    Point ccB = CenterOnLineCv(Center_B);
                    blueCircle.Set(ccB, new Point(0, 0), new Point(Radius_B, Radius_B));

                    Point ccG = CenterOnLineCv(Center_G);
                    greenCircle.Set(ccG, new Point(0, 0), new Point(Radius_G, Radius_G));

                    Point ccO = CenterOnLineCv(Center_O);
                    orangeCircle.Set(ccO, new Point(0, 0), new Point(Radius_O, Radius_O));
                }));
            }
            catch { }
        }