public static void DoEntrySideJobs(MachinesDTO senderMachine)
        {
            productId        = random.Next(1, 30);
            productionlineId = random.Next(1, 22);
            paletteBarcode   = "palettebarcode" + productId.ToString();
            boxquantity      = random.Next(50, 100);
            lot   = "lot" + productId.ToString();
            batch = "BT382020";

            easyModbusCommunication = new EasyModbusCommunication(senderMachine.IpAddress, 502);
            easyModbusCommunication.WriteToPLC(0, new int[] { 100 });//plcden ye done göndermesi için

            //Console.SetOut(TextWriter.Null);
            var rd = ReadConveyorPLC(senderMachine);
            //Console.SetOut(TextWriter.Synchronized(writer));

            var id = easyModbusCommunication.ConvertRegistersToInt(new int[] { rd.MW202, rd.MW203 });

            if (rd.MW200 == (int)Plc_Task.DONESUCCESSFULLY)
            {
                var pnId = InsertProductionNotification();//plc den gelen datayla beslenecek gibi düşün
                CreateTaskForPalette(paletteBarcode, senderMachine, pnId /*obj den gelen bir data veri barkod üzerine sistem kayıtlarını oluştur.*/);
            }

            //WriteDataToPlc();
        }
示例#2
0
        private static void CreateChargeTasks(MachinesDTO communicationMachine, Shuttle shuttle)
        {
            var asrs        = asrsData.GetAllAsrs().First(x => x.Location == Location.WH_OUT);
            var taskBatch   = machineTasksData.GetNewTaskBatch();
            var chrgAddress = addressData.GetAvailableChargeAddress();

            MachineTask opt1 = new MachineTask //asrs shuttle taşıma
            {
                OrderDetailPalletId   = 0,
                ProductNotificationId = 0,
                TaskType      = (int)TaskType.ShCHRG,
                TaskBatch     = taskBatch,
                Sequence      = 1,
                MachineCode   = asrs.Code,
                SourceType    = AddressType.ADDRESS,
                SourceAddress = shuttle.LastAddress,
                LoadInfo      = shuttle.Code,
                TargetType    = AddressType.ADDRESS,
                TargetAddress = chrgAddress,
                AssignUser    = "******",
                AssignReason  = "Charge",
                AssignTime    = DateTime.Now,
                StartTime     = null,
                EndTime       = null,
                SentFlag      = false,
                IsCompleted   = false,
                ErrorCode     = null
            };

            machineTasksData.InsertMachineTaskBatch(new List <MachineTask> {
                opt1
            });
        }
 public static PlcCommunicationWritedData IntArrayToObject_WD(int[] array, MachinesDTO machinesDTO)
 {
     return(new PlcCommunicationWritedData
     {
         //Id
         MW100 = array[0],
         MW101 = array[1],
         MW102 = array[2],
         MW103 = array[3],
         MW104 = array[4],
         MW105 = array[5],
         MW106 = array[6],
         MW107 = array[7],
         MW108 = array[8],
         MW109 = array[9],
         MW110 = array[10],
         MW111 = array[11],
         MW112 = array[12],
         MW113 = array[13],
         MW114 = array[14],
         MW115 = array[15],
         MW116 = array[16],
         MW117 = array[17],
         MW118 = array[18],
         MW119 = array[19],
         MW120 = array[20],
         MW121 = array[21],
         MW122 = array[22],
         MW123 = array[23],
         MW124 = array[24],
         MW125 = array[25],
         MW126 = array[26],
         MW127 = array[27],
         MW128 = array[28],
         MW129 = array[29],
         MW130 = array[30],
         MW131 = array[31],
         MW132 = array[32],
         MW133 = array[33],
         MW134 = array[34],
         MW135 = array[35],
         MW136 = array[36],
         MW137 = array[37],
         MW138 = array[38],
         MW139 = array[39],
         MW140 = array[40],
         MW141 = array[41],
         MW142 = array[42],
         MW143 = array[43],
         MW144 = array[44],
         MW145 = array[45],
         MW146 = array[46],
         MW147 = array[47],
         MW148 = array[48],
         MW149 = array[49],
         MachineCode = machinesDTO.Code,
         RecordDate = DateTime.Now
     });
 }
 public static PlcCommunicationReadedData IntArrayToObject_RD(int[] array, MachinesDTO machinesDTO)
 {
     return(new PlcCommunicationReadedData
     {
         //Id
         MW200 = array[0],
         MW201 = array[1],
         MW202 = array[2],
         MW203 = array[3],
         MW204 = array[4],
         MW205 = array[5],
         MW206 = array[6],
         MW207 = array[7],
         MW208 = array[8],
         MW209 = array[9],
         MW210 = array[10],
         MW211 = array[11],
         MW212 = array[12],
         MW213 = array[13],
         MW214 = array[14],
         MW215 = array[15],
         MW216 = array[16],
         MW217 = array[17],
         MW218 = array[18],
         MW219 = array[19],
         MW220 = array[20],
         MW221 = array[21],
         MW222 = array[22],
         MW223 = array[23],
         MW224 = array[24],
         MW225 = array[25],
         MW226 = array[26],
         MW227 = array[27],
         MW228 = array[28],
         MW229 = array[29],
         MW230 = array[30],
         MW231 = array[31],
         MW232 = array[32],
         MW233 = array[33],
         MW234 = array[34],
         MW235 = array[35],
         MW236 = array[36],
         MW237 = array[37],
         MW238 = array[38],
         MW239 = array[39], //TODO: plc registerları düzeltildiğinde değiştir
         MW240 = array[39], //array[40],
         MW241 = array[39], //array[41],
         MW242 = array[39], //array[42],
         MW243 = array[39], //array[43],
         MW244 = array[39], //array[44],
         MW245 = array[39], //array[45],
         MW246 = array[39], //array[46],
         MW247 = array[39], //array[47],
         MW248 = array[39], //array[48],
         MW249 = array[39], //array[49],
         MachineCode = machinesDTO.Code,
         RecordDate = DateTime.Now
     });
 }
