示例#1
0
文件: Hall.cs 项目: ingex0/smarttank
        void btnCreate_OnPress(object sender, EventArgs e)
        {
            if (bWaitEnter)
            {
                return;
            }

            if (bInRoom)
            {
                headSend          = new stPkgHead();
                Stream            = new MemoryStream();
                headSend.dataSize = 0;
                headSend.iSytle   = 39;
                SocketMgr.SendCommonPackge(headSend, Stream);
                Stream.Close();

                bIsHost = false;
                bInRoom = false;
            }

            headSend = new stPkgHead();
            //head.iSytle = //包头类型还没初始化


            Stream            = new MemoryStream();
            headSend.dataSize = 0;
            headSend.iSytle   = 30;
            SocketMgr.SendCommonPackge(headSend, Stream);
            Stream.Close();
            bWaitEnter = true;
        }
示例#2
0
        public StarwarRule2()
        {
            BaseGame.ShowMouse = true;

            bgTexture               = BaseGame.ContentMgr.Load <Texture2D>(Path.Combine(Directories.BgContent, "bg2"));
            npTexture               = BaseGame.ContentMgr.Load <Texture2D>(Path.Combine(Directories.UIContent, "namepass2"));
            bgRect                  = new Rectangle(0, 0, 800, 600);
            namebox                 = new Textbox("namebox", new Vector2(320, 400), 150, "", false);
            passbox                 = new Textbox("passbox", new Vector2(320, 430), 150, "", false);
            passbox.bStar           = true;
            namebox.maxLen          = 20;
            passbox.maxLen          = 20;
            btnLogin                = new TextButton("OkLogin", new Vector2(320, 480), "Login", 0, Color.Gold);
            btnClear                = new TextButton("ClearBtn", new Vector2(405, 480), "Clear", 0, Color.Gold);
            SocketMgr.OnReceivePkg += new SocketMgr.ReceivePkgEventHandler(OnReceivePack);
            btnLogin.OnClick       += new EventHandler(btnLogin_OnPress);
            btnClear.OnClick       += new EventHandler(btnClear_OnPress);
            wait      = 0;
            bHasError = false;

            SocketMgr.Initial();

            //heartTimer = new Timer(1000);
            //heartTimer.Elapsed += new ElapsedEventHandler(heartTimer_Tick);
        }
示例#3
0
文件: Hall.cs 项目: ingex0/smarttank
        void btnEnter_OnPress(object sender, EventArgs e)
        {
            if (bWaitEnter || bInRoom)
            {
                return;
            }


            if (roomList.selectedIndex == -1)
            {
                return;
            }

            headSend = new stPkgHead();
            //byte[] roomid;

            //roomid = SocketMgr.StructToBytes(roomList.MyIDs[roomList.selectedIndex]);

            Stream = new MemoryStream();
            //Stream.Write(roomid, 0, 4);
            //head.dataSize = 4;
            headSend.dataSize = 0;
            headSend.iSytle   = 31;
            SocketMgr.SendCommonPackge(headSend, Stream);
            Stream.Close();
            bWaitEnter = true;
        }
 public void PrintSocketState()
 {
     for (int i = 0; i < SocketMgr.GetInstance().socketArr.Length; i++)
     {
         Info(i.ToString() + ":" + SocketMgr.GetInstance().socketArr[i].socketState.ToString());
     }
 }
示例#5
0
        private void SendOverRankInfo()
        {
            stPkgHead head = new stPkgHead();

            head.iSytle = 80;
            RankInfo[] info   = new RankInfo[ships.Length];
            byte[]     buffer = new byte[ships.Length * RankInfo.TotolLength];

            for (int i = 0; i < ships.Length; i++)
            {
                info[i].Score = ships[i].Score;
                info[i].Rank  = 0;
                info[i].Name  = new char[RankInfo.NameLength];

                for (int j = 0; j < ships[i].PlayerName.Length; j++)
                {
                    info[i].Name[j] = ships[i].PlayerName[j];
                }

                byte[] temp = SocketMgr.StructToBytes(info[i]);
                temp.CopyTo(buffer, i * RankInfo.TotolLength);
            }

            MemoryStream stream = new MemoryStream();

            stream.Write(buffer, 0, buffer.Length);
            head.dataSize = buffer.Length;

            SocketMgr.SendCommonPackge(head, stream);
            stream.Close();
        }
示例#6
0
        /*
         * private void heartTimer_Tick(Object obj, ElapsedEventArgs e)
         * {
         *  stPkgHead head = new stPkgHead();
         *  MemoryStream Stream = new MemoryStream();
         *  head.dataSize = 0;
         *  head.iSytle = 0;
         *  SocketMgr.SendCommonPackge(head, Stream);
         *  Stream.Close();
         * }
         */
        void OnReceivePack(stPkgHead head, Byte[] data)
        {
            if (wait == 0)
            {
                return;
            }

            if (head.iSytle == 11)
            {
                wait--;
                //heartTimer.Start();
                GameManager.AddGameScreen(new Hall2(namebox.text));
            }
            if (head.iSytle == 12)
            {
                wait--;
                namebox        = new Textbox("namebox", new Vector2(320, 400), 150, "", false);
                passbox        = new Textbox("passbox", new Vector2(320, 430), 150, "", false);
                passbox.bStar  = true;
                namebox.maxLen = 20;
                passbox.maxLen = 20;
                SocketMgr.Close();
                System.Windows.Forms.MessageBox.Show("用户名密码错误或重登陆!");
            }
            else
            {
                bHasError = true;
            }
        }
示例#7
0
 public RPC()
 {
     client       = new SprotoRpc.Client();
     sm           = new SocketMgr();
     sessionMap   = new Dictionary <int, TFunc>();
     serverRPCMap = new Dictionary <int, TServerRPC> ();
     initRPC();
 }
示例#8
0
文件: Hall.cs 项目: ingex0/smarttank
 void btnRefresh_OnPress(object sender, EventArgs e)
 {
     headSend          = new stPkgHead();
     Stream            = new MemoryStream();
     headSend.dataSize = 0;
     headSend.iSytle   = 33;
     SocketMgr.SendCommonPackge(headSend, Stream);
     Stream.Close();
 }
示例#9
0
文件: Hall.cs 项目: ingex0/smarttank
 void btnStart_OnPress(object sender, EventArgs e)
 {
     headSend          = new stPkgHead();
     Stream            = new MemoryStream();
     headSend.dataSize = 0;
     headSend.iSytle   = 70;
     SocketMgr.SendCommonPackge(headSend, Stream);
     Stream.Close();
     bWaitEnter = true;
 }
        protected override void StationWork(int step)
        {
            WaranResult waranResult;

            switch (step)
            {
            case (int)StationStep.step_init:

                //retry_init:
                //IOMgr.GetInstace().WriteIoBit("上料真空吸电磁阀", true);
                //waranResult = CheckIobyName("上料吸嘴真空检测", false, "上料站: 上料吸嘴可能被堵住,请拿开");
                //if (waranResult == WaranResult.Retry)
                //    goto retry_init;
                PushMultStep((int)StationStep.step_CheckAllFinish);
                DelCurrentStep();
                userTimerCT.ResetStartTimer();
                oldTime = 0;
                break;

            case (int)StationStep.step_CheckAllFinish:
                if (SocketMgr.GetInstance().socketArr[(int)SocketType.load].socketState == SocketState.Have &&
                    (SocketMgr.GetInstance().socketArr[(int)SocketType.stick1].socketState == SocketState.None || SocketMgr.GetInstance().socketArr[(int)SocketType.stick1].socketState == SocketState.HaveHaftOK) &&
                    (SocketMgr.GetInstance().socketArr[(int)SocketType.stick2].socketState == SocketState.None || SocketMgr.GetInstance().socketArr[(int)SocketType.stick2].socketState == SocketState.HaveOK) &&
                    (SocketMgr.GetInstance().socketArr[(int)SocketType.press].socketState == SocketState.None || SocketMgr.GetInstance().socketArr[(int)SocketType.press].socketState == SocketState.HaveOK) &&
                    (SocketMgr.GetInstance().socketArr[(int)SocketType.unload].socketState == SocketState.None
                    )
                    )
                {
                    if (CheckLineIO())
                    {
                        Info("Socket流水线:各站准备完成开始流动");
                        MoveSocketLine();
                        if (ParamSetMgr.GetInstance().GetIntParam("保压屏蔽") != 1)
                        {
                            KeepPressure();
                        }
                        CurrentTime = userTimerCT.NowTime;
                        CTmsCounts  = CurrentTime - oldTime;
                        oldTime     = CurrentTime;
                        ParamSetMgr.GetInstance().SetDoubleParam("CT", CTmsCounts / 1000.00);
                    }
                }
                break;
            }
        }
