Esempio n. 1
0
        public async Task <(bool, string)> HabilitaForno(int Posicao)
        {
            string tagName     = string.Empty;
            string workStation = _configuration["WorkStation"];

            if (Posicao == 1)
            {
                tagName = _configuration["HabilitaForno1"];
            }
            else if (Posicao == 2)
            {
                tagName = _configuration["HabilitaForno2"];
            }
            else
            {
                return(false, "Não encontrado forno nesta posição");
            }

            var tagValue = await _interleverDb.Read(tagName);

            var tagNewValue = WriteBit(Convert.ToInt32(tagValue), 3).ToString();

            if (!await _interleverDb.Write(tagNewValue, tagName, workStation))
            {
                return(false, "Erro ao tentar escrever no banco de dados");
            }

            return(true, string.Empty);
        }
Esempio n. 2
0
 public async Task <IActionResult> Post([FromBody] TagEndPointModel tag)
 {
     if (await interlevelDb.Write(tag.value, tag.address, tag.workstation))
     {
         return(Ok());
     }
     return(BadRequest());
 }
        private async Task <bool> OpTypeTira(ProductionOrder productionOrder)
        {
            var trigger = _configuration["TagIdTrigger"];
            // Finaliza Ordem anterior
            var triggerPlc = _interleverDb.Write("2", trigger, "Linha");


            List <Thing> thingsGetList = new List <Thing>();
            var          trigger3      = _configuration["TagIdTrigger"];
            await _interleverDb.Write("2", trigger, "Linha");

            var phases = productionOrder.recipe.phases;

            /*Console.WriteLine("");
             * Console.WriteLine("");
             * Console.WriteLine("");
             * Console.WriteLine("Phase: ------------------------------------------------------------ ");
             * Console.WriteLine("Phase-> " +JsonConvert.SerializeObject(phases).ToString() );
             * Console.WriteLine("");
             * Console.WriteLine("");
             * Console.WriteLine("");
             * Console.WriteLine("Loop de phases");
             * Console.WriteLine(""); */
            foreach (var phase in phases)
            {
                foreach (var phaseParameter in phase.phaseParameters)
                {
                    /*Console.WriteLine("");
                    *  Console.WriteLine("");
                    *  Console.WriteLine("");
                    *  Console.WriteLine("phaseParameter: ------------------------------------------------------------ ");
                    *  Console.WriteLine("phaseParameter-> " +JsonConvert.SerializeObject(phaseParameter).ToString() );
                    *  Console.WriteLine("");
                    *  Console.WriteLine("");
                    *  Console.WriteLine("");*/
                    string value = phaseParameter.setupValue;

                    var tag = await _otherApi.GetTag(phaseParameter.tag.tagId);

                    //var tag = phaseParameter.tag;
                    //Console.WriteLine("tag: ------------------------------------------------------------ ");
                    //Console.WriteLine("tag-> " +JsonConvert.SerializeObject(tag).ToString() );
                    var thingGroup = await _otherApi.GetThingGroup(tag.thingGroupId);

                    //Console.WriteLine("Loop thingGroup: ------------------------------------------------------------ ");

                    foreach (var thingId in thingGroup.thingsIds)
                    {
                        Console.WriteLine("Foi no Foreach");
                        Console.WriteLine("");
                        Thing thing = null;

                        thing = thingsGetList.Where(x => x.thingId == thingId).FirstOrDefault();
                        Console.WriteLine("thingId" + thingId.ToString());
                        if (thing == null)
                        {
                            Console.WriteLine("get na thing");
                            thing = await _otherApi.GetThing(thingId);

                            //Console.WriteLine(JsonConvert.SerializeObject(await _otherApi.GetThing(thingId)).ToString() );
                            if (thing != null)
                            {
                                thingsGetList.Add(thing);
                            }
                        }
                        //Console.WriteLine(JsonConvert.SerializeObject(thing).ToString() );
                        if (string.IsNullOrEmpty(tag.physicalTag))
                        {
                            Console.WriteLine("");
                            Console.WriteLine("");
                            Console.WriteLine("Deu ruim");
                            Console.WriteLine("");
                            Console.WriteLine("");
                            continue;
                        }
                        Console.Write("Physical da tag :");
                        Console.WriteLine(tag.physicalTag);
                        Console.Write("Valor da tag :");
                        Console.WriteLine(value);
                        Console.Write("phisical connection : ");
                        Console.WriteLine(thing.physicalConnection);
                        Console.WriteLine("");
                        var e = _interleverDb.Write(value, tag.physicalTag, thing.physicalConnection);
                        Console.WriteLine("Fim");
                    }
                }
            }

            // envia o trigger para o PLC
            var triggerPlc2 = await _interleverDb.Write("5", trigger, "Linha");

            return(true);
        }