示例#5
0
        private static void CreateOptimizationTasks(MachinesDTO communicationMachine, Shuttle shuttle)
        {
            var asrs      = asrsData.GetAllAsrs().First(x => x.Location == Location.WH_OUT);
            var taskBatch = machineTasksData.GetNewTaskBatch();

            string nextOptAddress = palletsAtAddressesData.GetNextOptimizationNeededAddresses()[0]; //TODO: seç

            MachineTask opt1 = new MachineTask                                                      //asrs shuttle taşıma
            {
                OrderDetailPalletId   = 0,
                ProductNotificationId = 0,
                TaskType      = (int)TaskType.ShOPT,
                TaskBatch     = taskBatch,
                Sequence      = 1,
                MachineCode   = asrs.Code,
                SourceType    = AddressType.ADDRESS,
                SourceAddress = shuttle.LastAddress,
                LoadInfo      = shuttle.Code,
                TargetType    = AddressType.ADDRESS,
                TargetAddress = nextOptAddress,
                AssignUser    = "******",
                AssignReason  = "Optimization",
                AssignTime    = DateTime.Now,
                StartTime     = null,
                EndTime       = null,
                SentFlag      = false,
                IsCompleted   = false,
                ErrorCode     = null
            };

            MachineTask opt2 = new MachineTask //shuttle opt başla
            {
                OrderDetailPalletId   = 0,
                ProductNotificationId = 0,
                TaskType      = (int)TaskType.ShOPT,
                TaskBatch     = taskBatch,
                Sequence      = 2,
                MachineCode   = communicationMachine.Code,
                SourceType    = AddressType.ADDRESS,
                SourceAddress = nextOptAddress,
                LoadInfo      = "",
                TargetType    = AddressType.ADDRESS,
                TargetAddress = nextOptAddress,
                AssignUser    = "******",
                AssignReason  = "Optimization",
                AssignTime    = DateTime.Now,
                StartTime     = null,
                EndTime       = null,
                SentFlag      = false,
                IsCompleted   = false,
                ErrorCode     = null
            };

            machineTasksData.InsertMachineTaskBatch(new List <MachineTask> {
                opt1, opt2
            });
        }
        internal static void DoEntrySideJobs(MachinesDTO senderMachine)
        {
            //simule ok
            easyModbusCommunication = new EasyModbusCommunication(senderMachine.IpAddress, 502);
            easyModbusCommunication.WriteToPLC(0, new int[] { 100 });//plcden ye done göndermesi için
            //


            var rd = ReadAsrsPLC(senderMachine);
            var id = easyModbusCommunication.ConvertRegistersToInt(new int[] { rd.MW202, rd.MW203 });


            if (id > 0 && rd.MW200 == (int)Plc_Task.DONESUCCESSFULLY)
            {
                log.Info(id);


                var incomingTask = machineTasksData.GetMachineTaskById(id);
                var prodNotif    = productionNotificationData.GetProductionNotificationById(incomingTask.ProductNotificationId);

                if (!incomingTask.IsCompleted)
                {
                    if (incomingTask.TaskType == (int)TaskType.CTA)
                    {
                        palletsAtAddressesData.InsertPalettesAtAddresses(incomingTask, prodNotif);
                        addressData.AddressesChangeFirstRowInfo(incomingTask.TargetAddress, false, incomingTask.EndTime, Location.WH_IN);
                        machineTasksData.CreateTaskForFirstRowPalette(incomingTask);
                    }
                    else if (incomingTask.TaskType == (int)TaskType.CTB)
                    {
                        buffersData.UpdateBufferWithPalette(incomingTask); //buffer transaction logu tablosu oluşturup tutulmalı mı?
                        machineTasksData.CreateTaskForBufferPalette(incomingTask);
                    }
                    else if (incomingTask.TaskType == (int)TaskType.BTA) //TODO:check
                    {
                        buffersData.UpdateBufferWithOutPalette(incomingTask);
                        palletsAtAddressesData.InsertPalettesAtAddresses(incomingTask, prodNotif);
                        addressData.AddressesChangeFirstRowInfo(incomingTask.TargetAddress, false, incomingTask.EndTime, Location.WH_IN);
                        machineTasksData.CreateTaskForFirstRowPalette(incomingTask);
                    }

                    machineTasksData.UpdateMachineTaskWithPlcCompletedById(id);
                }


                //task ata
                AssignTask(senderMachine);
            }
            else if (rd.MW200 == (int)Plc_Task.DONEWITHERROR) // hata kontrolu
            {
                //yarım iş??
            }
        }
