示例#1
0
        public void WhenYearIsSet_ReturnYear()
        {
            byte[] data   = new byte[] { 0x49, 0x44, 0x33, 0, 0, 0, 0, 0, 0, 0x21, 0x54, 0x59, 0x45, 0x52, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x0, 0x32, 0x30, 0x31, 0x33 };
            var    stream = new MemoryStream(data);

            var tags = MTag.Create(stream);

            tags.Year.Should().Be(2013);
        }
示例#2
0
        public void WhenLatin1EncodingIsUsed_TerminateStringOnNull()
        {
            byte[] data   = new byte[] { 0x49, 0x44, 0x33, 0, 0, 0, 0, 0, 0, 0x1B, 0x54, 0x49, 0x54, 0x32, 0, 0, 0, 0x7, 0x0, 0x0, 0, 0x54, 0x65, 0x73, 0x74, 0x0, 0x41 };
            var    stream = new MemoryStream(data);

            var tags = MTag.Create(stream);

            tags.Title.Should().Be("Test");
        }
示例#3
0
        public void WhenTestIsSetAsTitleTag_ReturnsTest()
        {
            byte[] data   = new byte[] { 0x49, 0x44, 0x33, 0, 0, 0, 0, 0, 0, 0x19, 0x54, 0x49, 0x54, 0x32, 0, 0, 0, 0x5, 0x0, 0x0, 0, 0x54, 0x65, 0x73, 0x74 };
            var    stream = new MemoryStream(data);


            var tags = MTag.Create(stream);

            tags.Title.Should().Be("Test");
        }
        protected override TagAbstract UnpackTagSpecific(string custom)
        {
            // Region
            // Begin
            var jo   = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(custom);
            var mtag = new MTag();

            if (jo.ContainsKey(nameof(mtag.Region)))
            {
                mtag.Region = (ModbusRegion)jo[nameof(mtag.Region)].ToObject(typeof(ModbusRegion));
            }

            if (jo.ContainsKey(nameof(mtag.Begin)))
            {
                mtag.Begin = (int)jo[nameof(mtag.Begin)].ToObject(typeof(int));
            }

            return(mtag);
        }
示例#5
0
        public void WhenMultipleTagsAreSet_ReturnsTheExpectedTags()
        {
            string[] input = File.ReadAllText("test.txt").Split(' ');
            var      data  = new byte[input.Length];

            for (int i = 0; i < data.Length; i++)
            {
                data[i] = (byte)int.Parse(input[i], System.Globalization.NumberStyles.HexNumber);
            }

            var stream = new MemoryStream(data);

            var tags = MTag.Create(stream);

            tags.Title.Should().Be("The Crutch");
            tags.Band.Should().Be("Billy Talent");
            tags.TrackNumber.Should().Be(3);
            tags.AmountOfTracksInSet.Should().Be(12);
            tags.AlbumName.Should().Be("Afraid of Heights");
            tags.SetNumber.Should().Be(1);
            tags.AmountOfSets.Should().Be(1);
            tags.Year.Should().Be(2016);
            tags.Genres.Should().Contain("Alternative & Punk");
        }
示例#6
0
        public static Store Get()
        {
            var store = new Store();

            var connectionSource = new TcpConnectionSource
            {
                Port = 11502,
                Host = "127.0.0.1",
                Name = "localhost Tests",
            };

            store.ConnectionsSources.AddByName(connectionSource);

            var facility = new Facility
            {
                Name       = "TestFacility",
                AccessName = "orgName$departmentName$FieldName$wellName",
            };

            store.Facilities.AddByName(facility);



            var device = new ModbusDevice
            {
                Name      = "Plc1",
                FrameType = FrameType.Ip,
                SlaveId   = 1,
            };

            facility.Devices.AddByName(device);

            device.ConnectionSource = connectionSource;

            var tagGroup1 = new TagsGroup {
                Name = "currentData", Min = 10_000_000
            };
            var tagGroup2 = new TagsGroup {
                Name = "settings", Min = 10_000_000
            };


            var tag1 = new MTag
            {
                Groups = new Dictionary <string, TagsGroup>
                {
                    [tagGroup1.Name] = tagGroup1,
                },
                TemplateId = 1,
                Name       = "Tag1",
                Region     = ModbusRegion.HoldingRegisters,
                Begin      = 0,
                ValueType  = Common.ValueType.Int16,
            };

            device.Tags.Add("Tag1", tag1);

            device.Tags.Add("Tag2", new MTag
            {
                Groups = new Dictionary <string, TagsGroup>
                {
                    [tagGroup1.Name] = tagGroup1,
                    [tagGroup2.Name] = tagGroup2,
                },
                TemplateId = 1,
                Name       = "Tag2",
                Region     = ModbusRegion.HoldingRegisters,
                Begin      = 1,
                ValueType  = Common.ValueType.Int16,
            });

            device.Tags.Add("Tag3", new MTag
            {
                Groups = new Dictionary <string, TagsGroup>
                {
                    [tagGroup1.Name] = tagGroup1,
                },
                TemplateId = 2,
                Name       = "Tag3",
                Region     = ModbusRegion.HoldingRegisters,
                Begin      = 2,
                ValueType  = Common.ValueType.Int16,
            });

            device.Tags.Add("Tag4", new MTag
            {
                Groups = new Dictionary <string, TagsGroup>
                {
                    [tagGroup1.Name] = tagGroup1,
                },
                TemplateId = 2,
                Name       = "Tag4",
                Region     = ModbusRegion.HoldingRegisters,
                Begin      = 3,
                ValueType  = Common.ValueType.Float,
            });

            device.Tags.Add("boolTag5", new MTag
            {
                Groups = new Dictionary <string, TagsGroup>
                {
                    [tagGroup1.Name] = tagGroup1,
                },
                TemplateId = 1,
                Name       = "boolTag5",
                Region     = ModbusRegion.Coils,
                Begin      = 3,
                ValueType  = Common.ValueType.Bool,
            });

            store.TagLogService.Configs.Add(new TagLogger.TagLogConfig(tag1)
            {
                Hyst         = 1,
                PeriodMaxSec = 600,
                PeriodMinSec = 1,
                TagLogInfo   = new TagLogger.Entities.TagLogInfo
                {
                    DeviceName         = device.Name,
                    FacilityAccessName = facility.AccessName,
                    TagName            = tag1.Name,
                }
            });


            return(store);
        }