internal TIAOpennessTag(PlcTag source)
 {
     Name         = source.Name;
     Address      = source.LogicalAddress;
     DataTypeName = source.DataTypeName;
     Comments     = source.Comment.Items
                    .Select(c => new TIAOpennessComment()
     {
         Culture = c.Language.Culture, Text = c.Text
     }).ToList();
     IsExternalAccessible = source.ExternalAccessible;
     IsExternalVisible    = source.ExternalVisible;
 }
Пример #2
0
        private async Task SendPoints(Point first, Point second, CancellationToken ct)
        {
            if (test)
            {
                await Task.Run(() => Thread.Sleep(500));

                return;
            }

            #region PLCTags

            PlcTag <short> tagFirstPointX     = new PlcTag <short>("OpcUaServer;Application.GVL_Chess.G_lrFirstPointX", Controller, Monitor);
            PlcTag <short> tagFirstPointY     = new PlcTag <short>("OpcUaServer;Application.GVL_Chess.G_lrFirstPointY", Controller, Monitor);
            PlcTag <short> tagSecondPointX    = new PlcTag <short>("OpcUaServer;Application.GVL_Chess.G_lrSecondPointX", Controller, Monitor);
            PlcTag <short> tagSecondPointY    = new PlcTag <short>("OpcUaServer;Application.GVL_Chess.G_lrSecondPointY", Controller, Monitor);
            PlcTag <bool>  tagRobotIsDone     = new PlcTag <bool>("OpcUaServer;Application.GVL_Chess.G_xRobotIsDone", Controller, Monitor);
            PlcTag <bool>  tagRobotHasStopped = new PlcTag <bool>("OpcUaServer;Application.GVL_Chess.G_xRobotHasStopped", Controller, Monitor);
            PlcTag <short> tagWatchDog        = new PlcTag <short>("OpcUaServer;Application.GVL_Chess.G_iWatchdog", Controller, Monitor);
            PlcTag <bool>  tagGenLocation     = new PlcTag <bool>("OpcUaServer;Application.GVL_Chess.G_xGenPosition", Controller, Monitor);

            #endregion

            _robotIsDone = false;

            List <Task <bool> > tasks = new List <Task <bool> >()
            {
                tagFirstPointX.WriteValueAsync((short)first.X),
                tagFirstPointY.WriteValueAsync((short)first.Y),
                tagSecondPointX.WriteValueAsync((short)second.X),
                tagSecondPointY.WriteValueAsync((short)second.Y),
            };

            await Task.WhenAll(tasks);

            short resultFx;
            short resultFy;
            short resultSx;
            short resultSy;

            do
            {
                (_, resultFx) = await tagFirstPointX.ReadValueAsync();

                (_, resultFy) = await tagFirstPointY.ReadValueAsync();

                (_, resultSx) = await tagSecondPointX.ReadValueAsync();

                (_, resultSy) = await tagSecondPointY.ReadValueAsync();
            } while (resultFx != first.X || resultFy != first.Y || resultSx != second.X || resultSy != second.Y);

            await tagGenLocation.WriteValueAsync(true);

            tagRobotIsDone.ValueChanged += TagRobotIsDoneOnValueChanged;

            int i = 0;
            while (!_robotIsDone)
            {
                Console.WriteLine(i);
                i++;
                Thread.Sleep(1000);

                /*tagRobotHasStopped.ValueChanged += (sender, e) =>
                 * {
                 *  _robotHasStopped = e.NewValue;
                 *  IsPlaying = IsPlaying == EColor.White ? EColor.Black : EColor.White;
                 *  Console.WriteLine("Broken");
                 * };*/

                if (ct.IsCancellationRequested)
                {
                    Console.WriteLine("?");
                    break;
                }
            }

            List <Task <bool> > tasks2 = new List <Task <bool> >()
            {
                tagFirstPointX.WriteValueAsync(0),
                tagFirstPointY.WriteValueAsync(0),
                tagSecondPointX.WriteValueAsync(0),
                tagSecondPointY.WriteValueAsync(0),
                tagGenLocation.WriteValueAsync(false),
            };

            await Task.WhenAll(tasks2);

            Console.WriteLine(@"Tasks completed");
        }