public void Check_ItemBuilder()
        {
            // With predefined length-item.
            DynamicBytesPlcItem item = new Items.Builder.PlcItemBuilder()
                                       .ConstructBytesPlcItem("Bytes")
                                       .ForData()
                                       .AtDatablock(0)
                                       .AtPosition(0)
                                       .WithDynamicItem <UInt32PlcItem>()
                                       .BuildDynamic()
            ;

            System.Diagnostics.Debug.WriteLine(item.ToString());
            Assert.True(item.LengthPlcItem is UInt32PlcItem);
            Assert.AreEqual(default(UInt32), ((UInt32PlcItem)item.LengthPlcItem).Value);
            Assert.IsNotNull(item.Value);
            Assert.True(new byte[0].SequenceEqual(item.Value));

            // With initial value.
            var initialValue = new byte[] { Byte.MinValue, Byte.MaxValue, 10, 20, 30, 40, 50 };

            item = new Items.Builder.PlcItemBuilder()
                   .ConstructBytesPlcItem("Bytes")
                   .ForData()
                   .AtDatablock(0)
                   .AtPosition(0)
                   .WithDynamicItemFromInitialValue(initialValue)
                   .BuildDynamic()
            ;
            System.Diagnostics.Debug.WriteLine(item.ToString());
            Assert.True(item.LengthPlcItem is BytePlcItem);
            Assert.AreEqual(initialValue.Length, ((BytePlcItem)item.LengthPlcItem).Value);
            Assert.True(initialValue.SequenceEqual(item.Value));
        }
        public void Check_ItemBuilder()
        {
            // With predefined length-item.
            DynamicUtf8PlcItem item = new Items.Builder.PlcItemBuilder()
                                      .ConstructUtf8PlcItem("UTF8")
                                      .AtDatablock(0)
                                      .AtPosition(0)
                                      .WithDynamicItem <UInt32PlcItem>()
                                      .BuildDynamic()
            ;

            System.Diagnostics.Debug.WriteLine(item.ToString());
            Assert.True(item.LengthPlcItem is UInt32PlcItem);
            Assert.AreEqual(default(UInt32), ((UInt32PlcItem)item.LengthPlcItem).Value);
            Assert.IsNotNull(item.Value);
            Assert.AreEqual(String.Empty, item.Value);

            // With initial value.
            var initialValue = Guid.NewGuid().ToString();

            item = new Items.Builder.PlcItemBuilder()
                   .ConstructUtf8PlcItem("UTF8")
                   .AtDatablock(0)
                   .AtPosition(0)
                   .WithDynamicItemFromInitialValue(initialValue)
                   .BuildDynamic()
            ;
            System.Diagnostics.Debug.WriteLine(item.ToString());
            Assert.True(item.LengthPlcItem is BytePlcItem);
            Assert.AreEqual(Encoding.UTF8.GetBytes(initialValue).Length, ((BytePlcItem)item.LengthPlcItem).Value);
            Assert.AreEqual(initialValue, item.Value);
        }
Esempio n. 3
0
        public void Check_ItemBuilder()
        {
            EnumPlcItem <TestEnumeration> item = new Items.Builder.PlcItemBuilder()
                                                 .ConstructEnumPlcItem <TestEnumeration>("Enumeration")
                                                 .AtDatablock(0)
                                                 .AtPosition(0)
                                                 .WithInitialValue(TestEnumeration.Value1)
                                                 .Build()
            ;

            Assert.AreEqual((uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(TestEnumeration).GetEnumUnderlyingType()), ((IPlcItem)item).Value.ByteLength);

            System.Diagnostics.Debug.WriteLine(item.ToString());
        }