示例#11
0
文件: Hall.cs 项目: ingex0/smarttank
        void btnQuit_OnPress(object sender, EventArgs e)
        {
            headSend          = new stPkgHead();
            Stream            = new MemoryStream();
            headSend.dataSize = 0;
            headSend.iSytle   = 39;
            SocketMgr.SendCommonPackge(headSend, Stream);
            Stream.Close();

            bIsHost = false;
            bInRoom = false;

            headSend          = new stPkgHead();
            Stream            = new MemoryStream();
            headSend.dataSize = 0;
            headSend.iSytle   = 33;
            roomList.Clear();
            SocketMgr.SendCommonPackge(headSend, Stream);
            Stream.Close();
        }
示例#12
0
        void btnLogin_OnPress(object sender, EventArgs e)
        {
            if (wait != 0)
            {
                return;
            }

            LoginData data;

            data.Name = new char[21];
            char[] temp = namebox.text.ToCharArray();
            for (int i = 0; i < temp.Length; i++)
            {
                data.Name[i] = temp[i];
            }


            data.Password = new char[21];
            temp          = passbox.text.ToCharArray();
            for (int i = 0; i < temp.Length; i++)
            {
                data.Password[i] = temp[i];
            }
            stPkgHead    head   = new stPkgHead();
            MemoryStream Stream = new MemoryStream();

            Stream.Write(SocketMgr.StructToBytes(data), 0, LoginData.size);
            head.dataSize = (int)Stream.Length;
            head.iSytle   = 10;

            SocketMgr.ConnectToServer();
            SocketMgr.StartReceiveThread();
            SocketMgr.SendCommonPackge(head, Stream);
            Stream.Close();

            wait++;
        }
示例#13
0
        void OnReceivePack(stPkgHead head, MemoryStream data)
        {
            if (head.iSytle == 50)
            {
                RankInfo ri;
                string   str;

                for (int i = 0; i < head.dataSize; i += 32)
                {
                    str = "";
                    data.Read(rankBuffer, 0, 32);

                    ri = (RankInfo)SocketMgr.BytesToStuct(rankBuffer, typeof(RankInfo));

                    for (int j = 0; ri.name[j] != '\0'; ++j)
                    {
                        str += ri.name[j];
                    }


                    rankList.AddItem(ri.rank + "        " + str + "              " + ri.score);
                }
            }
        }
示例#14
0
文件: Hall.cs 项目: ingex0/smarttank
        public Hall(string tmpName)
        {
            devHeads = new List <string>();
            devHeads.Add("asokawu");
            devHeads.Add("ddli");
            devHeads.Add("jehutyhu");
            devHeads.Add("zashchen");
            devHeads.Add("orrischen");
            devHeads.Add("johntan");
            devHeads.Add("seekyao");
            myName = tmpName;

            heads  = new List <Texture2D>();
            ranks  = new List <int>();
            scores = new List <int>();

            BaseGame.ShowMouse = true;

            roomList = new Listbox("roomlist", new Vector2(50, 120), new Point(200, 350), Color.White, Color.Green);

            rankList = new Listbox("ranklist", new Vector2(300, 120), new Point(450, 350), Color.White, Color.Green);


            bgTexture = BaseGame.ContentMgr.Load <Texture2D>(Path.Combine(Directories.BgContent, "bg"));
            rlTexture = BaseGame.ContentMgr.Load <Texture2D>(Path.Combine(Directories.UIContent, "roomlist"));
            riTexture = BaseGame.ContentMgr.Load <Texture2D>(Path.Combine(Directories.UIContent, "roominfo"));

            bgRect = new Rectangle(0, 0, 800, 600);


            btnRefresh = new TextButton("RefreshBtn", new Vector2(150, 480), "Refresh", 0, Color.Gold);
            btnCreate  = new TextButton("CreateBtn", new Vector2(310, 480), "Create a new room", 0, Color.Gold);
            btnQuit    = new TextButton("QuitBtn", new Vector2(450, 410), "Quit", 0, Color.Gold);
            btnEnter   = new TextButton("EnterBtn", new Vector2(70, 480), "Enter", 0, Color.Gold);
            btnRank    = new TextButton("RankBtn", new Vector2(650, 480), "Rank List", 0, Color.Gold);
            btnStart   = new TextButton("StartBtn", new Vector2(550, 410), "Start", 0, Color.Gold);

            btnRefresh.OnClick += new EventHandler(btnRefresh_OnPress);
            btnCreate.OnClick  += new EventHandler(btnCreate_OnPress);
            btnQuit.OnClick    += new EventHandler(btnQuit_OnPress);
            btnEnter.OnClick   += new EventHandler(btnEnter_OnPress);
            btnRank.OnClick    += new EventHandler(btnRank_OnPress);
            btnStart.OnClick   += new EventHandler(btnStart_OnPress);

            rankList.OnChangeSelection += new EventHandler(rankList_OnChangeSelection);
            roomList.OnChangeSelection += new EventHandler(roomList_OnChangeSelection);

            SocketMgr.OnReceivePkg += new SocketMgr.ReceivePkgEventHandler(OnReceivePack);



            headSend          = new stPkgHead();
            Stream            = new MemoryStream();
            headSend.dataSize = 0;
            headSend.iSytle   = 33;
            SocketMgr.SendCommonPackge(headSend, Stream);
            Stream.Close();
            bInRoom    = false;
            bWaitEnter = false;
            bIsHost    = false;
            bHasError  = false;
        }