示例#7
0
        public static PlcCommunicationReadedData ReadShuttlePLC(MachinesDTO communicationMachine)
        {
            easyModbusCommunication = new EasyModbusCommunication(communicationMachine.IpAddress, 502);

            var readedData = easyModbusCommunication.ReadFromPLC(0, 40);

            var rd = ObjectAssign.IntArrayToObject_RD(readedData, communicationMachine);

            readedDataAcces.InsertReadedData(rd);

            return(rd);
        }
示例#8
0
        private void LoadData()
        {
            Logger.AddTrace(string.Format("Loading Machines Configuration from: {0}", _machinesPath));

            _machines = Serializer.Deserialize <MachinesDTO>(_machinesPath);

            if (_machines != null)
            {
                return;
            }

            _machines = new MachinesDTO();
        }
        public TaskDTO GetTaskDataForShuttle(MachinesDTO communicationMachine)
        {
            TaskDTO obj;

            using (var conn = new SqlConnection(conStr))
            {
                conn.Open();
                //TODO: task seçimi optimizasyon için sequence ekle
                obj = conn.QuerySingleOrDefault <TaskDTO>("sp_GetTaskDataForShuttle_sel", new { Code = communicationMachine.Code }, commandType: System.Data.CommandType.StoredProcedure);
                conn.Close();
            }
            return(obj);
        }
