public void ActLogic(List <T_GelStep> act_group, List <T_GelStep> act_group_next, double dt)
        {
            if (act_group != null && act_group.Count != 0 && act_group[0].State == 0)
            {
                int next_state    = 2;
                var seque_act     = Sequence.create();
                var exper_package = ((ExperimentPackage)act_group[0].ExperPackage);
                seque_act.exp_pack = exper_package;
                AbstractCanDevice device = null;
                foreach (var act in act_group)
                {
                    resmanager.tip_count += act.InjectCount;
                }
                if (act_group[0].InjectCount != 0)
                {
                    var act_next = act_group_next == null ? null : act_group_next[0];
                    device = injectorDevice;
                    act_group.Sort((a, b) => { return(((ExperimentPackage)a.ExperPackage).piercer_index > ((ExperimentPackage)b.ExperPackage).piercer_index ? 1 : -1); });
                    seque_act = generater.GenerateAction(act_group);
                    if (act_next != null && act_next.InjectCount == 0)
                    {
                        seque_act.AddAction(SkCallBackFun.create((ActionBase act_tem) =>
                        {
                            inj_wait_time = 9999;
                            return(true);
                        }));
                    }
                }
                else
                {
                    var act      = act_group[0];
                    var act_next = act_group_next == null ? null : act_group_next[0];
                    var resinfo  = resmanager.GetResByCode(exper_package.GetGelMask(), "T_BJ_GelSeat");
                    if (resinfo == null)
                    {
                        resinfo = resmanager.GetResByCode(exper_package.GetGelMask(), "T_BJ_Centrifuge");
                    }
                    if ((resinfo == null || !resinfo.PutOk) && act.StepClass != TestStepEnum.LoadGel)
                    {
                        return;
                    }
                    switch (act.StepClass)
                    {
                    case TestStepEnum.LoadGel:
                    {
                        if (actionmanager.getAllActionsCount(handDevice) == 0)
                        {
                            var take_seat  = resmanager.GetResByCode(exper_package.GetGelMask(), "T_BJ_GelSeat", "", "3");
                            var paper_seat = resmanager.GetResByCode("null", "T_BJ_GelSeat", "", "4", null, exper_package.is_crossmatching);
                            if (paper_seat != null)
                            {
                                device = handDevice;
                                if (take_seat != null)
                                {
                                    generater.GenerateTakeGelFromNormal(take_seat, ref seque_act);
                                }
                                else
                                {
                                    seque_act.AddAction(HandTakeGelFromWare.create(handDevice, 3001, gelwareDevice, exper_package.gel_mask_id, exper_package.GetGelMask(), exper_package.GetSampleCode(act.SampleIndex)));
                                }
                                seque_act.AddAction(HandPutGelToNormal.create(handDevice, 3001, gelwareDevice, paper_seat));
                                if (act_next != null && act_next.StepClass != TestStepEnum.LoadGel)
                                {
                                    seque_act.AddAction(SkCallBackFun.create((ActionBase act_tem) => {
                                            hand_wait_time = 999999;
                                            var ware_act   = MoveTo.create(gelwareDevice, 3000, 0);
                                            ware_act.runAction(gelwareDevice);
                                            return(true);
                                        }));
                                }
                                exper_package.piercer_index             = paper_seat.CountX;
                                paper_seat.Values[paper_seat.CountX, 0] = new ResInfoData();
                                seque_act.destroyfun = (ActionBase act_tem) =>
                                {
                                    paper_seat.Values[paper_seat.CountX, 0] = null;
                                    return(true);
                                };
                                next_state = 2;
                            }
                            else
                            {
                                next_state = 0;
                            }
                        }
                        else
                        {
                            next_state = 0;
                        }
                    }
                    break;

                    case TestStepEnum.KaiKongGel:
                    {
                        int handrx      = 0;
                        int injrx       = 0;
                        var device_hand = new ActionDevice(handDevice);
                        var device_inj  = new ActionDevice(injectorDevice);
                        next_state = 0;
                        if (resinfo.Purpose != "4")
                        {
                            var put_seat = resmanager.GetResByCode("null", "T_BJ_GelSeat", "", "4");
                            if (put_seat == null && resinfo.Purpose != "3")
                            {
                                put_seat = resmanager.GetResByCode("null", "T_BJ_GelSeat", "", "3");
                            }
                            if (put_seat != null)
                            {
                                device = handDevice;
                                ResInfoData put_gel = null;
                                if (resinfo.Purpose == "lxj")
                                {
                                    put_gel = generater.GenerateTakeGelFromCent(resinfo, resinfo.CenCode, ref seque_act);
                                }
                                else
                                {
                                    put_gel = generater.GenerateTakeGelFromNormal(resinfo, ref seque_act);
                                }
                                generater.GeneratePutGelToNormal(put_seat, put_gel, ref seque_act);
                                next_state = 0;
                            }
                        }
                        else
                        {
                            bool is_next_kaikong = act_next != null ? act_next.StepClass == TestStepEnum.KaiKongGel : false;
                            var  paper_seat      = resmanager.GetResByCode(exper_package.GetGelMask(), "T_BJ_GelSeat", "", "4");
                            int  yb = is_next_kaikong ? -1 : 0;
                            if (paper_seat != null &&
                                device_hand.GetRealX(ref handrx) &&
                                (handrx + 1000) < paper_seat.X && ActionDevice.hand_tx < paper_seat.X &&
                                device_inj.GetRealX(ref injrx) &&
                                (injrx + 1000) < paper_seat.InjectorX && ActionDevice.inj_tx < paper_seat.InjectorX + 1000)
                            {
                                device = piercerDevice;
                                seque_act.AddAction(PaperCard.create(piercerDevice, 3000, paper_seat, yb));
                                seque_act.AddAction(SkCallBackFun.create((ActionBase acttem) =>
                                    {
                                        exper_package.is_open = true;
                                        resmanager.gel_count++;
                                        return(true);
                                    }));
                                next_state = 2;
                            }
                        }
                    }
                    break;

                    case TestStepEnum.JYJS:
                    {
                        exper_package.is_jyjs = true;
                        next_state            = 2;
                    }
                    break;

                    case TestStepEnum.ZKDFY:
                    {
                        next_state = 0;
                        if (resinfo.Purpose == "1")
                        {
                            next_state = 0;
                            exper_package.hatch_cur_time += dt;
                            if (exper_package.hatch_cur_time >= exper_package.hatch_time)
                            {
                                next_state = 2;
                            }
                        }
                        else if (!(resinfo.Purpose == "4" && actionmanager.getAllActionsCount(piercerDevice) != 0))
                        {
                            var put_seat = resmanager.GetResByCode("null", "T_BJ_GelSeat", "", "1");
                            if (put_seat == null && resinfo.Purpose != "3")
                            {
                                put_seat = resmanager.GetResByCode("null", "T_BJ_GelSeat", "", "3");
                            }
                            if (put_seat != null)
                            {
                                device = handDevice;
                                ResInfoData put_gel = null;
                                if (resinfo.Purpose == "lxj")
                                {
                                    put_gel = generater.GenerateTakeGelFromCent(resinfo, resinfo.CenCode, ref seque_act);
                                }
                                else
                                {
                                    put_gel = generater.GenerateTakeGelFromNormal(resinfo, ref seque_act);
                                }
                                exper_package.hatch_cur_time = 0;
                                generater.GeneratePutGelToNormal(put_seat, put_gel, ref seque_act);
                                next_state = 0;
                            }
                            else
                            {
                                next_state = 0;
                            }
                        }
                    }
                    break;

                    case TestStepEnum.ZKDLXJ:
                    {
                        if (actionmanager.getAllActionsCount(handDevice) == 0)
                        {
                            next_state = 0;
                            if (resinfo.Purpose != "lxj" && !(resinfo.Purpose == "4" && actionmanager.getAllActionsCount(piercerDevice) != 0))
                            {
                                //查看可用离心机
                                var centrifuge_list = resmanager.centrifuge_list.Where(item => item.Status == 1).ToList();
                                centrifuge_list.Sort((a, b) => { return(a.LastUseTime < b.LastUseTime ? 1 : -1); });
                                foreach (var seat in centrifuge_list)
                                {
                                    CentrifugeMDevice cendev = cenMrg.GetCentrifugeByCode(seat.Code);
                                    if (seat.Status == 1 && cendev != null)
                                    {
                                        device = handDevice;
                                        bool is_last_cent = seat == centrifuge_list[centrifuge_list.Count - 1];
                                        bool iscanputcen  = IsCanPutCen(cendev);
                                        var  put_seat     = resmanager.GetResByCode("null", "T_BJ_Centrifuge", cendev.Centrifugem.Code.SetValue);
                                        if (iscanputcen == false)
                                        {
                                            put_seat = null;
                                        }
                                        //放进待定位
                                        if (put_seat == null && resinfo.Purpose != "3" && is_last_cent)
                                        {
                                            put_seat = resmanager.GetResByCode("null", "T_BJ_GelSeat", "", "3");
                                        }
                                        if (put_seat != null)
                                        {
                                            var spaw      = Spawn.create();
                                            var put_seque = Sequence.create();
                                            if (put_seat.Purpose == "lxj")
                                            {
                                                //打开离心机门
                                                var opendoor_act = HandOpenCloseDoor.create(handDevice, 5000, cendev.Centrifugem.Code.SetValue, true);
                                                put_seque.AddAction(opendoor_act);
                                            }
                                            var put_gel = generater.GenerateTakeGelFromNormal(resinfo, ref put_seque);
                                            spaw.AddAction(put_seque);
                                            seque_act.AddAction(spaw);
                                            if (put_seat.Purpose == "lxj")
                                            {
                                                spaw.AddAction(MoveTo.create(cendev, 30001, -1, -1, put_seat.CenGelP[put_seat.CountX]));
                                                generater.GeneratePutGelToCent(cendev.Centrifugem.Code.SetValue, put_seat, put_gel, ref seque_act);
                                            }
                                            else
                                            {
                                                generater.GeneratePutGelToNormal(put_seat, put_gel, ref seque_act);
                                            }
                                            seat.LastUseTime = Engine.getInstance().getSystemMs();
                                            break;
                                        }
                                        else
                                        {
                                            next_state = 0;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            next_state = 0;
                        }
                    }
                    break;

                    case TestStepEnum.PutPeiGelBack:
                    {
                        var put_seat = resmanager.GetResByCode("null", "T_BJ_GelSeat", "", "2");
                        if (put_seat != null && resinfo.Purpose == "lxj")
                        {
                            device = handDevice;
                            var put_gel = generater.GenerateTakeGelFromCent(resinfo, resinfo.CenCode, ref seque_act);
                            generater.GeneratePutGelToNormal(put_seat, put_gel, ref seque_act);
                            next_state = 2;
                        }
                    }
                    break;

                    case TestStepEnum.XJPD:
                    {
                        var put_seat     = resmanager.GetResByCode("", "T_BJ_Camera");               //相机位
                        var wasted_seat  = resmanager.GetResByCode("", "T_BJ_WastedSeat", "", "1");  //垃圾位
                        var daiding_seat = resmanager.GetResByCode("null", "T_BJ_GelSeat", "", "3"); //待定位
                        if (put_seat != null && wasted_seat != null && !(resinfo.Purpose == "4" && actionmanager.getAllActionsCount(piercerDevice) != 0))
                        {
                            device = handDevice;
                            ResInfoData put_gel = null;
                            if (resinfo.Purpose == "lxj")
                            {
                                put_gel = generater.GenerateTakeGelFromCent(resinfo, resinfo.CenCode, ref seque_act);
                            }
                            else
                            {
                                put_gel = generater.GenerateTakeGelFromNormal(resinfo, ref seque_act);
                            }

                            seque_act.AddAction(MoveTo.create(handDevice, 3000, -1, -1, 0));
                            seque_act.AddAction(MoveTo.create(handDevice, 3000, (int)put_seat.X, (int)(put_seat.Y), -1));
                            seque_act.AddAction(MoveTo.create(handDevice, 3000, -1, -1, (int)(put_seat.Z)));
                            //拍照分析
                            seque_act.AddAction(SkCallBackFun.create((ActionBase acttem) =>
                                {
                                    opDevice.CameraLight(true);
                                    bool result = true;
                                    if (cameraDevice.IsOpen == false)
                                    {
                                        result = cameraDevice.Open();
                                    }
                                    var bm = cameraDevice.CaptureImage();
                                    cameraDevice.Save(bm, exper_package);
                                    opDevice.CameraLight(false);
                                    return(true);
                                }));
                            //是否还有动作
                            if (exper_package.action_list.Count > 1 && daiding_seat != null)
                            {
                                seque_act.AddAction(MoveTo.create(handDevice, 3000, -1, -1, 0));
                                generater.GeneratePutGelToNormal(daiding_seat, put_gel, ref seque_act);
                            }
                            else
                            {
                                seque_act.AddAction(MoveTo.create(handDevice, 3000, -1, -1, 0));
                                seque_act.AddAction(MoveTo.create(handDevice, 3000, (int)wasted_seat.X, (int)(wasted_seat.Y)));
                                seque_act.AddAction(HandPutCard.create(handDevice, 3000, (int)wasted_seat.ZPut, 0));
                                seque_act.AddAction(SkCallBackFun.create((ActionBase act_tem) => {
                                        DelPackage(exper_package);
                                        return(true);
                                    }));
                            }
                            next_state = 2;
                        }
                    }
                    break;

                    case TestStepEnum.ECONOMIZECOUNTTIME:
                    {
                        next_state = 0;
                        if (exper_package.is_open)
                        {
                            exper_package.after_kktime -= dt;
                            if (exper_package.after_kktime <= 0)
                            {
                                device     = handDevice;
                                next_state = 2;
                                exper_package.after_kktime = 0;
                                ResInfoData put_gel = null;
                                if (resinfo.Purpose == "lxj")
                                {
                                    put_gel = generater.GenerateTakeGelFromCent(resinfo, resinfo.CenCode, ref seque_act);
                                }
                                else
                                {
                                    put_gel = generater.GenerateTakeGelFromNormal(resinfo, ref seque_act);
                                }

                                var wasted_seat = resmanager.GetResByCode("", "T_BJ_WastedSeat");        //垃圾位
                                seque_act.AddAction(MoveTo.create(handDevice, 3000, -1, -1, 0));
                                seque_act.AddAction(MoveTo.create(handDevice, 3000, (int)wasted_seat.X, (int)(wasted_seat.Y)));
                                seque_act.AddAction(HandPutCard.create(handDevice, 3000, (int)wasted_seat.ZPut, 0));
                            }
                        }
                    }
                    break;
                    }
                }
                if (device != null)
                {
                    seque_act.AddAction(SkCallBackFun.create((ActionBase act) =>
                    {
                        foreach (var act_tem in act_group)
                        {
                            act_tem.State = next_state;
                        }
                        return(true);
                    }));
                    foreach (var act_tem in act_group)
                    {
                        act_tem.State = 1;
                    }
                    seque_act.runAction(device);
                }
                else
                {
                    foreach (var act_tem in act_group)
                    {
                        act_tem.State = next_state;
                    }
                }
            }
        }
예제 #2
0
        public void Logic(ResInfoData resinfo, double dt)
        {
            switch (resinfo.GetActionAt(0))
            {
            case ActionPointType.Hatch:
            {
                if (resinfo.Purpose == "1")
                {
                    resinfo.HatchCurTime += dt;
                    if (resinfo.HatchCurTime >= resinfo.HatchTime)
                    {
                        resinfo.RemoveActionAt(0);
                    }
                }
                else if (!(resinfo.Purpose == "4" && actionmanager.getAllActionsCount(piercerDevice) != 0))
                {
                    var seque    = Sequence.create();
                    var put_seat = resmanager.GetResByCode("null", "T_BJ_GelSeat", "", "1");
                    if (put_seat == null && resinfo.Purpose != "3")
                    {
                        put_seat = resmanager.GetResByCode("null", "T_BJ_GelSeat", "", "3");
                    }
                    if (put_seat != null)
                    {
                        ResInfoData put_gel = null;
                        if (resinfo.Purpose == "lxj")
                        {
                            //CentrifugeMDevice cendev = cenMrg.GetCentrifugeByCode(resinfo.CenCode);
                            //seque.AddAction(MoveTo.create(cendev, 30000, -1, -1, 0));
                            //seque.AddAction(InitXyz.create(cendev, 30000, false, false, true));
                            put_gel = generater.GenerateTakeGelFromCent(resinfo, resinfo.CenCode, ref seque);
                        }
                        else
                        {
                            put_gel = generater.GenerateTakeGelFromNormal(resinfo, ref seque);
                        }
                        put_gel.HatchCurTime = 0;
                        generater.GeneratePutGelToNormal(put_seat, put_gel, ref seque);
                        seque.runAction(handDevice);
                    }
                }
            }
            break;

            case ActionPointType.Centrifugal:
            {
                if (resinfo.Purpose != "lxj" && !(resinfo.Purpose == "4" && actionmanager.getAllActionsCount(piercerDevice) != 0))
                {
                    foreach (var seat in resmanager.centrifuge_list)
                    {
                        CentrifugeMDevice cendev = cenMrg.GetCentrifugeByCode(seat.Code);
                        if (seat.Status == 1 && cendev != null)
                        {
                            bool iscanputcen = IsCanPutCen(cendev);
                            var  seque       = Sequence.create();
                            var  put_seat    = resmanager.GetResByCode("null", "T_BJ_Centrifuge", cendev.Centrifugem.Code.SetValue);
                            if (iscanputcen == false)
                            {
                                put_seat = null;
                            }
                            if (put_seat == null && resinfo.Purpose != "3")
                            {
                                put_seat = resmanager.GetResByCode("null", "T_BJ_GelSeat", "", "3");
                            }
                            if (put_seat != null)
                            {
                                var spaw      = Spawn.create();
                                var put_seque = Sequence.create();
                                var put_gel   = generater.GenerateTakeGelFromNormal(resinfo, ref put_seque);
                                spaw.AddAction(put_seque);
                                seque.AddAction(spaw);
                                if (put_seat.Purpose == "lxj")
                                {
                                    spaw.AddAction(MoveTo.create(cendev, 30001, -1, -1, put_seat.CenGelP[put_seat.CountX]));
                                    generater.GeneratePutGelToCent(cendev.Centrifugem.Code.SetValue, put_seat, put_gel, ref seque);
                                }
                                else
                                {
                                    generater.GeneratePutGelToNormal(put_seat, put_gel, ref seque);
                                }
                                seque.runAction(handDevice);
                                break;
                            }
                        }
                    }
                }
            }
            break;

            case ActionPointType.PutPeiGelBack:
            {
                var seque    = Sequence.create();
                var put_seat = resmanager.GetResByCode("null", "T_BJ_GelSeat", "", "2");
                if (put_seat != null && resinfo.Purpose == "lxj")
                {
                    //CentrifugeMDevice cendev = cenMrg.GetCentrifugeByCode(resinfo.CenCode);
                    //seque.AddAction(MoveTo.create(cendev, 30000, -1, -1, 0));
                    //seque.AddAction(InitXyz.create(cendev, 30000, false, false, true));
                    var put_gel = generater.GenerateTakeGelFromCent(resinfo, resinfo.CenCode, ref seque);
                    generater.GeneratePutGelToNormal(put_seat, put_gel, ref seque);
                    seque.AddAction(SkCallBackFun.create((ActionBase acttem) => {
                            resinfo.RemoveActionAt(0);
                            return(true);
                        }));
                    seque.runAction(handDevice);
                }
            }
            break;

            case ActionPointType.Camera:
            {
                var seque       = Sequence.create();
                var put_seat    = resmanager.GetResByCode("", "T_BJ_Camera");
                var wasted_seat = resmanager.GetResByCode("", "T_BJ_WastedSeat");
                if (put_seat != null && wasted_seat != null && !(resinfo.Purpose == "4" && actionmanager.getAllActionsCount(piercerDevice) != 0))
                {
                    ResInfoData put_gel = null;
                    if (resinfo.Purpose == "lxj")
                    {
                        //CentrifugeMDevice cendev = cenMrg.GetCentrifugeByCode(resinfo.CenCode);
                        //seque.AddAction(MoveTo.create(cendev, 30000, -1, -1, 0));
                        //seque.AddAction(InitXyz.create(cendev, 30000, false, false, true));
                        put_gel = generater.GenerateTakeGelFromCent(resinfo, resinfo.CenCode, ref seque);
                    }
                    else
                    {
                        put_gel = generater.GenerateTakeGelFromNormal(resinfo, ref seque);
                    }

                    seque.AddAction(MoveTo.create(handDevice, 3000, -1, -1, 0));
                    seque.AddAction(MoveTo.create(handDevice, 3000, (int)put_seat.X, (int)(put_seat.Y), -1));
                    seque.AddAction(MoveTo.create(handDevice, 3000, -1, -1, (int)(put_seat.Z)));
                    //拍照分析
                    seque.AddAction(SkCallBackFun.create((ActionBase acttem) =>
                        {
                            bool result = true;
                            if (cameraDevice.IsOpen == false)
                            {
                                result = cameraDevice.Open();
                            }
                            var bm      = cameraDevice.CaptureImage();
                            var bag     = new TestBag(Common.Enums.TestLevelEnum.Normal);
                            var gel     = new Gel(resinfo.GetGelMask());
                            bag.GelType = resinfo.gel;
                            bag.Add(resinfo.GetSampleBarcode(), (byte)resinfo.GetSampleRackIndex(), (byte)resinfo.CountX);
                            bag.SetStartTime(resinfo.StartTime);
                            gel.SampleBarcodes.Add(resinfo.GetSampleBarcode());
                            cameraDevice.Save(bag, gel, bm, "888");
                            //cameraDevice.Close();
                            put_gel.RemoveActionAt(0);
                            return(true);
                        }));
                    seque.AddAction(MoveTo.create(handDevice, 3000, (int)wasted_seat.X, (int)(wasted_seat.Y)));
                    seque.AddAction(HandPutCard.create(handDevice, 3000, (int)wasted_seat.ZPut, 0));
                    seque.runAction(handDevice);
                }
            }
            break;
            }
        }