示例#15
0
        public StationStep StepCheckIpos(bool bmanual = false)
        {
            StationStep step               = StationStep.Step_CheckIpos;
            bool        dEnableA           = ParamSetMgr.GetInstance().GetBoolParam("屏蔽A工位");
            bool        dEnableB           = ParamSetMgr.GetInstance().GetBoolParam("屏蔽B工位");
            bool        bA_UnLoadLoadStart = TableData.GetInstance().GetStationStartCmd("A_UnLoadLoad") && !dEnableA;
            bool        bB_UnLoadLoadStart = TableData.GetInstance().GetStationStartCmd("B_UnLoadLoad") && !dEnableB;

            if (bA_UnLoadLoadStart || bB_UnLoadLoadStart || ParamSetMgr.GetInstance().GetBoolParam("重新上料"))
            {
                ParamSetMgr.GetInstance().SetBoolParam("重新上料", false);
                TableData.GetInstance().ResetStartCmd("A_UnLoadLoad");
                TableData.GetInstance().ResetStartCmd("B_UnLoadLoad");
                strStationName = TableData.GetInstance().GetStationName();
                if (strStationName == "A_Pick" || strStationName == "B_Pick")
                {
                    TableData.GetInstance().SetStationResult("A_UnLoadLoad", true);
                    TableData.GetInstance().SetStationResult("B_UnLoadLoad", true);
                    return(step);
                }
                SocketNumOfUnloadLoad = TableData.GetInstance().GetSocketNum(1, 0.5) - 1;
                if (SocketNumOfUnloadLoad == 0 && dEnableA)
                {
                    TableData.GetInstance().SetStationResult("A_UnLoadLoad", true);
                    TableData.GetInstance().SetStationResult("B_UnLoadLoad", true);
                    return(step);
                }
                if (SocketNumOfUnloadLoad == 1 && dEnableB)
                {
                    TableData.GetInstance().SetStationResult("A_UnLoadLoad", true);
                    TableData.GetInstance().SetStationResult("B_UnLoadLoad", true);
                    return(step);
                }
                IOMgr.GetInstace().WriteIoBit("NG指示红灯", false);
                IOMgr.GetInstace().WriteIoBit("OK指示绿灯", true);
                Info("开始上下料,安全光栅开始屏蔽");
                ParamSetMgr.GetInstance().SetBoolParam("启用安全光栅", false);
                ParamSetMgr.GetInstance().SetBoolParam("可以上下料", true);

                SocketState state = SocketMgr.GetInstance().socketArr[SocketNumOfUnloadLoad].socketState;
                if (state == SocketState.HaveOK || state == SocketState.HaveNG)
                {
                    string lightColor = state == SocketState.HaveOK ? "OK指示绿灯" : "NG指示红灯";
                    string fp         = state == SocketState.HaveOK ? "P" : "F";
                    UserTest.TestResultAB[SocketNumOfUnloadLoad].SocketerNumber = SocketNumOfUnloadLoad == 0 ? "A" : "B";
                    #region 计算CT赋值
                    if (UserTest.ProductCount.CountCTAll == 0)
                    {
                        UserTest.ProductCount.StarCTTime  = DateTime.Now;
                        UserTest.ProductCount.EndCTTime   = DateTime.Now;
                        UserTest.ProductCount.CountCTTime = 0;
                    }
                    else
                    {
                        UserTest.ProductCount.CountCTTime += (DateTime.Now - UserTest.ProductCount.EndCTTime).TotalSeconds;
                        UserTest.ProductCount.EndCTTime    = DateTime.Now;
                        if ((DateTime.Now - UserTest.ProductCount.StarCTTime).TotalMinutes > ParamSetMgr.GetInstance().GetDoubleParam("UPH计算时长"))
                        {
                            if (UserTest.ProductCount.CountCTAll > ParamSetMgr.GetInstance().GetDoubleParam("UPH计算时长范围内最少个数"))
                            {
                                UserTest.ProductCount.UPH = (UserTest.ProductCount.CountCTAll) * 3600 / UserTest.ProductCount.CountCTTime;
                            }
                            //清除
                            UserTest.ProductCount.CountCTAll = -1;
                        }
                    }
                    UserTest.ProductCount.CountCTAll++;
                    if (SocketNumOfUnloadLoad == 0)
                    {
                        if (fp == "P")
                        {
                            UserTest.ProductCount.OKA++;
                        }
                        else
                        {
                            UserTest.ProductCount.NGA++;
                            if (!UserTest.FailResultAB.Play)
                            {
                                UserTest.ProductCount.PlayFailA++;
                                UserTest.FailResultAB.OC   = true;
                                UserTest.FailResultAB.SFR  = true;
                                UserTest.FailResultAB.Tilt = true;
                            }
                            if (!UserTest.FailResultAB.OC)
                            {
                                UserTest.ProductCount.OCFailA++;
                                UserTest.FailResultAB.Play = true;
                                UserTest.FailResultAB.SFR  = true;
                                UserTest.FailResultAB.Tilt = true;
                            }
                            if (!UserTest.FailResultAB.Tilt)
                            {
                                UserTest.ProductCount.TiltFailA++;
                                UserTest.FailResultAB.OC   = true;
                                UserTest.FailResultAB.SFR  = true;
                                UserTest.FailResultAB.Play = true;
                            }
                            if (!UserTest.FailResultAB.SFR)
                            {
                                UserTest.ProductCount.SFRFailA++;
                                UserTest.FailResultAB.OC   = true;
                                UserTest.FailResultAB.Play = true;
                                UserTest.FailResultAB.Tilt = true;
                            }
                            if (UserTest.FailResultAB.Play && UserTest.FailResultAB.OC && UserTest.FailResultAB.Tilt && UserTest.FailResultAB.SFR)
                            {
                                UserTest.ProductCount.OtherFailA++;
                            }
                        }
                    }
                    else
                    {
                        if (fp == "P")
                        {
                            UserTest.ProductCount.OKB++;
                        }
                        else
                        {
                            UserTest.ProductCount.NGB++;
                            if (!UserTest.FailResultAB.Play)
                            {
                                UserTest.ProductCount.PlayFailB++;
                                UserTest.FailResultAB.OC   = true;
                                UserTest.FailResultAB.SFR  = true;
                                UserTest.FailResultAB.Tilt = true;
                            }
                            if (!UserTest.FailResultAB.OC)
                            {
                                UserTest.ProductCount.OCFailB++;
                                UserTest.FailResultAB.Play = true;
                                UserTest.FailResultAB.SFR  = true;
                                UserTest.FailResultAB.Tilt = true;
                            }
                            if (!UserTest.FailResultAB.Tilt)
                            {
                                UserTest.ProductCount.TiltFailB++;
                                UserTest.FailResultAB.OC   = true;
                                UserTest.FailResultAB.SFR  = true;
                                UserTest.FailResultAB.Play = true;
                            }
                            if (!UserTest.FailResultAB.SFR)
                            {
                                UserTest.ProductCount.SFRFailB++;
                                UserTest.FailResultAB.OC   = true;
                                UserTest.FailResultAB.Play = true;
                                UserTest.FailResultAB.Tilt = true;
                            }
                            if (UserTest.FailResultAB.Play && UserTest.FailResultAB.OC && UserTest.FailResultAB.Tilt && UserTest.FailResultAB.SFR)
                            {
                                UserTest.ProductCount.OtherFailB++;
                            }
                        }
                    }


                    #endregion
                    Form_Auto.EvenShowCT(SocketNumOfUnloadLoad + 1);
                    UserTest.TestResultAB[SocketNumOfUnloadLoad].Result = fp == "P" ? true : false;
                    if (fp == "P")
                    {
                        UserTest.TestResultAB[SocketNumOfUnloadLoad].FailStep = "Pass";
                    }
                    UserTest.TestResultAB[SocketNumOfUnloadLoad].EndTime  = DateTime.Now;
                    UserTest.TestResultAB[SocketNumOfUnloadLoad].TestTime = (UserTest.TestResultAB[SocketNumOfUnloadLoad].EndTime - UserTest.TestResultAB[SocketNumOfUnloadLoad].StarTime).TotalSeconds;
                    string errCsv = CSVHelper.Instance.SaveToCSVPath(PathHelper.TestResultCsvPath, UserTest.TestResultAB[SocketNumOfUnloadLoad]);
                    IOMgr.GetInstace().WriteIoBit("OK指示绿灯", false);
                    IOMgr.GetInstace().WriteIoBit("NG指示红灯", false);
                    IOMgr.GetInstace().WriteIoBit(lightColor, true);
                    Info($"保存OK结果:cvs={errCsv}.");
                    if (SocketNumOfUnloadLoad == 0)
                    {
                        IOMgr.GetInstace().WriteIoBit($"ALens升降气缸", true);
                    }
                    else
                    {
                        IOMgr.GetInstace().WriteIoBit($"BLens升降气缸", true);
                    }
                    //PlaceToSocket(SocketNumOfUnloadLoad);
                    UserTest.CTTestAB[SocketNumOfUnloadLoad].Star = false;
                    UserTest.CTTestAB[SocketNumOfUnloadLoad].End  = false;
                    UserTest.CTTestAB[SocketNumOfUnloadLoad].Show = true;
                }
                //同意下料接口
                SysFunConfig.LodUnloadPatten.ULoad(SocketNumOfUnloadLoad == 0? "A":"B", bmanual);
retry_check_Start:
                ParamSetMgr.GetInstance().SetBoolParam("启用安全光栅", false);
                WaranResult waranResult = doWhileCheckStartSignal.doSomething(this, doWhileCheckStartSignal, false, new object[] { this });
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_check_Start;
                }
                IOMgr.GetInstace().WriteIoBit($"相机光源", true);
                IOMgr.GetInstace().WriteIoBit("启动按钮灯", false);
                IOMgr.GetInstace().WriteIoBit("OK指示绿灯", false);
                IOMgr.GetInstace().WriteIoBit("NG指示红灯", false);
                if (!IOMgr.GetInstace().ReadIoInBit($"点胶液位感应") && ParamSetMgr.GetInstance().GetBoolParam("点胶液位检测"))
                {
                    MessageBox.Show($"点胶液位感应有信号,胶水已经用完!请更换,或者屏蔽[点胶液位检测]。", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                    goto retry_check_Start;
                }
                Form_Auto.EvenGetSN(SocketNumOfUnloadLoad);
                if (UserTest.TestResultAB[SocketNumOfUnloadLoad].SerialNumber == "NOSN")
                {
                    MessageBox.Show("请输入SN 或者屏蔽SN,重新启动", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                    goto retry_check_Start;
                }
                if (SocketNumOfUnloadLoad == 0)
                {
                    UserTest.ProductCount.CompeteA++;
                }
                else
                {
                    UserTest.ProductCount.CompeteB++;
                }
                ParamSetMgr.GetInstance().SetBoolParam("启用安全光栅", true);
                ParamSetMgr.GetInstance().SetBoolParam("可以上下料", false);
                ParamSetMgr.GetInstance().SetBoolParam("AA完成", false);
                ParamSetMgr.GetInstance().SetBoolParam("点胶完成", false);
                ParamSetMgr.GetInstance().SetBoolParam("启动AA", false);
                ParamSetMgr.GetInstance().SetBoolParam("启动点胶", false);
                Info("开始上下料,安全光栅开始启用");
                ParamSetMgr.GetInstance().SetBoolParam("启用安全光栅", true);
                UserTest.CTTestAB[SocketNumOfUnloadLoad].Star = true;
                UserTest.CTTestAB[SocketNumOfUnloadLoad].End  = false;
                UserTest.CTTestAB[SocketNumOfUnloadLoad].Show = false;

                step = StationStep.Step_GoSnap;
            }
            return(step);
        }
示例#16
0
        public StationStep StepGoSnap(VisionControl visionControl, bool bmanual = false)
        {
            StationStep step = StationStep.Step_Stop;

            //拍照识别是否有料,计算偏差(6月后做)
            ParamSetMgr.GetInstance().SetBoolParam("启动点胶", true);
            //开始点胶(优先实现画轨迹)
            //获取当前夹取位置是A工位还是B工位
            int StationIndex = TableData.GetInstance().GetSocketNum(1, 0.5) - 1;

            PathHelper.Disp_ID = StationIndex;
            string stationAAName = StationIndex == 0 ? "A" : "B";

            ParamSetMgr.GetInstance().SetBoolParam($"{stationAAName}工位点胶", true);
            double     CenterX      = ParamSetMgr.GetInstance().GetDoubleParam("产品点胶X轴半径");
            double     CenterY      = ParamSetMgr.GetInstance().GetDoubleParam("产品点胶Y轴半径");
            double     DelZ         = ParamSetMgr.GetInstance().GetDoubleParam("点胶Z轴上升高度偏差");
            int        DispDelay    = ParamSetMgr.GetInstance().GetIntParam("出胶延迟");
            double     DispRunAngle = ParamSetMgr.GetInstance().GetDoubleParam("画胶角度");
            double     DispEndAngle = ParamSetMgr.GetInstance().GetDoubleParam("收胶角度");
            bool       DispEnable   = ParamSetMgr.GetInstance().GetBoolParam("屏蔽点胶");
            bool       DispPhoto    = ParamSetMgr.GetInstance().GetBoolParam("点胶相机拍照定位");
            double     SafeZ        = GetStationPointDic()[$"安全位置"].pointZ;
            double     X            = 0;
            double     Y            = 0;
            double     DispPhotoX   = GetStationPointDic()[$"{stationAAName}工位拍照位"].pointX;
            double     DispPhotoY   = GetStationPointDic()[$"{stationAAName}工位拍照位"].pointY;
            double     DispPhotoZ   = GetStationPointDic()[$"{stationAAName}工位拍照位"].pointZ;
            double     DispPosX     = GetStationPointDic()[$"{stationAAName}工位点胶位"].pointX;
            double     DispPosY     = GetStationPointDic()[$"{stationAAName}工位点胶位"].pointY;
            double     DispPosZ     = GetStationPointDic()[$"{stationAAName}工位点胶位"].pointZ;
            double     x1           = GetStationPointDic()["安全位置"].pointX;
            CameraBase cam          = null;

            if (!ParamSetMgr.GetInstance().GetBoolParam("屏蔽上相机"))
            {
                cam = CameraMgr.GetInstance().GetCamera("Top");
                cam.BindWindow(visionControl);
                Task.Run(() =>
                {
                    cam.StopGrap();
                    cam.SetTriggerMode(CameraModeType.Software);
                    cam.SetGain(ParamSetMgr.GetInstance().GetIntParam("点胶相机增益"));
                    cam.SetExposureTime(ParamSetMgr.GetInstance().GetIntParam("点胶相机曝光"));
                    cam.StartGrab();
                });
            }
            IOMgr.GetInstace().WriteIoBit($"相机光源", true);
retry_uplens:
            IOMgr.GetInstace().WriteIoBit($"{stationAAName}Lens升降气缸", true);
            WaranResult waranResult1 = CheckIobyName($"{stationAAName}Lens上升到位", true, $"{stationAAName}Lens上升到位", bmanual);

            if (waranResult1 == WaranResult.Retry)
            {
                goto retry_uplens;
            }
            MoveSigleAxisPosWaitInpos(AxisZ, SafeZ, (double)SpeedType.High, 0.005, bmanual, this);
            MoveY(DispPhotoY, SpeedType.High);

            MoveMulitAxisPosWaitInpos(new int[] { AxisX, AxisZ }, new double[] { DispPhotoX, DispPhotoZ }, new double[] { (double)SpeedType.High, (double)SpeedType.High }, 0.005, bmanual, this);
            HObject img = null;



            if (!ParamSetMgr.GetInstance().GetBoolParam("屏蔽上相机"))
            {
                img = cam.GetImage();
                if (img == null || !img.IsInitialized())
                {
                    img = cam.GetImage();
                }
                else
                {
                    ImageHelper.Instance.SaveImage($"{PathHelper.ImagePathDisp}{DateTime.Now.ToString("HHmmssfff")}.bmp", "bmp", img.Clone());
                }
            }


            IOMgr.GetInstace().WriteIoBit($"相机光源", false);
            //去画胶
            Task.Run(() =>
            {
                if (ParamSetMgr.GetInstance().GetBoolParam("是否选择程控电源"))
                {
                    double valueVoltage = ParamSetMgr.GetInstance().GetDoubleParam("程控电源电压");
                    OtherDevices.ckPower.SetVoltage(StationIndex + 1, valueVoltage);
                    double valueCurrent = ParamSetMgr.GetInstance().GetDoubleParam("程控电源电流");
                    OtherDevices.ckPower.SetCurrent(StationIndex + 1, valueCurrent);
                }
                IOMgr.GetInstace().WriteIoBit($"{stationAAName}模组上电", true);
                IOMgr.GetInstace().WriteIoBit($"12V开启", ParamSetMgr.GetInstance().GetBoolParam("是否开启非程控12V"));
            });
            if (DispEnable)
            {
                step = StationStep.Step_CheckIpos;
                MoveSigleAxisPosWaitInpos(AxisZ, SafeZ, (double)SpeedType.High, 0.005, bmanual, this);
                TableData.GetInstance().SetStationResult("A_UnLoadLoad", true);
                TableData.GetInstance().SetStationResult("B_UnLoadLoad", true);
                return(step);
            }
            if (DispPhoto)
            {
                ////MoveY(DispPhotoY, SpeedType.High);
                ////MoveMulitAxisPosWaitInpos(new int[] { AxisX, AxisZ }, new double[] { DispPhotoX, DispPhotoZ }, new double[] { (double)SpeedType.High, (double)SpeedType.High }, 0.005, bmanual, this);

                //拍照计算 +半径
                double CenterdelX = 0;
                double CenterdelY = 0;
                X        = CenterX + CenterdelX;
                Y        = CenterdelY;
                DispPosX = DispPhotoX - X;
                DispPosY = DispPhotoY + CenterdelY;
            }
            else
            {
                X = CenterX;
                Y = 0;
            }
            //  IOMgr.GetInstace().WriteIoBit("点胶机", false);
            bool brtnExc = true;

            MotionMgr.GetInstace().AddAxisToGroup("点胶群组", 2, new int[] { AxisX, AxisY });

            MoveY(DispPosY, SpeedType.High);
            MoveMulitAxisPosWaitInpos(new int[] { AxisX, AxisZ }, new double[] { DispPosX, DispPosZ + DelZ + 10 }, new double[] { (double)SpeedType.High, (double)SpeedType.High }, 0.005, bmanual, this);

            //    MoveMulitAxisPosWaitInpos(new int[] { AxisX }, new double[] { DispPosX }, new double[] { (double)SpeedType.High }, 0.005, bmanual, this);
            IOMgr.GetInstace().WriteIoBit("点胶机", false);
            MoveMulitAxisPosWaitInpos(new int[] { AxisZ }, new double[] { DispPosZ + DelZ }, new double[] { (double)SpeedType.High }, 0.005, bmanual, this);
            if (ParamSetMgr.GetInstance().GetStringParam("点胶轨迹") == "Circle")
            {
                DateTime dateTime = DateTime.Now;
                if (DispDelay >= 0)
                {
                    IOMgr.GetInstace().WriteIoBit("点胶机", true);
                    Thread.Sleep(DispDelay);
                }
                else
                {
                    Task.Run(() =>
                    {
                        while (true)
                        {
                            if ((DateTime.Now - dateTime).TotalSeconds > Math.Abs(DispDelay) / 1000.0)
                            {
                                IOMgr.GetInstace().WriteIoBit("点胶机", true);
                                break;
                            }
                            Thread.Sleep(10);
                        }
                    });
                }



                //走

                brtnExc &= MotionMgr.GetInstace().ClearBufMove("点胶群组");
                brtnExc &= MotionMgr.GetInstace().RestGpErr("点胶群组");
                //  GpState gps = MotionMgr.GetInstace().GetGpState("点胶群组");
                brtnExc &= MotionMgr.GetInstace().AddBufMove("点胶群组", BufMotionType.buf_Arc2dAbsAngleCW, 1, 2, (double)SpeedType.Mid, (double)SpeedType.Mid, new double[2] {
                    X, Y
                }, new double[2] {
                    DispPosZ, 0
                });
                brtnExc &= MotionMgr.GetInstace().BufTrans("点胶群组");//M314没有buf运动,所以放在这里star
                brtnExc &= MotionMgr.GetInstace().BufStart("点胶群组");
                Thread.Sleep(400);
                if (!WaitXY(DispPosX, DispPosY))
                {
                    IOMgr.GetInstace().WriteIoBit("点胶机", false);
                    return(step);
                }
                IOMgr.GetInstace().WriteIoBit("点胶机", false);
            }
            else
            {
                IOMgr.GetInstace().WriteIoBit("点胶机", true);
                Thread.Sleep(DispDelay);
                MoveY(DispPosY + CenterY * 10, SpeedType.Mid);
                MoveMulitAxisPosWaitInpos(new int[] { AxisX }, new double[] { DispPosX + CenterX * 2 }, new double[] { (double)SpeedType.Mid }, 0.005, bmanual, this);
                MoveY(DispPosY - CenterY * 10, SpeedType.Mid);
                MoveMulitAxisPosWaitInpos(new int[] { AxisX }, new double[] { DispPosX }, new double[] { (double)SpeedType.Mid }, 0.005, bmanual, this);
                MoveY(DispPosY, SpeedType.Mid);
                IOMgr.GetInstace().WriteIoBit("点胶机", false);
            }
            IOMgr.GetInstace().WriteIoBit($"相机光源", true);

            MoveMulitAxisPosWaitInpos(new int[] { AxisZ }, new double[] { DispPosZ + 3 }, new double[] { (double)SpeedType.Mid }, 0.005, bmanual, this);

            MoveMulitAxisPosWaitInpos(new int[] { AxisZ }, new double[] { DispPosZ + 10 }, new double[] { (double)SpeedType.High }, 0.005, bmanual, this);
            if (!ParamSetMgr.GetInstance().GetBoolParam("屏蔽上相机"))
            {
                MoveMulitAxisPosWaitInpos(new int[] { AxisX, AxisZ }, new double[] { DispPhotoX, DispPhotoZ }, new double[] { (double)SpeedType.High, (double)SpeedType.High }, 0.005, bmanual, this);
                // MoveSigleAxisPosWaitInpos(AxisX, DispPhotoX, (double)SpeedType.High, 0.005, bmanual, this);
                MoveY(DispPhotoY, SpeedType.High);
                HObject img2 = cam.GetImage();
                if (img2 == null || !img2.IsInitialized())
                {
                    img2 = cam.GetImage();
                }
                else
                {
                    ImageHelper.Instance.SaveImage($"{PathHelper.ImagePathDisp}{DateTime.Now.ToString("HHmmssfff")}.bmp", "bmp", img2.Clone());
                }
            }
            IOMgr.GetInstace().WriteIoBit($"相机光源", false);

            MoveMulitAxisPosWaitInpos(new int[] { AxisZ }, new double[] { SafeZ }, new double[] { (double)SpeedType.High }, 0.005, bmanual, this);
            MoveSigleAxisPosWaitInpos(AxisX, x1, (double)SpeedType.High, 0.005, bmanual, this);
            step = StationStep.Step_CheckIpos;
            //if (DialogResult.OK!= MessageBox.Show("请确定点胶效果是否OK,OK按确定", "Info", MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly))
            //{
            //    ParamSetMgr.GetInstance().SetBoolParam("重新上料", true);
            //    return step;
            //}
            ParamSetMgr.GetInstance().SetBoolParam("重新上料", false);
            SocketMgr.GetInstance().SetSocketState(SocketNumOfUnloadLoad, SocketState.Have);
            TableData.GetInstance().SetStationResult("A_UnLoadLoad", true);
            TableData.GetInstance().SetStationResult("B_UnLoadLoad", true);
            ParamSetMgr.GetInstance().SetBoolParam("点胶完成", true);
            return(step);
        }
        public void MoveSocketLine(bool bmanual = false)
        {
            WaranResult waranResult;

            Info("各站都已经完成,开始移动");
            Info("XY轴气缸移动前 Socket 状态:");
            PrintSocketState();

            Info("X轴气缸退回");
check_cyliderXback:
            IOMgr.GetInstace().WriteIoBit("X轴气缸电磁阀", false);
            waranResult = CheckIobyName("X轴气缸1原位", true, "Socket流水站: X轴气缸退回, 没到位可能卡住,,请拿开", bmanual);
            if (waranResult == WaranResult.Retry)
            {
                goto check_cyliderXback;
            }
            waranResult = CheckIobyName("X轴气缸2原位", true, "Socket流水站: X轴气缸退回, 没到位可能卡住,,请拿开", bmanual);
            if (waranResult == WaranResult.Retry)
            {
                goto check_cyliderXback;
            }
            Info("Y轴气缸伸出");
check_cyliderYout:
            IOMgr.GetInstace().WriteIoBit("Y轴气缸电磁阀", true);
            waranResult = CheckIobyName("Y轴气缸1到位", true, "Socket流水站: Y轴气缸移动伸出, 没到位可能卡住,,请拿开", bmanual);
            if (waranResult == WaranResult.Retry)
            {
                goto check_cyliderYout;
            }
            waranResult = CheckIobyName("Y轴气缸2到位", true, "Socket流水站: Y轴气缸移动伸出, 没到位可能卡住,,请拿开", bmanual);
            if (waranResult == WaranResult.Retry)
            {
                goto check_cyliderYout;
            }

            Info("Y轴气缸退回");
check_cyliderYback:
            IOMgr.GetInstace().WriteIoBit("Y轴气缸电磁阀", false);

            waranResult = CheckIobyName("Y轴气缸1原位", true, "Socket流水站: Y轴气缸移动退回, 没到位可能卡住,,请拿开", bmanual);
            if (waranResult == WaranResult.Retry)
            {
                goto check_cyliderYback;
            }
            waranResult = CheckIobyName("Y轴气缸2原位", true, "Socket流水站: Y轴气缸移动退回, 没到位可能卡住,,请拿开", bmanual);
            if (waranResult == WaranResult.Retry)
            {
                goto check_cyliderYback;
            }

            Info("X轴气缸伸出");
check_cyliderXout:
            IOMgr.GetInstace().WriteIoBit("X轴气缸电磁阀", true);
            waranResult = CheckIobyName("X轴气缸1到位", true, "Socket流水站: X轴气缸伸出, 没到位可能卡住,,请拿开", bmanual);
            if (waranResult == WaranResult.Retry)
            {
                goto check_cyliderXout;
            }
            waranResult = CheckIobyName("X轴气缸2到位", true, "Socket流水站: X轴气缸伸出, 没到位可能卡住,,请拿开", bmanual);
            if (waranResult == WaranResult.Retry)
            {
                goto check_cyliderXout;
            }
            SocketMgr.GetInstance().MoveNext();
            Info("X轴气缸退回");
check_cyliderXback2:
            IOMgr.GetInstace().WriteIoBit("X轴气缸电磁阀", false);
            waranResult = CheckIobyName("X轴气缸1原位", true, "Socket流水站: X轴气缸退回, 没到位可能卡住,,请拿开", bmanual);
            if (waranResult == WaranResult.Retry)
            {
                goto check_cyliderXback2;
            }
            waranResult = CheckIobyName("X轴气缸2原位", true, "Socket流水站: X轴气缸退回, 没到位可能卡住,,请拿开", bmanual);
            if (waranResult == WaranResult.Retry)
            {
                goto check_cyliderXback2;
            }


            Info("XY轴气缸移动后 Socket 状态:");
            PrintSocketState();
        }
        public void KeepPressure(bool bmanual = false)
        {
            WaranResult waranResult;

            if (SocketMgr.GetInstance().socketArr[(int)SocketType.press].socketState == SocketState.HaveOK || bmanual)
            {
retry_press_up2:
                IOMgr.GetInstace().WriteIoBit("保压气缸电磁阀", false);
                waranResult = CheckIobyName("保压上下气缸原位", true, "流水线站:保压上下气缸原位 没有到位,请检查感应器,气缸,气压,线路等", bmanual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_press_up2;
                }
retry_messureA:
                waranResult = dowhileCheckA.doSomething(this, dowhileCheckA, bmanual, null);
                if (waranResult != WaranResult.Run)
                {
                    waranResult = AlarmMgr.GetIntance().WarnWithDlg("保压时 ,A模块读不出数据 ", this, CommonDlg.DlgWaranType.Waran_Stop_Retry);
                    if (waranResult == WaranResult.Retry)
                    {
                        goto retry_messureA;
                    }
                }
retry_messureB:
                waranResult = dowhileCheckB.doSomething(this, dowhileCheckA, bmanual, null);
                if (waranResult != WaranResult.Run)
                {
                    waranResult = AlarmMgr.GetIntance().WarnWithDlg("保压时 ,B模块读不出数据 ", this, CommonDlg.DlgWaranType.Waran_Stop_Retry);
                    if (waranResult == WaranResult.Retry)
                    {
                        goto retry_messureB;
                    }
                }

                for (int i = 0; i < 4; i++)
                {
                    pressvals[i]     = press1[i];
                    pressvals[4 + i] = press2[i];
                }

retry_press_down:
                IOMgr.GetInstace().WriteIoBit("保压气缸电磁阀", true);
                waranResult = CheckIobyName("保压上下气缸到位", true, "流水线站:保压上下气缸到位 没有到位,请检查感应器,气缸,气压,线路等", bmanual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_press_down;
                }

                Thread.Sleep(ParamSetMgr.GetInstance().GetIntParam("保压时间"));

retry_messureA2:
                waranResult = dowhileCheckA.doSomething(this, dowhileCheckA, bmanual, null);
                if (waranResult != WaranResult.Run)
                {
                    waranResult = AlarmMgr.GetIntance().WarnWithDlg("保压时 ,A模块读不出数据 ", this, CommonDlg.DlgWaranType.Waran_Stop_Retry);
                    if (waranResult == WaranResult.Retry)
                    {
                        goto retry_messureA2;
                    }
                }
retry_messureB2:
                waranResult = dowhileCheckB.doSomething(this, dowhileCheckA, bmanual, null);
                if (waranResult != WaranResult.Run)
                {
                    waranResult = AlarmMgr.GetIntance().WarnWithDlg("保压时 ,B模块读不出数据 ", this, CommonDlg.DlgWaranType.Waran_Stop_Retry);
                    if (waranResult == WaranResult.Retry)
                    {
                        goto retry_messureB2;
                    }
                }
                for (int i = 0; i < 4; i++)
                {
                    pressvals[i]     = Math.Abs(pressvals[i] - press1[i]);
                    pressvals[4 + i] = Math.Abs(pressvals[i + 4] - press2[i]);
                }
                Thread.Sleep(500);
                Weighing.GetInstance().Update(new int[] { pressvals[0], pressvals[1], pressvals[2], pressvals[3] }, new int[] { pressvals[4], pressvals[5], pressvals[6], pressvals[7] });
retry_press_up:
                IOMgr.GetInstace().WriteIoBit("保压气缸电磁阀", false);
                waranResult = CheckIobyName("保压上下气缸原位", true, "流水线站:保压上下气缸原位 没有到位,请检查感应器,气缸,气压,线路等", bmanual);
                if (waranResult == WaranResult.Retry)
                {
                    goto retry_press_up;
                }
            }
        }
        protected override bool InitStation()
        {
            ParamSetMgr.GetInstance().SetBoolParam("Socket流水线初始化完成", false);
            SocketMgr.GetInstance().ResetAllSocket();
            AlarmMgr.GetIntance().DoWhenAlarmEvent += DoSomethingWhenalarm;
            WaranResult waranResult;

            Info("Y轴气缸伸出");
check_cyliderYout:
            IOMgr.GetInstace().WriteIoBit("Y轴气缸电磁阀", true);
            waranResult = CheckIobyName("Y轴气缸1到位", true, "Socket流水站:流水线自检  Y轴气缸移动伸出, 没到位可能卡住,,请拿开");
            if (waranResult == WaranResult.Retry)
            {
                goto check_cyliderYout;
            }
            waranResult = CheckIobyName("Y轴气缸2到位", true, "Socket流水站:流水线自检  Y轴气缸移动伸出, 没到位可能卡住,,请拿开");
            if (waranResult == WaranResult.Retry)
            {
                goto check_cyliderYout;
            }

            Info("Y轴气缸退回");
check_cyliderYback:
            IOMgr.GetInstace().WriteIoBit("Y轴气缸电磁阀", false);

            waranResult = CheckIobyName("Y轴气缸1原位", true, "Socket流水站:流水线自检 Y轴气缸移动退回, 没到位可能卡住,,请拿开");
            if (waranResult == WaranResult.Retry)
            {
                goto check_cyliderYback;
            }
            waranResult = CheckIobyName("Y轴气缸2原位", true, "Socket流水站:流水线自检 Y轴气缸移动退回, 没到位可能卡住,,请拿开");
            if (waranResult == WaranResult.Retry)
            {
                goto check_cyliderYback;
            }
            Info("X轴气缸伸出");
check_cyliderXout:
            IOMgr.GetInstace().WriteIoBit("X轴气缸电磁阀", true);
            waranResult = CheckIobyName("X轴气缸1到位", true, "Socket流水站: 流水线自检 X轴气缸伸出, 没到位可能卡住,,请拿开");
            if (waranResult == WaranResult.Retry)
            {
                goto check_cyliderXout;
            }
            waranResult = CheckIobyName("X轴气缸2到位", true, "Socket流水站: 流水线自检 X轴气缸伸出, 没到位可能卡住,,请拿开");
            if (waranResult == WaranResult.Retry)
            {
                goto check_cyliderXout;
            }

            Info("X轴气缸退回");
check_cyliderXback:
            IOMgr.GetInstace().WriteIoBit("X轴气缸电磁阀", false);
            waranResult = CheckIobyName("Y轴气缸1原位", true, "Socket流水站: 流水线自检 X轴气缸退回, 没到位可能卡住,,请拿开");
            if (waranResult == WaranResult.Retry)
            {
                goto check_cyliderXback;
            }
            waranResult = CheckIobyName("X轴气缸2原位", true, "Socket流水站:流水线自检 X轴气缸退回, 没到位可能卡住,,请拿开");
            if (waranResult == WaranResult.Retry)
            {
                goto check_cyliderXback;
            }



            PushMultStep((int)StationStep.step_init);
            ParamSetMgr.GetInstance().SetBoolParam("Socket流水线初始化完成", true);
            return(true);
        }
示例#20
0
文件: Hall.cs 项目: ingex0/smarttank
        void OnReceivePack(stPkgHead head, byte[] data)
        {
            if (head.iSytle == 40)
            {
                head.iSytle = 40;
            }
            if (head.iSytle == 33)
            {
                //刷房间列表成功
                string   str;
                RoomInfo room;
                byte[]   tmpData;
                roomList.Clear();

                tmpData = new byte[head.dataSize];

                for (int i = 0; i < head.dataSize; i += 36)
                {
                    str = "";
                    //data.Read(roomBuffer, 0, 32);

                    for (int k = 0; k < 36; ++k)
                    {
                        tmpData[k] = data[i + k];
                    }

                    room = (RoomInfo)SocketMgr.BytesToStuct(tmpData, typeof(RoomInfo));

                    for (int j = 0; room.name[j] != '\0'; ++j)
                    {
                        str += room.name[j];
                    }


                    roomList.AddItem(" " + str + " ( " + room.players + " / 2 )", room.id);
                }
            }
            else if (head.iSytle == 35)
            {
                //创建房间成功
                bWaitEnter = false;

                headSend          = new stPkgHead();
                Stream            = new MemoryStream();
                headSend.dataSize = 0;
                headSend.iSytle   = 33;
                SocketMgr.SendCommonPackge(headSend, Stream);
                Stream.Close();
                bInRoom = true;

                headSend          = new stPkgHead();
                Stream            = new MemoryStream();
                headSend.dataSize = 0;
                headSend.iSytle   = 34;
                SocketMgr.SendCommonPackge(headSend, Stream);
                Stream.Close();
            }
            else if (head.iSytle == 36)
            {
                //创建房间失败
                bWaitEnter = false;

                bInRoom = false;
                bIsHost = false;
            }
            else if (head.iSytle == 37)
            {
                //加入房间成功
                bWaitEnter = false;

                headSend          = new stPkgHead();
                Stream            = new MemoryStream();
                headSend.dataSize = 0;
                headSend.iSytle   = 33;
                SocketMgr.SendCommonPackge(headSend, Stream);
                Stream.Close();
                bInRoom = true;

                headSend          = new stPkgHead();
                Stream            = new MemoryStream();
                headSend.dataSize = 0;
                headSend.iSytle   = 34;
                SocketMgr.SendCommonPackge(headSend, Stream);
                Stream.Close();
            }
            else if (head.iSytle == 38)
            {
                //加入房间失败
                bWaitEnter = false;

                bInRoom = false;
                bIsHost = false;
            }
            else if (head.iSytle == 34)
            {
                //列举用户信息


                string   str;
                UserInfo player;
                byte[]   tmpData;

                Monitor.Enter(heads);
                Monitor.Enter(ranks);
                Monitor.Enter(scores);
                heads.Clear();
                ranks.Clear();
                scores.Clear();



                tmpData = new byte[head.dataSize];
                bIsHost = false;
                string[] tmpNames  = new string[6];
                int      playerNum = 0;
                for (int i = 0; i < head.dataSize; i += 56)
                {
                    str = "";
                    //data.Read(roomBuffer, 0, 32);

                    for (int k = 0; k < 56; ++k)
                    {
                        tmpData[k] = data[i + k];
                    }

                    player = (UserInfo)SocketMgr.BytesToStuct(tmpData, typeof(UserInfo));

                    for (int j = 0; player.name[j] != '\0'; ++j)
                    {
                        str += player.name[j];
                    }
                    if (str == myName && player.state == 1)
                    {
                        bIsHost = true;
                    }
                    tmpNames[playerNum] = str;//, Font font)
                    ranks.Add(player.rank);
                    scores.Add(player.score);
                    Texture2D tex;
                    if (devHeads.Contains(str))
                    {
                        tex = BaseGame.ContentMgr.Load <Texture2D>(Path.Combine(Directories.UIContent, str));
                    }
                    else
                    {
                        tex = BaseGame.ContentMgr.Load <Texture2D>(Path.Combine(Directories.UIContent, "head"));
                    }
                    if (tex == null)
                    {
                        throw new Exception("");
                    }



                    heads.Add(tex);
                    playerNum++;

                    //roomList.AddItem("room 1" + " ( " + room.players + " / 6 )", room.id);
                }
                playerCount = playerNum;

                userNames = new string[playerNum];
                for (int i = 0; i < playerNum; i++)
                {
                    userNames[i] = tmpNames[i];
                }

                Monitor.Exit(scores);
                Monitor.Exit(ranks);
                Monitor.Exit(heads);

                headSend          = new stPkgHead();
                Stream            = new MemoryStream();
                headSend.dataSize = 0;
                headSend.iSytle   = 33;
                SocketMgr.SendCommonPackge(headSend, Stream);
                Stream.Close();
            }
            else if (head.iSytle == 70)
            {
                //开始游戏
                bWaitEnter = false;
                if (bIsHost)
                {
                    GameManager.AddGameScreen(new StarwarLogic(0, userNames));
                }
                else
                {
                    for (int i = 0; i < playerCount; i++)
                    {
                        if (userNames[i] == myName)
                        {
                            GameManager.AddGameScreen(new StarwarLogic(i, userNames));
                        }
                    }
                }
            }
            else if (head.iSytle == 71)
            {
                bWaitEnter = false;
            }
        }
示例#21
0
 void Start()
 {
     mSocketMgr = new SocketMgr();
 }
示例#22
0
        public Rank()
        {
            devHeads = new List <string>();
            devHeads.Add("asokawu");
            devHeads.Add("ddli");
            devHeads.Add("jehutyhu");
            devHeads.Add("zashchen");
            devHeads.Add("orrischen");
            devHeads.Add("johntan");
            devHeads.Add("seekyao");

            BaseGame.ShowMouse = true;


            rankPos = new Vector2(50, 120);

            roomList       = new Listbox("roomlist", new Vector2(550, 120), new Point(200, 150), Color.White, Color.Black);
            rankList       = new Listbox("ranklist", rankPos, new Point(450, 350), Color.White, Color.Green);
            bgTexture      = BaseGame.ContentMgr.Load <Texture2D>(Path.Combine(Directories.BgContent, "bg"));
            rkTexture      = BaseGame.ContentMgr.Load <Texture2D>(Path.Combine(Directories.UIContent, "ranklist"));
            piTexture      = BaseGame.ContentMgr.Load <Texture2D>(Path.Combine(Directories.UIContent, "yourinfo"));
            bgRect         = new Rectangle(0, 0, 800, 600);
            btnOK          = new TextButton("OKBtn", new Vector2(550, 370), "OK", 0, Color.Gold);
            btnOK.OnClick += new EventHandler(btnOK_OnPress);
            rankList.OnChangeSelection += new EventHandler(rankList_OnChangeSelection);
            roomList.OnChangeSelection += new EventHandler(roomList_OnChangeSelection);
            SocketMgr.OnReceivePkg     += new SocketMgr.ReceivePkgEventHandler(OnReceivePack);



            stPkgHead head = new stPkgHead();

            //head.iSytle = //包头类型还没初始化
            byte[] rankcode = new byte[4];
            rankcode[0] = 1;
            rankcode[1] = 0;
            rankcode[2] = 0;
            rankcode[3] = 0;

            MemoryStream Stream = new MemoryStream();

            Stream.Write(rankcode, 0, 4);
            head.dataSize = 4;
            head.iSytle   = 50;
            SocketMgr.SendCommonPackge(head, Stream);
            Stream.Close();


            stPkgHead    head2   = new stPkgHead();
            MemoryStream Stream2 = new MemoryStream();

            head2.dataSize = 0;
            head2.iSytle   = 40;
            SocketMgr.SendCommonPackge(head2, Stream2);
            Stream2.Close();

            head = new stPkgHead();
            //head.iSytle = //包头类型还没初始化
            rankcode    = new byte[4];
            rankcode[0] = 1;
            rankcode[1] = 0;
            rankcode[2] = 0;
            rankcode[3] = 0;

            Stream = new MemoryStream();
            Stream.Write(rankcode, 0, 4);
            head.dataSize = 4;
            head.iSytle   = 50;
            SocketMgr.SendCommonPackge(head, Stream);
            Stream.Close();

            bOK       = false;
            rankItems = new List <RankIF>();
            bLoaded   = false;
            // 连接到服务器
            //SocketMgr.ConnectToServer();
        }
示例#23
0
        void OnReceivePack(stPkgHead head, byte[] data)
        {
            byte[] tmpData;

            tmpData = new Byte[head.dataSize];

            if (head.iSytle == 50)
            {
                RankInfo ri;
                RankIF   tmpItem;
                string   str;
                rankItems.Clear();



                for (int i = 0; i < head.dataSize; i += 32)
                {
                    str = "";
                    for (int k = 0; k < 32; k++)
                    {
                        tmpData[k] = data[i + k];
                    }
                    ri = (RankInfo)SocketMgr.BytesToStuct(tmpData, typeof(RankInfo));
                    for (int j = 0; ri.name[j] != '\0'; ++j)
                    {
                        str += ri.name[j];
                    }
                    tmpItem.rank  = ri.rank;
                    tmpItem.score = ri.score;
                    tmpItem.name  = str;
                    rankItems.Add(tmpItem);
                }
            }
            else if (head.iSytle == 40)
            {
                UserInfo player;
                string   str;
                str = "";
                //data.Read(roomBuffer, 0, 32);

                player = (UserInfo)SocketMgr.BytesToStuct(data, typeof(UserInfo));

                for (int j = 0; player.name[j] != '\0'; ++j)
                {
                    str += player.name[j];
                }

                myInfo.name  = str;
                myInfo.rank  = player.rank;
                myInfo.score = player.score;

                if (devHeads.Contains(myInfo.name))
                {
                    hdTexture = BaseGame.ContentMgr.Load <Texture2D>(Path.Combine(Directories.UIContent, myInfo.name));
                }
                else
                {
                    hdTexture = BaseGame.ContentMgr.Load <Texture2D>(Path.Combine(Directories.UIContent, "head"));
                }
                bLoaded = true;
            }
        }
示例#24
0
 public void OnClose()
 {
     //heartTimer.Stop();
     SocketMgr.OnReceivePkg -= OnReceivePack;
     SocketMgr.Close();
 }
示例#25
0
 public override void HandleReqest(ActionCode action, string data)
 {
     SocketMgr.SendRequest(requestCode, ActionCode.Login, data);
 }