示例#10
0
        public static bool WriteShuttlePLC(MachinesDTO communicationMachine, TaskDTO taskDTO)
        {
            var idReg = easyModbusCommunication.ConvertIntToRegisters(taskDTO.taskId);
            var xReg  = easyModbusCommunication.ConvertIntToRegisters(taskDTO.X);
            var z1Reg = easyModbusCommunication.ConvertIntToRegisters(taskDTO.Z1);
            var z2Reg = easyModbusCommunication.ConvertIntToRegisters(taskDTO.Z2);
            var gReg  = easyModbusCommunication.ConvertIntToRegisters(taskDTO.G);

            //task verisine göre plc write datası oluşturup yazılması gerekie.
            PlcCommunicationWritedData wd = new PlcCommunicationWritedData();

            wd.MW100 = 0; //tetik

            wd.MW102 = idReg[0];
            wd.MW103 = idReg[1];

            wd.MW109 = (int)Plc_Asrs.GO;

            wd.MW110 = xReg[0];
            wd.MW111 = xReg[1];

            wd.MW112 = z1Reg[0];
            wd.MW113 = z1Reg[1];

            wd.MW114 = z2Reg[0];
            wd.MW115 = z2Reg[1];

            wd.MW116 = gReg[0];
            wd.MW117 = gReg[1];

            wd.MachineCode = communicationMachine.Code;
            wd.RecordDate  = DateTime.Now;

            easyModbusCommunication = new EasyModbusCommunication(communicationMachine.IpAddress, 502);


            if (easyModbusCommunication.WriteToPLC(0, ArrayAssign.WritedDataToIntArray(wd)))//plc ye yazdıysa
            {
                writedDataAcces.InsertWritedData(wd);
                return(true);
            }
            else
            {
                log.Error($"ASRS Plc Write Error. TaskId : {taskDTO.taskId}");
                return(false);
            }
        }
