コード例 #1
0
 /// <summary>
 /// Writes a field from the <paramref name="record"/> to the <paramref name="encoder"/>
 /// using the <paramref name="writer"/>.
 /// </summary>
 /// <param name="record">The record value from which the field needs to be extracted</param>
 /// <param name="fieldName">The name of the field in the record</param>
 /// <param name="fieldPos">The position of field in the record</param>
 /// <param name="writer">Used to write the field value to the encoder</param>
 /// <param name="encoder">Encoder to write to</param>
 protected abstract void WriteField(object record, string fieldName, int fieldPos, WriteItem writer, Encoder encoder);
コード例 #2
0
 /// <inheritdoc/>
 protected override void WriteField(object record, string fieldName, int fieldPos, WriteItem writer, Encoder encoder)
 {
     writer(((ISpecificRecord)record).Get(fieldPos), encoder);
 }
コード例 #3
0
        private static IEnumerable <WritePackage> CreateWritePackages(SiemensPlcProtocolContext s7Context, IEnumerable <WriteItem> vars)
        {
            var result = new List <WritePackage>();

            foreach (var item in vars.OrderByDescending(x => x.NumberOfItems).ToList())
            {
                var currentPackage = result.FirstOrDefault(package => package.TryAdd(item));
                if (currentPackage == null)
                {
                    if (item.NumberOfItems > s7Context.WriteItemMaxLength)
                    {
                        var    bytesToWrite = item.NumberOfItems;
                        ushort processed    = 0;
                        while (bytesToWrite > 0)
                        {
                            var slice = Math.Min(s7Context.WriteItemMaxLength, bytesToWrite);
                            var child = WriteItem.CreateChild(item, (ushort)(item.Offset + processed), slice);
                            if (slice < s7Context.WriteItemMaxLength)
                            {
                                currentPackage = result.FirstOrDefault(package => package.TryAdd(child));
                            }

                            if (currentPackage == null)
                            {
                                currentPackage = new WritePackage(s7Context.PduSize);
                                if (currentPackage.TryAdd(child))
                                {
                                    if (currentPackage.Full)
                                    {
                                        yield return(currentPackage.Return());

                                        if (currentPackage.Handled)
                                        {
                                            currentPackage = null;
                                        }
                                    }
                                    else
                                    {
                                        result.Add(currentPackage);
                                    }
                                }
                                else
                                {
                                    ThrowHelper.ThrowCouldNotAddPackageException(nameof(WritePackage));
                                }
                            }
                            processed    += slice;
                            bytesToWrite -= slice;
                        }
                    }
                    else
                    {
                        currentPackage = new WritePackage(s7Context.PduSize);
                        result.Add(currentPackage);
                        if (!currentPackage.TryAdd(item))
                        {
                            ThrowHelper.ThrowCouldNotAddPackageException(nameof(WritePackage));
                        }
                    }
                }

                if (currentPackage != null)
                {
                    if (currentPackage.Full)
                    {
                        yield return(currentPackage.Return());
                    }

                    if (currentPackage.Handled)
                    {
                        result.Remove(currentPackage);
                    }
                }
            }
            foreach (var package in result)
            {
                yield return(package.Return());
            }
        }
コード例 #4
0
 /// <inheritdoc/>
 protected override void WriteField(object record, string fieldName, int fieldPos, WriteItem writer, Encoder encoder)
 {
     writer(((GenericRecord)record)[fieldName], encoder);
 }
