public void Write(TagDouble Tag, Double Value) { if (Tag.Address.Table == Table.HoldingRegisters) { WriteHoldingRegisters(Tag.Address.Index, BitConverter.GetBytes(Value)); } }
private void Update(TagDouble Tag) { int index = (Tag.Address.Index - this.Address.Index) * sizeof(UInt16); Double value = BitConverter.ToDouble(Buffer, index); Tag.ValueSetter(value); }
internal static ITag ParseValue(BinaryReader reader, byte id) { switch (id) { case TagBoolean.TypeId: return(TagBoolean.Parse(reader)); case TagByte.TypeId: return(TagByte.Parse(reader)); case TagShort.TypeId: return(TagShort.Parse(reader)); case TagInt.TypeId: return(TagInt.Parse(reader)); case TagFloat.TypeId: return(TagFloat.Parse(reader)); case TagLong.TypeId: return(TagLong.Parse(reader)); case TagDouble.TypeId: return(TagDouble.Parse(reader)); case TagString.TypeId: return(TagString.Parse(reader)); case TagCompound.TypeId: return(TagCompound.Parse(reader)); case TagList.TypeId: return(TagList.Parse(reader)); default: throw new FormatException("Invalid type ID: " + id + ". At file position " + reader.BaseStream.Position); } }
public void Add(TagDouble Tag, UInt16 Index) { Tag.PLC = this; Tag.Address = new Address { Table = Table.HoldingRegisters, Index = Index }; Add(Tag); }
public override void WritePayload(Stream stream, INamedBinaryTag iTag) { TagDouble tag = iTag as TagDouble; byte[] data = BitConverter.GetBytes(tag.Value); data = data.ReverseIfLittleEndian(); stream.Write(data, 0, 8); }
public ITag Add(string name, double value) { ITag tag; tag = new TagDouble(name, value); this.Add(tag); return(tag); }
public static TagCompound ParseCompound(JsonReader reader, string rootName = "") { TagCompound res = new TagCompound(rootName); string tagName = null; while (reader.Read()) { if (reader.TokenType == JsonToken.PropertyName) { tagName = reader.Value as string; } if (reader.TokenType == JsonToken.Boolean) { bool b = (bool)reader.Value; TagByte tag = new TagByte(tagName, b); res.Set(tag); } else if (reader.TokenType == JsonToken.Integer) { long l = (long)reader.Value; TagLong tag = new TagLong(tagName, l); res.Set(tag); } else if (reader.TokenType == JsonToken.Float) { double d = (double)reader.Value; TagDouble tag = new TagDouble(tagName, d); res.Set(tag); } else if (reader.TokenType == JsonToken.String) { string s = reader.Value as string; TagString tag = new TagString(tagName, s); res.Set(tag); } else if (reader.TokenType == JsonToken.StartObject) { TagCompound tag = ParseCompound(reader); res.Set(tag); } else if (reader.TokenType == JsonToken.StartArray) { TagList list = ParseList(reader, tagName); res.Set(list); } else if (reader.TokenType == JsonToken.EndObject) { return(res); } } return(res); }
public static TagCompound ParseCompound(JsonReader reader, string rootName = "") { TagCompound res = new TagCompound(rootName); string tagName = null; while (reader.Read()) { if (reader.TokenType == JsonToken.PropertyName) { tagName = reader.Value as string; } if (reader.TokenType == JsonToken.Boolean) { bool b = (bool)reader.Value; TagByte tag = new TagByte(tagName, b); res.Set(tag); } else if (reader.TokenType == JsonToken.Integer) { long l = (long)reader.Value; TagLong tag = new TagLong(tagName, l); res.Set(tag); } else if (reader.TokenType == JsonToken.Float) { double d = (double)reader.Value; TagDouble tag = new TagDouble(tagName, d); res.Set(tag); } else if (reader.TokenType == JsonToken.String) { string s = reader.Value as string; TagString tag = new TagString(tagName, s); res.Set(tag); } else if (reader.TokenType == JsonToken.StartObject) { TagCompound tag = ParseCompound(reader); res.Set(tag); } else if (reader.TokenType == JsonToken.StartArray) { TagList list = ParseList(reader, tagName); res.Set(list); } else if (reader.TokenType == JsonToken.EndObject) { return res; } } return res; }
public void ConstructorWithValueTest() { // arrange TagDouble tag; double value; value = double.MaxValue; // act tag = new TagDouble(value); // assert Assert.IsEmpty(tag.Name); Assert.AreEqual(value, tag.Value); }
public void ConstructorTest() { // arrange TagDouble tag; double expected; expected = 0; // act tag = new TagDouble(); // assert Assert.IsEmpty(tag.Name); Assert.AreEqual(expected, tag.Value); }
public void Equals_returns_false_with_different_value() { // arrange TagDouble target; TagDouble other; bool actual; target = new TagDouble(string.Empty, 8.98846567431158E+307); other = new TagDouble(string.Empty, 5.99231044954105E+307); // act actual = target.Equals(other); // assert Assert.IsFalse(actual); }
public void Constructor_sets_name() { // arrange TagDouble target; string expected; string actual; expected = "Alphatag"; // act target = new TagDouble(expected); // assert actual = target.Name; Assert.AreEqual(expected, actual); }
public void Equals_returns_false_with_different_name() { // arrange TagDouble target; TagDouble other; bool actual; target = new TagDouble("Alpha", 8.98846567431158E+307); other = new TagDouble("Beta", 8.98846567431158E+307); // act actual = target.Equals(other); // assert Assert.IsFalse(actual); }
public void Equals_returns_true_for_matching_tag() { // arrange TagDouble target; TagDouble other; bool actual; target = new TagDouble("alpha", 8.98846567431158E+307); other = new TagDouble("alpha", 8.98846567431158E+307); // act actual = target.Equals(other); // assert Assert.IsTrue(actual); }
public void Constructor_sets_value() { // arrange TagDouble target; double expected; double actual; expected = 8.98846567431158E+307; // act target = new TagDouble(string.Empty, expected); // assert actual = target.Value; Assert.Equal(expected, actual); }
public void Constructor_sets_default_name() { // arrange TagDouble target; string expected; string actual; expected = string.Empty; // act target = new TagDouble(); // assert actual = target.Name; Assert.AreEqual(expected, actual); }
public void Constructor_sets_value_without_name() { // arrange TagDouble target; double expected; double actual; expected = 8.98846567431158E+307; // act target = new TagDouble(expected); // assert actual = target.Value; Assert.AreEqual(expected, actual); }
public void Constructor_sets_default_value() { // arrange TagDouble target; double expected; double actual; expected = 0; // act target = new TagDouble(); // assert actual = target.Value; Assert.AreEqual(expected, actual); }
public void ConstructorWithNameAndValueTest() { // arrange TagDouble tag; string name; double value; name = "creationDate"; value = double.MaxValue; // act tag = new TagDouble(name, value); // assert Assert.AreEqual(name, tag.Name); Assert.AreEqual(value, tag.Value); }
public void ConstructorWithNameTest() { // arrange TagDouble tag; string name; double expected; name = "creationDate"; expected = 0; // act tag = new TagDouble(name); // assert Assert.AreEqual(name, tag.Name); Assert.AreEqual(expected, tag.Value); }
public void Type_returns_correct_value() { // arrange TagDouble target; TagType expected; TagType actual; target = new TagDouble(); expected = TagType.Double; // act actual = target.Type; // assert Assert.AreEqual(expected, actual); }
public void GetHashCode_returns_same_value_for_matching_tags() { // arrange TagDouble target; int actual; int expected; target = new TagDouble("beta", 8.98846567431158E+307); expected = new TagDouble("beta", 8.98846567431158E+307).GetHashCode(); // act actual = target.GetHashCode(); // assert Assert.AreEqual(expected, actual); }
public void ToString_returns_string_version_of_tag() { // arrange TagDouble target; string expected; string actual; expected = "[Double: gamma=8.98846567431158E+307]"; target = new TagDouble("gamma", 8.98846567431158E+307); // act actual = target.ToString(); // assert Assert.AreEqual(expected, actual); }
public void ToValueString_returns_string_version_of_value() { // arrange TagDouble target; string expected; string actual; expected = "8.98846567431158E+307"; target = new TagDouble(string.Empty, 8.98846567431158E+307); // act actual = target.ToValueString(); // assert Assert.AreEqual(expected, actual); }
public void GetHashCode_returns_different_values_with_different_value() { // arrange TagDouble target; int actual; int notExpected; target = new TagDouble(string.Empty, 8.98846567431158E+307); notExpected = new TagDouble(string.Empty, 5.99231044954105E+307).GetHashCode(); // act actual = target.GetHashCode(); // assert Assert.AreNotEqual(notExpected, actual); }
public void GetHashCode_returns_different_values_with_different_name() { // arrange TagDouble target; int actual; int notExpected; target = new TagDouble("Alpha", 8.98846567431158E+307); notExpected = new TagDouble("Beta", 8.98846567431158E+307).GetHashCode(); // act actual = target.GetHashCode(); // assert Assert.AreNotEqual(notExpected, actual); }
public void Value_can_be_set() { // arrange TagDouble target; double expected; double actual; expected = 8.98846567431158E+307; target = new TagDouble(); // act target.Value = expected; // assert actual = target.Value; Assert.AreEqual(expected, actual); }
public void SetValue_updates_value() { // arrange Tag target; double expected; double actual; target = new TagDouble(); expected = 8.98846567431158E+307; // act target.SetValue(expected); // assert actual = ((TagDouble)target).Value; Assert.AreEqual(expected, actual); }
public override object ParsePayload(Stream stream, INamedBinaryTag tagBase) { byte[] data = new byte[8]; if (stream.Read(data, 0, 8) < 8) { throw new EndOfStreamException("End of stream reached inside of tag. Put those bytes back!"); } data = data.ReverseIfLittleEndian(); double val = BitConverter.ToDouble(data, 0); TagDouble tag = tagBase as TagDouble; if (tag == null) { throw new InvalidCastException("Wrong NBT type! Expected TagDouble, found " + tagBase.GetType().Name); } tag.Value = val; return(val); }
public void ToStringTest() { // arrange TagDouble target; string expected; string actual; string name; double value; name = "tagname"; value = double.MaxValue; expected = string.Format("[Double: {0}={1}]", name, value); target = new TagDouble(name, value); // act actual = target.ToString(); // assert Assert.AreEqual(expected, actual); }
public void NameTest() { // arrange TagDouble target; string expected; target = new TagDouble(); expected = "newvalue"; // act target.Name = expected; // assert Assert.AreEqual(expected, target.Name); }
private void Update(TagDouble Tag) { int index = (Tag.Address.Index - this.Address.Index) * sizeof(UInt16); Double value = BitConverter.ToDouble(Buffer, index); Tag.ValueSetter(value); }
public void ToValueStringTest() { // arrange ITag target; string expected; string actual; double value; value = double.MaxValue; expected = value.ToString(CultureInfo.InvariantCulture); target = new TagDouble(value); // act actual = target.ToValueString(); // assert Assert.AreEqual(expected, actual); }
public static TagList ParseList(JsonReader reader, string rootName) { TagList list = new TagList(rootName); bool foundGeneric = false; while (reader.Read()) { if (reader.TokenType == JsonToken.Boolean) { if (!foundGeneric) { foundGeneric = true; list.GenericType = ETagType.Byte; } bool b = (bool)reader.Value; TagByte tag = new TagByte(null, b); list.Add(tag); } else if (reader.TokenType == JsonToken.Integer) { if (!foundGeneric) { foundGeneric = true; list.GenericType = ETagType.Long; } long l = (long)reader.Value; TagLong tag = new TagLong(null, l); list.Add(tag); } else if (reader.TokenType == JsonToken.Float) { if (!foundGeneric) { foundGeneric = true; list.GenericType = ETagType.Float; } else if (list.GenericType == ETagType.Long) { List<TagDouble> buf = new List<TagDouble>(); foreach (TagLong tl in list) { buf.Add(new TagDouble(tl.Name, tl.Value)); } list.Clear(); list.GenericType = ETagType.Double; foreach (TagDouble td in buf) { list.Add(td); } } double d = (double)reader.Value; TagDouble tag = new TagDouble(null, d); list.Add(tag); } else if (reader.TokenType == JsonToken.String) { if (!foundGeneric) { foundGeneric = true; list.GenericType = ETagType.String; } string s = reader.Value as string; TagString tag = new TagString(null, s); list.Add(tag); } else if (reader.TokenType == JsonToken.StartObject) { if (!foundGeneric) { foundGeneric = true; list.GenericType = ETagType.Compound; } TagCompound tag = ParseCompound(reader, null); list.Add(tag); } else if (reader.TokenType == JsonToken.StartArray) { if (!foundGeneric) { foundGeneric = true; list.GenericType = ETagType.List; } TagList inner = ParseList(reader, null); list.Add(inner); } else if (reader.TokenType == JsonToken.EndArray) { return list; } else { throw new NotImplementedException("Currently no handling for this type of JSON token: " + reader.TokenType.ToString()); } } return list; }
public void ValueTest() { // arrange TagDouble target; double expected; target = new TagDouble(); expected = double.MaxValue; // act target.Value = expected; // assert Assert.AreEqual(expected, target.Value); }
public void TypeTest() { // arrange TagType expected; TagType actual; expected = TagType.Double; // act actual = new TagDouble().Type; // assert Assert.AreEqual(expected, actual); }
public void ToStringWithIndentTest() { // arrange TagDouble target; string expected; string actual; string name; double value; string prefix; prefix = "test"; name = "tagname"; value = double.MaxValue; expected = string.Format("{2}[Double: {0}={1}]", name, value, prefix); target = new TagDouble(name, value); // act actual = target.ToString(prefix); // assert Assert.AreEqual(expected, actual); }
public Tag ExportTag() { tc ["SleepTimer"] = new TagShort(SleepTimer); TagList<TagDouble > motion = new TagList<TagDouble>(); motion [0] = new TagDouble(Motion [0]); motion [1] = new TagDouble(Motion [1]); motion [2] = new TagDouble(Motion [2]); tc ["Motion"] = motion; tc ["OnGround"] = new TagByte(){Byte = OnGround}; tc ["HurtTime"] = new TagShort(HurtTime); tc ["Health"] = new TagShort(Health); tc ["Dimension"] = new TagInt(Dimension); tc ["Air"] = new TagShort(Air); if (tc ["Inventory"] is TagList<TagCompound> == false) { tc ["Inventory"] = new TagList<TagCompound>(); } TagList<TagCompound > inv = tc ["Inventory"] as TagList<TagCompound>; for (byte n = 0; n < 104; n++) { SlotItem item = null; if (n < 36) item = Inventory [n]; if (n >= 80 && n < 84) item = InventoryCraft [n - 80]; if (n >= 100) item = InventoryWear [n - 100]; TagCompound ti = null; //Find slot item foreach (TagCompound itc in inv) { if (itc ["Slot"].Byte == n) { ti = itc; break; } } if (item == null) { if (ti != null) inv.Remove(ti); continue; } if (ti == null) { ti = new TagCompound(); inv.Add(ti); } ti ["id"] = new TagShort((short)item.ItemID); ti ["Damage"] = new TagShort((short)item.Uses); ti ["Count"] = new TagByte((byte)item.Count); ti ["Slot"] = new TagByte(n); } inv.Sort((x, y) => x ["Slot"].Byte - y ["Slot"].Byte); TagList<TagDouble > p = new TagList<TagDouble>(); p [0] = new TagDouble(Pos .X); p [1] = new TagDouble(Pos .Y); p [2] = new TagDouble(Pos .Z); tc ["Pos"] = p; tc ["AttackTime"] = new TagShort(AttackTime); tc ["Sleeping"] = new TagByte(Sleeping); tc ["Fire"] = new TagShort(Fire); tc ["FallDistance"] = new TagFloat(FallDistance); TagList<TagFloat > rot = new TagList<TagFloat>(); rot [0] = new TagFloat(Rotation [0]); rot [1] = new TagFloat(Rotation [1]); tc ["Rotation"] = rot; tc ["DeathTime"] = new TagShort(DeathTime); if (Spawn != null) { tc ["SpawnX"] = new TagInt(Spawn.X); tc ["SpawnY"] = new TagInt(Spawn.Y); tc ["SpawnZ"] = new TagInt(Spawn.Z); } tc ["foodExhaustionLevel"] = new TagFloat(foodExhaustionLevel); tc ["foodTickTimer"] = new TagInt(foodTickTimer); tc ["foodSaturationLevel"] = new TagFloat(foodSaturationLevel); tc ["foodLevel"] = new TagInt(foodLevel); tc ["XpLevel"] = new TagInt(XpLevel); tc ["XpTotal"] = new TagInt(XpTotal); tc ["Xp"] = new TagInt(Xp); tc ["playerGameType"] = new TagInt(playerGameType); return tc; }
public void TestLoadComplexNbt() { Tag tag; tag = this.CreateComplexData(); Assert.IsNotNull(tag); Assert.IsInstanceOf <TagCompound>(tag); TagCompound level = tag as TagCompound; Assert.AreEqual("Level", level.Name); TagShort shortTest = level.GetShort("shortTest"); Assert.IsNotNull(shortTest); Assert.AreEqual("shortTest", shortTest.Name); Assert.AreEqual(32767, shortTest.Value); TagLong longTest = level.GetLong("longTest"); Assert.IsNotNull(longTest); Assert.AreEqual("longTest", longTest.Name); Assert.AreEqual(9223372036854775807, longTest.Value); TagFloat floatTest = level.GetFloat("floatTest"); Assert.IsNotNull(floatTest); Assert.AreEqual("floatTest", floatTest.Name); Assert.AreEqual(0.49823147f, floatTest.Value); TagString stringTest = level.GetString("stringTest"); Assert.IsNotNull(stringTest); Assert.AreEqual("stringTest", stringTest.Name); Assert.AreEqual("HELLO WORLD THIS IS A TEST STRING едж!", stringTest.Value); TagInt intTest = level.GetInt("intTest"); Assert.IsNotNull(intTest); Assert.AreEqual("intTest", intTest.Name); Assert.AreEqual(2147483647, intTest.Value); TagCompound nestedCompoundTest = level.GetCompound("nested compound test"); Assert.IsNotNull(nestedCompoundTest); Assert.AreEqual("nested compound test", nestedCompoundTest.Name); TagCompound ham = nestedCompoundTest.GetCompound("ham"); Assert.IsNotNull(ham); Assert.AreEqual("ham", ham.Name); TagString ham_name = ham.GetString("name"); Assert.IsNotNull(ham_name); Assert.AreEqual("name", ham_name.Name); Assert.AreEqual("Hampus", ham_name.Value); TagFloat ham_value = ham.GetFloat("value"); Assert.IsNotNull(ham_value); Assert.AreEqual("value", ham_value.Name); Assert.AreEqual(0.75f, ham_value.Value); TagCompound egg = nestedCompoundTest.GetCompound("egg"); Assert.IsNotNull(egg); Assert.AreEqual("egg", egg.Name); TagString egg_name = egg.GetString("name"); Assert.IsNotNull(egg_name); Assert.AreEqual("name", egg_name.Name); Assert.AreEqual("Eggbert", egg_name.Value); TagFloat egg_value = egg.GetFloat("value"); Assert.IsNotNull(egg_value); Assert.AreEqual("value", egg_value.Name); Assert.AreEqual(0.5f, egg_value.Value); TagByte byteTest = level.GetByte("byteTest"); Assert.IsNotNull(byteTest); Assert.AreEqual("byteTest", byteTest.Name); Assert.AreEqual(0x7f, byteTest.Value); TagDouble doubleTest = level.GetDouble("doubleTest"); Assert.IsNotNull(doubleTest); Assert.AreEqual("doubleTest", doubleTest.Name); Assert.AreEqual(0.4931287132182315, doubleTest.Value); TagList listTest_long = level.GetList("listTest (long)"); Assert.IsNotNull(listTest_long); Assert.AreEqual("listTest (long)", listTest_long.Name); Assert.IsNotNull(listTest_long.Value); Assert.AreEqual(5, listTest_long.Value.Count); Assert.AreEqual(11, (listTest_long.Value[0] as TagLong).Value); Assert.AreEqual(12, (listTest_long.Value[1] as TagLong).Value); Assert.AreEqual(13, (listTest_long.Value[2] as TagLong).Value); Assert.AreEqual(14, (listTest_long.Value[3] as TagLong).Value); Assert.AreEqual(15, (listTest_long.Value[4] as TagLong).Value); TagList listTest_compound = level.GetList("listTest (compound)"); Assert.IsNotNull(listTest_compound); Assert.AreEqual("listTest (compound)", listTest_compound.Name); Assert.IsNotNull(listTest_compound.Value); Assert.AreEqual(2, listTest_compound.Value.Count); TagCompound listTest_compound_tag0 = listTest_compound.Value[0] as TagCompound; Assert.IsNotNull(listTest_compound_tag0); TagString listTest_compound_tag0_name = listTest_compound_tag0.GetString("name"); Assert.IsNotNull(listTest_compound_tag0_name); Assert.AreEqual("name", listTest_compound_tag0_name.Name); Assert.AreEqual("Compound tag #0", listTest_compound_tag0_name.Value); TagLong listTest_compound_tag0_createdOn = listTest_compound_tag0.GetLong("created-on"); Assert.IsNotNull(listTest_compound_tag0_createdOn); Assert.AreEqual("created-on", listTest_compound_tag0_createdOn.Name); Assert.AreEqual(1264099775885, listTest_compound_tag0_createdOn.Value); TagCompound listTest_compound_tag1 = listTest_compound.Value[1] as TagCompound; Assert.IsNotNull(listTest_compound_tag1); TagString listTest_compound_tag1_name = listTest_compound_tag1.GetString("name"); Assert.IsNotNull(listTest_compound_tag1_name); Assert.AreEqual("name", listTest_compound_tag1_name.Name); Assert.AreEqual("Compound tag #1", listTest_compound_tag1_name.Value); TagLong listTest_compound_tag1_createdOn = listTest_compound_tag1.GetLong("created-on"); Assert.IsNotNull(listTest_compound_tag1_createdOn); Assert.AreEqual("created-on", listTest_compound_tag1_createdOn.Name); Assert.AreEqual(1264099775885, listTest_compound_tag1_createdOn.Value); TagByteArray byteArrayTest = level.GetByteArray("byteArrayTest (the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...))"); Assert.IsNotNull(byteArrayTest); Assert.AreEqual("byteArrayTest (the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...))", byteArrayTest.Name); Assert.IsNotNull(byteArrayTest.Value); Assert.AreEqual(1000, byteArrayTest.Value.Length); }
public static TagList ParseList(JsonReader reader, string rootName) { TagList list = new TagList(rootName); bool foundGeneric = false; while (reader.Read()) { if (reader.TokenType == JsonToken.Boolean) { if (!foundGeneric) { foundGeneric = true; list.GenericType = ETagType.Byte; } bool b = (bool)reader.Value; TagByte tag = new TagByte(null, b); list.Add(tag); } else if (reader.TokenType == JsonToken.Integer) { if (!foundGeneric) { foundGeneric = true; list.GenericType = ETagType.Long; } long l = (long)reader.Value; TagLong tag = new TagLong(null, l); list.Add(tag); } else if (reader.TokenType == JsonToken.Float) { if (!foundGeneric) { foundGeneric = true; list.GenericType = ETagType.Float; } else if (list.GenericType == ETagType.Long) { List <TagDouble> buf = new List <TagDouble>(); foreach (TagLong tl in list) { buf.Add(new TagDouble(tl.Name, tl.Value)); } list.Clear(); list.GenericType = ETagType.Double; foreach (TagDouble td in buf) { list.Add(td); } } double d = (double)reader.Value; TagDouble tag = new TagDouble(null, d); list.Add(tag); } else if (reader.TokenType == JsonToken.String) { if (!foundGeneric) { foundGeneric = true; list.GenericType = ETagType.String; } string s = reader.Value as string; TagString tag = new TagString(null, s); list.Add(tag); } else if (reader.TokenType == JsonToken.StartObject) { if (!foundGeneric) { foundGeneric = true; list.GenericType = ETagType.Compound; } TagCompound tag = ParseCompound(reader, null); list.Add(tag); } else if (reader.TokenType == JsonToken.StartArray) { if (!foundGeneric) { foundGeneric = true; list.GenericType = ETagType.List; } TagList inner = ParseList(reader, null); list.Add(inner); } else if (reader.TokenType == JsonToken.EndArray) { return(list); } else { throw new NotImplementedException("Currently no handling for this type of JSON token: " + reader.TokenType.ToString()); } } return(list); }
public void Write(TagDouble Tag, Double Value) { if (Tag.Address.Table == Table.HoldingRegisters) { WriteHoldingRegisters(Tag.Address.Index, BitConverter.GetBytes(Value)); } }
/// <summary> /// Creates a tag for the specified parameters. /// </summary> /// <exception cref="ArgumentException">Thrown if <paramref name="tagType"/> is not valid.</exception> /// <param name="tagType">Type of the tag to create.</param> /// <param name="name">The name of the tag create.</param> /// <param name="listType">The type of items a list holds.</param> /// <returns> /// A new tag using the specified parameters. /// </returns> public static Tag CreateTag(string name, TagType tagType, TagType listType) { Tag result; if (tagType != TagType.List) { if (listType != TagType.None) { throw new ArgumentException("Only lists can have a list type.", nameof(listType)); } switch (tagType) { case TagType.Byte: result = new TagByte(name); break; case TagType.Short: result = new TagShort(name); break; case TagType.Int: result = new TagInt(name); break; case TagType.Long: result = new TagLong(name); break; case TagType.Float: result = new TagFloat(name); break; case TagType.Double: result = new TagDouble(name); break; case TagType.ByteArray: result = new TagByteArray(name); break; case TagType.String: result = new TagString(name); break; case TagType.Compound: result = new TagCompound(name); break; case TagType.IntArray: result = new TagIntArray(name); break; case TagType.End: result = new TagEnd(); break; default: throw new ArgumentException("Unrecognized or unsupported tag type.", nameof(tagType)); } } else { result = new TagList(name, listType); } return(result); }
public void Add(TagDouble Tag, UInt16 Index) { Tag.PLC = this; Tag.Address = new Address { Table = Table.HoldingRegisters, Index = Index }; Add(Tag); }