示例#11
0
        private static void AssignTask(MachinesDTO communicationMachine, PlcCommunicationReadedData rd)
        {
            var shuttle = shuttlesData.GetShuttleByCode(communicationMachine.Code);

            if (shuttle.Assignment == ShuttleAssign.OPTIMIZATION && shuttle.Status == Enum.GetName(typeof(SysStatus), SysStatus.READY))
            {
                //simule ok
                easyModbusCommunication = new EasyModbusCommunication(communicationMachine.IpAddress, 502);
                easyModbusCommunication.WriteToPLC(48, new int[] { 75 }); //plcden ye done göndermesi için
                                                                          //

                //şarjı varsa başka tüpe taşı ve optimizasyon başlat
                if (rd.MW248 > 10)//TODO: make parametric
                {
                    CreateOptimizationTasks(communicationMachine, shuttle);
                }
                else
                {
                    //şarja gönder, başka mekiği optimizasyon için ata, taşı, optimizasyon başlat
                    CreateChargeTasks(communicationMachine, shuttle);
                    shuttlesData.SelectNewOptimizationShuttle(); //yeni shuttle döndürür yeni optimizasyon mekiği için iş atayabilir yada mekikten sinyal gelince normal işleyişe göre çalışır
                }

                //şarjı yoksa şarja taşı, başka mekiği optimizasyon olarak ata, bulunduğu yeri yada başka adresi optimize görevi yaz (önce taşı sonra yaz!)
            }


            //TODO: optimization task seçmede kontrolet
            TaskDTO taskDTO = machineTasksData.GetTaskDataForShuttle(communicationMachine);

            if (taskDTO != null && WriteShuttlePLC(communicationMachine, taskDTO))
            {
                log.Info("shuttle assign id: " + taskDTO.taskId);
                machineTasksData.UpdateMachineTaskWithPlcSentById(taskDTO.taskId);
                machineTasksData.UpdateMachineTaskWithMachineCodeById(taskDTO.taskId, communicationMachine.Code);
            }
            else
            {
                CheckNeedShuttleAddressesAndCreateTaskForIt(communicationMachine);
            }
        }
        private static void AssignTask(MachinesDTO communicationMachine)
        {
            if (communicationMachine.Location == Location.WH_IN)
            {
                TaskDTO taskDTO = machineTasksData.GetTaskDataForEntrySide();

                if (taskDTO != null && WriteAsrsPLC(communicationMachine, taskDTO))
                {
                    log.Info("assign id: " + taskDTO.taskId);
                    machineTasksData.UpdateMachineTaskWithPlcSentById(taskDTO.taskId);
                }
            }
            else if (communicationMachine.Location == Location.WH_OUT)
            {
                //TODO: adres ağzı dolu olanın taskı atanmalı
                //shuttle getirdiğinde
                TaskDTO taskDTO = machineTasksData.GetTaskDataForExitSide();

                if (taskDTO != null && WriteAsrsPLC(communicationMachine, taskDTO))
                {
                    machineTasksData.UpdateMachineTaskWithPlcSentById(taskDTO.taskId);
                }
            }
        }
        public static void ReadStrechMachinePLC(MachinesDTO communicationMachine)
        {
            easyModbusCommunication = new EasyModbusCommunication(communicationMachine.IpAddress, 502);
            var readedData = easyModbusCommunication.ReadFromPLC(0, 40);

            var obj = ObjectAssign.IntArrayToObject_RD(readedData, communicationMachine);

            readedDataAcces.InsertReadedData(obj);


            if (true /*obj.MW200 == 0*/)
            {
                int productId = 0;//plc okuma sonrası netleşecek alanlar belki barcoda göre gidip tekrar sorgu atması gerekecek

                InsertPreProductionNotification(new PreProductionNotification
                {
                    ProductId           = 0,
                    PaletteBarcode      = "",
                    BatchNo             = "BT382020",
                    PreNotificationTime = DateTime.Now,
                    Lot = "",
                    ReadOnTheConveyor = false
                });

                //insert başarılı ve bufferda aynı üründen varsa adresinin tüp ağzında da aynı üründen varsa
                //adrese mekik shuttle taşıma işi oluştur

                var address = addressData.GetFirstRowIsEmptyByProductId(productId);
                var buffer  = buffersData.GetPaletteInfoByProductId(productId);

                if (!address.FirstRowIsEmpty && buffer.Id > 0)
                {
                    CreateTasksForShuttleRelocation(address.Code);
                }
            }
        }
        internal static void DoExitSideJobs(MachinesDTO communicationMachine)
        {
            var rd = ReadAsrsPLC(communicationMachine);
            var id = easyModbusCommunication.ConvertRegistersToInt(new int[] { rd.MW202, rd.MW203 });


            var incomingTask = machineTasksData.GetMachineTaskById(id);

            if (incomingTask.TaskType == (int)TaskType.ATC)
            {
                //TODO:paletin hangi place e gittiğine göre fg4 ya da normal

                machineTasksData.UpdateMachineTaskWithPlcCompletedById(id);
                palletsAtAddressesData.UpdatePalletsAtAddressWithRelease(incomingTask.LoadInfo);

                orderDetailPalletsData.UpdateOrderDetailPalletsWithTaken(incomingTask.OrderDetailPalletId);
                var odp = orderDetailPalletsData.GetOrderDetailPalletById(incomingTask.OrderDetailPalletId);


                int remainPalletCount = orderDetailPalletsData.RemainCountByOrderDetailId(odp.OrderDetailId);

                if (remainPalletCount == 0)
                {
                    orderDetailsData.UpdateOrderDetailsWithTaken(odp.OrderDetailId);
                }

                UpdateProductQuantitiesPlaces();//trickery

                addressData.AddressesChangeFirstRowInfo(incomingTask.SourceAddress, true, null, Location.WH_OUT);
            }
            else if (incomingTask.TaskType == (int)TaskType.ShATA)
            {
                machineTasksData.UpdateMachineTaskWithPlcCompletedById(id);
                shuttlesData.UpdateShuttleLastAddressAndStatus(incomingTask);
                addressData.AddressesChangeFirstRowInfo(incomingTask.SourceAddress, true, null, Location.WH_OUT);
            }
            else if (incomingTask.TaskType == (int)TaskType.ShCHRG)
            {
                machineTasksData.UpdateMachineTaskWithPlcCompletedById(id);
                shuttlesData.UpdateShuttleLastAddressAndStatus(incomingTask);
                addressData.AddressesChangeFirstRowInfo(incomingTask.SourceAddress, true, null, Location.WH_OUT);
            }
            else if (incomingTask.TaskType == (int)TaskType.ATA)//olma ihtimali düşük olursa giriş işlemi gibi çalışması gerekebilir.
            {
                //değerlendir
            }
            else
            {
                //hata logu vs try catch
            }


            //tüp ağzındaki paleti aldı fg4 yada normal conveyore bıraktı
            //mekik aldı taşıdı
            //mekik aldı şarja götürdü
            //durumlarına göre güncellemeler yapacak
            //status update leri kritik olmalı


            //yaptığı işlerin kontrolünden sonra yeni iş atama:
            //orders check
            //mekik şarj task
            AssignTask(communicationMachine);
        }