コード例 #5
0
        public async Task ReadWriteSingleDWords()
        {
            await PlcTestServer.ExecuteClientAsync(async (client) =>
            {
                var originWriteTags = new Dictionary <string, object>
                {
                    { $"DB2.10006,dw", (uint)0 },
                    { $"DB2.10010,di", 0 }
                };
                var writeResults = (await client.WriteAsync(originWriteTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();
                var results      = (await client.ReadAsync(originWriteTags.Select(w => ReadItem.CreateFromTag(w.Key)))).ToArray();



                Assert.Equal(2, results.Count());
                Assert.Equal(typeof(uint), results[0].Type);
                Assert.Equal((uint)0, (uint)results[0].Value);
                Assert.Equal(typeof(int), results[1].Type);
                Assert.Equal(0, (int)results[1].Value);


                var writeTags = new Dictionary <string, object>
                {
                    { $"DB2.10006,dw", (uint)15 },
                    { $"DB2.10010,di", 25 }
                };

                writeResults = (await client.WriteAsync(writeTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();

                results = (await client.ReadAsync(writeTags.Select(w => ReadItem.CreateFromTag(w.Key)))).ToArray();


                Assert.Equal(2, results.Count());
                Assert.Equal(typeof(uint), results[0].Type);
                Assert.Equal((ushort)15, (uint)results[0].Value);
                Assert.Equal(typeof(int), results[1].Type);
                Assert.Equal(25, (int)results[1].Value);

                writeResults = (await client.WriteAsync(originWriteTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();
            });
        }
コード例 #6
0
        public override bool Execute()
        {
            try
            {
                Directory.CreateDirectory(Path.GetDirectoryName(ProjectFile));

                List <string> packs = new();

                var excludedPackIds = ExcludedPackIds.Select(i => i.ItemSpec);

                XmlWriterSettings settings = new XmlWriterSettings
                {
                    Indent      = true,
                    IndentChars = "  "
                };

                XmlWriter writer = XmlWriter.Create(ProjectFile, settings);

                writer.WriteStartElement("Project");
                writer.WriteAttributeString("Sdk", "Microsoft.NET.Sdk");

                writer.WriteStartElement("PropertyGroup");
                writer.WriteElementString("TargetFramework", "net6.0");
                writer.WriteElementString("IncludeBuildOutput", "false");
                writer.WriteEndElement();

                writer.WriteStartElement("ItemGroup");

                foreach (var manifestFile in ManifestFiles)
                {
                    WorkloadManifest manifest = WorkloadManifestReader.ReadWorkloadManifest(
                        Path.GetFileNameWithoutExtension(manifestFile.ItemSpec), File.OpenRead(manifestFile.ItemSpec), manifestFile.ItemSpec);

                    foreach (var pack in manifest.Packs.Values)
                    {
                        if (pack.IsAlias)
                        {
                            foreach (var alias in pack.AliasTo.Keys.Where(k => k.StartsWith("win")))
                            {
                                if (!excludedPackIds.Contains($"{pack.AliasTo[alias]}"))
                                {
                                    WriteItem(writer, "PackageDownload", ("Include", $"{pack.AliasTo[alias]}"), ("Version", $"[{pack.Version}]"));
                                    packs.Add($"$(NuGetPackageRoot){pack.AliasTo[alias]}\\{pack.Version}\\*.nupkg");
                                }
                            }
                        }
                        else if (!excludedPackIds.Contains($"{pack.Id}"))
                        {
                            WriteItem(writer, "PackageDownload", ("Include", $"{pack.Id}"), ("Version", $"[{pack.Version}]"));
                            packs.Add($"$(NuGetPackageRoot){pack.Id}\\{pack.Version}\\*.nupkg");
                        }
                    }
                }

                writer.WriteEndElement();

                writer.WriteStartElement("Target");
                writer.WriteAttributeString("Name", "CopyPacks");
                writer.WriteAttributeString("AfterTargets", "Build");

                writer.WriteStartElement("ItemGroup");

                foreach (var pack in packs)
                {
                    WriteItem(writer, "Pack", ("Include", pack));
                }

                writer.WriteEndElement();

                writer.WriteStartElement("Copy");
                writer.WriteAttributeString("SourceFiles", "@(Pack)");
                writer.WriteAttributeString("DestinationFolder", $"{PackageSource}");
                writer.WriteEndElement();

                writer.WriteEndElement();

                writer.WriteEndElement();
                writer.Flush();
                writer.Close();
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e);
            }

            return(!Log.HasLoggedErrors);
        }
コード例 #7
0
        public async Task ReadWriteBigDBData()
        {
            await PlcTestServer.ExecuteClientAsync(async (client) =>
            {
                var data            = Enumerable.Repeat((byte)0x00, 1000).ToArray();
                var originWriteTags = new Dictionary <string, object>
                {
                    { $"DB2.2500,b,1000", data }
                };

                var writeResults = (await client.WriteAsync(originWriteTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();
                var results      = (await client.ReadAsync(originWriteTags.Select(w => ReadItem.CreateFromTag(w.Key)))).ToArray();

                Assert.True(results.FirstOrDefault().Data.ToArray().SequenceEqual(data));

                var data2     = Enumerable.Repeat((byte)0x25, 1000).ToArray();
                var writeTags = new Dictionary <string, object>
                {
                    { $"DB2.2500,b,1000", data2 }
                };

                writeResults = (await client.WriteAsync(writeTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();

                results = (await client.ReadAsync(writeTags.Select(w => ReadItem.CreateFromTag(w.Key)))).ToArray();

                Assert.True(results.FirstOrDefault().Data.ToArray().SequenceEqual(data2));

                writeResults = (await client.WriteAsync(originWriteTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();
            });
        }
コード例 #8
0
        public async Task ReadWriteMultibleDInts()
        {
            await PlcTestServer.ExecuteClientAsync(async (client) =>
            {
                var originWriteTags = new Dictionary <string, object>
                {
                    { $"DB2.10038,di,2", new int[] { 0, 0 } }
                };
                var writeResults = (await client.WriteAsync(originWriteTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();
                var results      = (await client.ReadAsync(originWriteTags.Select(w => ReadItem.CreateFromTag(w.Key)))).ToArray();


                Assert.Single(results);
                Assert.Equal(typeof(int[]), results[0].Type);

                var resultValueDefault = results[0].GetValue <int[]>();

                Assert.True(resultValueDefault.SequenceEqual(originWriteTags.FirstOrDefault().Value as int[]));

                var writeData = new int[] { 22, 21 };
                var writeTags = new Dictionary <string, object>
                {
                    { $"DB2.10038,di,2", writeData }
                };

                writeResults = (await client.WriteAsync(writeTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();

                results = (await client.ReadAsync(writeTags.Select(w => ReadItem.CreateFromTag(w.Key)))).ToArray();

                Assert.Single(results);
                Assert.Equal(typeof(int[]), results[0].Type);

                var resultValue = results[0].GetValue <int[]>();

                Assert.True(resultValue.SequenceEqual(writeData));

                writeResults = (await client.WriteAsync(originWriteTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();
            });
        }
コード例 #9
0
        public async Task ReadWriteSingleStrings2()
        {
            await PlcTestServer.ExecuteClientAsync(async (client) =>
            {
                var originWriteTags = new Dictionary <string, object>
                {
                    { $"DB2.10090,s,20", "" },
                    { $"DB2.10112,s,20", "                    " }
                };
                var writeResults = (await client.WriteAsync(originWriteTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();
                var results      = (await client.ReadAsync(originWriteTags.Select(w => ReadItem.CreateFromTag(w.Key)))).ToArray();


                Assert.Equal(2, results.Count());
                Assert.Equal(typeof(string), results[0].Type);
                Assert.Equal("", (string)results[0].Value);
                Assert.Equal(typeof(string), results[1].Type);
                Assert.Equal("                    ", (string)results[1].Value);


                var writeTags = new Dictionary <string, object>
                {
                    { $"DB2.10046,s,20", "A PARTIAL STRING".PadLeft(20).Substring(0, 18) },
                    { $"DB2.10068,s,20", "A FULLY STRING IT IS".PadLeft(20) }
                };

                writeResults = (await client.WriteAsync(writeTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();

                results = (await client.ReadAsync(writeTags.Select(w => ReadItem.CreateFromTag(w.Key)))).ToArray();


                Assert.Equal(2, results.Count());
                Assert.Equal(typeof(string), results[0].Type);
                Assert.Equal("A PARTIAL STRING".PadLeft(20).Substring(0, 18), (string)results[0].Value);
                Assert.Equal(typeof(string), results[1].Type);
                Assert.Equal("A FULLY STRING IT IS".PadLeft(20), (string)results[1].Value);

                writeResults = (await client.WriteAsync(originWriteTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();
            });
        }
コード例 #10
0
        public async Task ReadWriteSingleStrings()
        {
            await PlcTestServer.ExecuteClientAsync(async (client) =>
            {
                var originWriteTags = new Dictionary <string, object>
                {
                    { $"DB2.10046,s,20", "" },
                    { $"DB2.10068,s,20", "                    " }
                };
                var writeResults = (await client.WriteAsync(originWriteTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();
                var results      = (await client.ReadAsync(originWriteTags.Select(w => ReadItem.CreateFromTag(w.Key)))).ToArray();


                Assert.Equal(2, results.Count());
                Assert.Equal(typeof(string), results[0].Type);
                Assert.Equal("", (string)results[0].Value);
                Assert.Equal(typeof(string), results[1].Type);
                Assert.Equal("                    ", (string)results[1].Value);


                var writeTags = new Dictionary <string, object>
                {
                    { $"DB2.10046,s,20", "Test1" },
                    { $"DB2.10068,s,20", "Test2               " }
                };

                writeResults = (await client.WriteAsync(writeTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();

                results = (await client.ReadAsync(writeTags.Select(w => ReadItem.CreateFromTag(w.Key)))).ToArray();


                Assert.Equal(2, results.Count());
                Assert.Equal(typeof(string), results[0].Type);
                Assert.Equal("Test1", (string)results[0].Value);
                Assert.Equal(typeof(string), results[1].Type);
                Assert.Equal("Test2               ", (string)results[1].Value);

                writeResults = (await client.WriteAsync(originWriteTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();
            });
        }
コード例 #11
0
        public async Task ReadWriteSingles()
        {
            await PlcTestServer.ExecuteClientAsync(async (client) =>
            {
                var originWriteTags = new Dictionary <string, object>
                {
                    { $"DB2.10014,r", (float)0.0 }
                };
                var writeResults = (await client.WriteAsync(originWriteTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();
                var results      = (await client.ReadAsync(originWriteTags.Select(w => ReadItem.CreateFromTag(w.Key)))).ToArray();



                Assert.Single(results);
                Assert.Equal(typeof(float), results[0].Type);
                Assert.Equal((float)0.0, (float)results[0].Value);

                var writeTags = new Dictionary <string, object>
                {
                    { $"DB2.10014,r", (float)0.5 }
                };

                writeResults = (await client.WriteAsync(writeTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();

                results = (await client.ReadAsync(writeTags.Select(w => ReadItem.CreateFromTag(w.Key)))).ToArray();

                Assert.Single(results);
                Assert.Equal(typeof(float), results[0].Type);
                Assert.Equal((float)0.5, (float)results[0].Value);

                writeResults = (await client.WriteAsync(originWriteTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();
            });
        }
コード例 #12
0
        public async Task ReadWriteSingleBits()
        {
            await PlcTestServer.ExecuteClientAsync(async (client) =>
            {
                var originWriteTags = new Dictionary <string, object>
                {
                    { $"DB2.10000,x0", false },
                    { $"DB2.10000,x5", false }
                };
                var writeResults = (await client.WriteAsync(originWriteTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();


                var results = (await client.ReadAsync(originWriteTags.Select(w => ReadItem.CreateFromTag(w.Key)))).ToArray();


                Assert.Equal(2, results.Count());
                Assert.Equal(typeof(bool), results[0].Type);
                Assert.False((bool)results[0].Value);
                Assert.Equal(typeof(bool), results[1].Type);
                Assert.False((bool)results[1].Value);


                var writeTags = new Dictionary <string, object>
                {
                    { $"DB2.10000,x0", true },
                    { $"DB2.10000,x5", true }
                };

                writeResults = (await client.WriteAsync(writeTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();

                results = (await client.ReadAsync(writeTags.Select(w => ReadItem.CreateFromTag(w.Key)))).ToArray();

                Assert.Equal(2, results.Count());
                Assert.Equal(typeof(bool), results[0].Type);
                Assert.True((bool)results[0].Value);
                Assert.Equal(typeof(bool), results[1].Type);
                Assert.True((bool)results[1].Value);

                writeResults = (await client.WriteAsync(originWriteTags.Select(w => WriteItem.CreateFromTag(w.Key, w.Value)))).ToArray();
            });
        }
コード例 #13
0
    public virtual void HandleInteractiveHitTest(HitTestResult result)
    {
        if (result == null)
        {
            Debug.LogError("Invalid hit test result!");
            return;
        }
        if (!m_GroundPlaneUI.IsCanvasButtonPressed())
        {
            Debug.Log("HandleInteractiveHitTest() called.");
            // If the PlaneFinderBehaviour's Mode is Automatic, then the Interactive HitTestResult will be centered.
            // PlaneMode.Ground and PlaneMode.Placement both use PlaneFinder's ContentPositioningBehaviour
            m_ContentPositioningBehaviour = m_PlaneFinder.GetComponent <ContentPositioningBehaviour>();
            m_ContentPositioningBehaviour.DuplicateStage = false;
            // Place object based on Ground Plane mode
            if (showGameObject != null && lastName != showGameObjectName)
            {
                lastName = showGameObjectName;
                showGameObject.gameObject.SetActive(true);
                isPlaced = true;
                if (showGameObjectName == "haiou")
                {
                    showGameObject.GetComponent <Haiou>().Init();
                }
                else
                {
                    FingerTouchEL.Instance.targetGameObject = showGameObject;
                }


                UtilityHelper.EnableRendererColliderCanvas(showGameObject, true);

                switch (showGameObject.GetComponent <WriteItem>().goodsPositionEnum)
                {
                case PlaneMode.None:
                    break;

                case PlaneMode.GROUND:
                    m_ContentPositioningBehaviour.AnchorStage = m_PlaneAnchor;
                    m_ContentPositioningBehaviour.PositionContentAtPlaneAnchor(result);
                    showGameObject.transform.parent = planeAnchor.transform;

                    break;

                case PlaneMode.MIDAIR:
                    m_ContentPositioningBehaviour.AnchorStage = m_MidAirAnchor;
                    m_ContentPositioningBehaviour.PositionContentAtMidAirAnchor(showGameObject.transform);
                    showGameObject.transform.parent = midAirAnchor.transform;
                    break;

                default:
                    break;
                }


                showGameObject.transform.localPosition    = Vector3.zero;
                showGameObject.transform.localEulerAngles = Vector3.zero;
                if (showGameObject.name == "wurenji")
                {
                    showGameObject.GetComponentInChildren <Cloth>().enabled = false;
                }
                showGameObject.transform.localScale = Vector3.one * 0.5f;
                if (showGameObject.name == "wurenji")
                {
                    showGameObject.GetComponentInChildren <Cloth>().enabled = true;
                }
                UtilityHelper.RotateTowardCameraVuforia(showGameObject);
                // YiyouStaticDataManager.Instance.ShowModel = showGameObject;
                FirstUseTipManager.Instance.ShowNextTip(TipType.WriteTip);
                WriteItem writeItem = showGameObject.GetComponent <WriteItem>();
                if (writeItem != null && writeItem.goodsEnum != GoodsWriteEnum.None)
                {
                    ShowInput();
                    GroundPlaneUI.Instance.SetIntroductionText("请选择字体并输入文字");
                }
                else
                {
                    GroundPlaneUI.Instance.SetIntroductionText("", false);

                    ShowButtonPanel();
                }

                ShowEffectPanel();
                GroundPlaneUI.Instance.SetReticleVisiblity(false);
                WriteManager.Instance.SetGoodsEnum(showGameObject.GetComponent <WriteItem>().goodsEnum);
                InitLight(showGameObject.name);
            }
            else
            {
                if (showGameObject == null)
                {
                    GroundPlaneUI.Instance.SetIntroductionText("请先选择合影道具");
                }
            }
        }
    }