Exemplo n.º 1
0
        public void EnumTest()
        {
            var pm = new ModbusTcpParameter
            {
                Server = "127.0.0.1:502",

                Host      = 1,
                ReadCode  = FunctionCodes.ReadRegister,
                WriteCode = FunctionCodes.WriteRegister,
            };

            var xml = new NewLife.Serialization.Xml
            {
                //Encoding = encoding,
                UseAttribute = false,
                UseComment   = true
            };

            xml.Write(pm);

            var str = xml.GetString();

            Assert.Equal(@"<ModbusTcpParameter>
  <!--主机/站号-->
  <Host>1</Host>
  <!--读取功能码。若点位地址未指定区域,则采用该功能码-->
  <ReadCode>ReadRegister</ReadCode>
  <!--写入功能码。若点位地址未指定区域,则采用该功能码-->
  <WriteCode>WriteRegister</WriteCode>
  <!--地址。tcp地址如127.0.0.1:502-->
  <Server>127.0.0.1:502</Server>
  <!--协议标识。默认0-->
  <ProtocolId>0</ProtocolId>
</ModbusTcpParameter>", str);

            var xml2 = new NewLife.Serialization.Xml
            {
                //Encoding = encoding,
                UseAttribute = false,
                UseComment   = true,
                EnumString   = false,
            };

            xml2.Write(pm);

            var str2 = xml2.GetString();

            Assert.Equal(@"<ModbusTcpParameter>
  <!--主机/站号-->
  <Host>1</Host>
  <!--读取功能码。若点位地址未指定区域,则采用该功能码-->
  <ReadCode>3</ReadCode>
  <!--写入功能码。若点位地址未指定区域,则采用该功能码-->
  <WriteCode>6</WriteCode>
  <!--地址。tcp地址如127.0.0.1:502-->
  <Server>127.0.0.1:502</Server>
  <!--协议标识。默认0-->
  <ProtocolId>0</ProtocolId>
</ModbusTcpParameter>", str2);
        }
Exemplo n.º 2
0
        public void EnumTest()
        {
            var pm = new ModbusTcpParameter
            {
                Server = "127.0.0.1:502",

                Host      = 1,
                ReadCode  = FunctionCodes.ReadRegister,
                WriteCode = FunctionCodes.WriteRegister,
            };

            var xml = new NewLife.Serialization.Xml
            {
                //Encoding = encoding,
                UseAttribute = false,
                UseComment   = true
            };

            xml.Write(pm);

            var str = xml.GetString();

            Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<ModbusTcpParameter>
  <Host>1</Host>
  <ReadCode>ReadRegister</ReadCode>
  <WriteCode>WriteRegister</WriteCode>
  <Server>127.0.0.1:502</Server>
  <ProtocolId>0</ProtocolId>
</ModbusTcpParameter>", str);

            var xml2 = new NewLife.Serialization.Xml
            {
                //Encoding = encoding,
                UseAttribute = false,
                UseComment   = true,
                EnumString   = false,
            };

            xml2.Write(pm);

            var str2 = xml2.GetString();

            Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<ModbusTcpParameter>
  <Host>1</Host>
  <ReadCode>3</ReadCode>
  <WriteCode>6</WriteCode>
  <Server>127.0.0.1:502</Server>
  <ProtocolId>0</ProtocolId>
</ModbusTcpParameter>", str2);
        }