示例#15
0
        internal static void DoShuttleJobs(MachinesDTO senderMachine)
        {
            //simule ok
            easyModbusCommunication = new EasyModbusCommunication(senderMachine.IpAddress, 502);
            easyModbusCommunication.WriteToPLC(0, new int[] { 100, 0 });//plcden ye done göndermesi için
            //


            var rd = ReadShuttlePLC(senderMachine);
            var id = easyModbusCommunication.ConvertRegistersToInt(new int[] { rd.MW202, rd.MW203 });

            if (id > 0 && rd.MW200 == (int)Plc_Task.DONESUCCESSFULLY)
            {
                int distance = 0;

                var incomingTask = machineTasksData.GetMachineTaskById(id);

                if (incomingTask.IsCompleted == false)
                {
                    if (incomingTask.TaskType == (int)TaskType.ShOPT)
                    {
                        //Tüpteki paletlerin bilgileri distancetoexit bilgileri entry date e göre güncelle isinside true olanlar
                        palletsAtAddressesData.OptimizationUpdatePalletsAtAddresses(incomingTask.TargetAddress);

                        machineTasksData.UpdateMachineTaskWithPlcCompletedById(id);
                    }
                    else if (incomingTask.TaskType == (int)TaskType.ShINSERT) //asrs koyduktan sonra oluşacak
                    {
                        //asrs koyduğunda oluştu burda güncellenmeli
                        //Tüp ağzındaki paleti palletsataddressde güncelle(distance to exit),
                        palletsAtAddressesData.UpdatePalletsAtAddressWithShInsert(incomingTask, distance);

                        //adrsin tüp agzı bilgisini güncelle boş olarak
                        addressData.AddressesChangeFirstRowInfo(incomingTask.TargetAddress, true, null, Location.WH_IN);


                        machineTasksData.UpdateMachineTaskWithPlcCompletedById(id);
                    }
                    else if (incomingTask.TaskType == (int)TaskType.ShTAKEOUT) //orderdetail a göre veye asrs buraya mekik taşıdıktan sonra oluşacak??
                    {
                        //Tüp içindeki en öndeki paleti palletsataddressde güncelle(sadece distance bilgisi  ),
                        palletsAtAddressesData.UpdatePalletsAtAddressWithShTakeOut(incomingTask);

                        //adresin tüp agzı bilgisini güncelle dolu olarak
                        addressData.AddressesChangeFirstRowInfo(incomingTask.TargetAddress, false, DateTime.Now, Location.WH_OUT);

                        machineTasksData.UpdateMachineTaskWithPlcCompletedById(id);
                    }
                    else if (incomingTask.TaskType == (int)TaskType.ShATA)
                    {
                        //asrs de bu adım asrs için var burada shuttle için yapması gereken birşey olup olmadığı kontrol edilebilir
                        //
                        machineTasksData.UpdateMachineTaskWithPlcCompletedById(id);
                    }
                    else
                    {
                        //hata logu vs try catch
                    }
                }

                AssignTask(senderMachine, rd);
            }
        }
示例#16
0
        private static void CheckNeedShuttleAddressesAndCreateTaskForIt(MachinesDTO communicationMachine)
        {
            //sp_GetNeedShuttleAddresses_sel
            var list = addressData.GetNeedShuttleAddresses();

            //TODO: eğer atanmış iş varsa aynı adrese yenisini atamamlı


            if (list.Count > 0)
            {
                var shuttle = shuttlesData.GetShuttleByCode(communicationMachine.Code);
                var asrs    = asrsData.GetAllAsrs().First(x => x.Location == Location.WH_OUT); //çıkış tarafındaki asrs taşıma işiyle ilgili

                var         taskBatch          = machineTasksData.GetNewTaskBatch();
                MachineTask machineTaskShuttle = new MachineTask
                {
                    OrderDetailPalletId   = 0,
                    ProductNotificationId = 0,
                    TaskType      = (int)TaskType.ShATA, //tüp başına gitmesi için gerekli komutu buradan alabilir?
                    TaskBatch     = taskBatch,
                    Sequence      = 1,
                    MachineCode   = communicationMachine.Code,
                    SourceType    = AddressType.ADDRESS,
                    SourceAddress = shuttle.LastAddress,
                    LoadInfo      = "",
                    TargetType    = AddressType.ADDRESS,
                    TargetAddress = shuttle.LastAddress, //list[0].Code,
                    AssignUser    = "******",
                    AssignReason  = "ShuttleNeed",
                    AssignTime    = DateTime.Now,
                    StartTime     = null,
                    EndTime       = null,
                    SentFlag      = false,
                    IsCompleted   = false,
                    ErrorCode     = null
                };

                MachineTask machineTaskAsrs = new MachineTask
                {
                    OrderDetailPalletId   = 0,
                    ProductNotificationId = 0,
                    TaskType      = (int)TaskType.ShATA, //tüp başına gitmesi için gerekli komutu buradan alabilir?
                    TaskBatch     = taskBatch,
                    Sequence      = 2,
                    MachineCode   = asrs.Code,
                    SourceType    = AddressType.ADDRESS,
                    SourceAddress = shuttle.LastAddress,
                    LoadInfo      = shuttle.Code,
                    TargetType    = AddressType.ADDRESS,
                    TargetAddress = list[0].Code, //gideceği adres
                    AssignUser    = "******",
                    AssignReason  = "ShuttleNeed",
                    AssignTime    = DateTime.Now,
                    StartTime     = null,
                    EndTime       = null,
                    SentFlag      = false,
                    IsCompleted   = false,
                    ErrorCode     = null
                };

                machineTasksData.InsertMachineTask(machineTaskShuttle);
                machineTasksData.InsertMachineTask(machineTaskAsrs);
            }
        }
        public static void CreateTaskForPalette(string barcode, MachinesDTO communicationMachine, long pnId)
        {
            var asrs = asrsData.GetAllAsrs().First(x => x.Location == Location.WH_IN);

            Product product   = productsData.GetProductByBarcode(barcode);
            var     target    = SelectTarget(product.Id);
            var     taskBatch = tasksData.GetNewTaskBatch();

            MachineTask machineTask = new MachineTask
            {
                OrderDetailPalletId   = 0,//boş kalamalı
                ProductNotificationId = (int)pnId,
                TaskType = target.Item1 == AddressType.ADDRESS ? (int)TaskType.CTA :
                           target.Item1 == AddressType.BUFFER ? (int)TaskType.CTB :
                           0, //address type göre task type belirlendi 0 olma durumunda hata var demektir
                TaskBatch     = taskBatch,
                Sequence      = 1,
                MachineCode   = asrs.Code,
                SourceType    = communicationMachine.Type,
                SourceAddress = communicationMachine.Code, //conveyorden alıyor conveyore konum bigileri eklemek gerekebilir
                LoadInfo      = barcode,
                TargetType    = target.Item1,
                TargetAddress = target.Item2,
                AssignUser    = "******",
                AssignReason  = "STANDART",
                AssignTime    = DateTime.Now,
                StartTime     = null,
                EndTime       = null,
                SentFlag      = false,
                IsCompleted   = false,
                ErrorCode     = null,
            };

            //insert task
            tasksData.InsertMachineTask(machineTask);


            //daha sonra icra edilmek üzere palet buffera taşındıysa batch ve sequence ayarlayarak
            //buffer dan address e taşıma task ı oluştur
            if (target.Item1 == AddressType.BUFFER)
            {
                MachineTask machineTaskBTA = new MachineTask
                {
                    OrderDetailPalletId   = 0,//boş kalamalı
                    ProductNotificationId = (int)pnId,
                    TaskType      = (int)TaskType.BTA,
                    TaskBatch     = taskBatch,
                    Sequence      = 2,
                    MachineCode   = asrs.Code,
                    SourceType    = AddressType.BUFFER,
                    SourceAddress = target.Item2,
                    LoadInfo      = barcode,
                    TargetType    = AddressType.ADDRESS,
                    TargetAddress = addressData.SelectRelatedAppropiriateAddress(product.Id),  //TODO: mutlaka adres seçilmesi sağlanacak. yeni method yazılmalı
                    AssignUser    = "******",
                    AssignReason  = "STANDART",
                    AssignTime    = DateTime.Now,
                    StartTime     = null,
                    EndTime       = null,
                    SentFlag      = false,
                    IsCompleted   = false,
                    ErrorCode     = null,
                };
                tasksData.InsertMachineTask(machineTaskBTA);
            }
        }