public void ReadExample( )
        {
            #region ReadExample1


            SiemensFetchWriteNet siemensTcpNet = new SiemensFetchWriteNet(" 192.168.1.110", 2000);

            // 此处以M100寄存器作为示例
            byte   byte_M100   = siemensTcpNet.ReadByte("M100").Content;       // 读取M100的值
            short  short_M100  = siemensTcpNet.ReadInt16("M100").Content;      // 读取M100-M101组成的字
            ushort ushort_M100 = siemensTcpNet.ReadUInt16("M100").Content;     // 读取M100-M101组成的无符号的值
            int    int_M100    = siemensTcpNet.ReadInt32("M100").Content;      // 读取M100-M103组成的有符号的数据
            uint   uint_M100   = siemensTcpNet.ReadUInt32("M100").Content;     // 读取M100-M103组成的无符号的值
            float  float_M100  = siemensTcpNet.ReadFloat("M100").Content;      // 读取M100-M103组成的单精度值
            long   long_M100   = siemensTcpNet.ReadInt64("M100").Content;      // 读取M100-M107组成的大数据值
            ulong  ulong_M100  = siemensTcpNet.ReadUInt64("M100").Content;     // 读取M100-M107组成的无符号大数据
            double double_M100 = siemensTcpNet.ReadDouble("M100").Content;     // 读取M100-M107组成的双精度值
            string str_M100    = siemensTcpNet.ReadString("M100", 10).Content; // 读取M100-M109组成的ASCII字符串数据

            // 读取数组
            short[]  short_M100_array  = siemensTcpNet.ReadInt16("M100", 10).Content;  // 读取M100-M101组成的字
            ushort[] ushort_M100_array = siemensTcpNet.ReadUInt16("M100", 10).Content; // 读取M100-M101组成的无符号的值
            int[]    int_M100_array    = siemensTcpNet.ReadInt32("M100", 10).Content;  // 读取M100-M103组成的有符号的数据
            uint[]   uint_M100_array   = siemensTcpNet.ReadUInt32("M100", 10).Content; // 读取M100-M103组成的无符号的值
            float[]  float_M100_array  = siemensTcpNet.ReadFloat("M100", 10).Content;  // 读取M100-M103组成的单精度值
            long[]   long_M100_array   = siemensTcpNet.ReadInt64("M100", 10).Content;  // 读取M100-M107组成的大数据值
            ulong[]  ulong_M100_array  = siemensTcpNet.ReadUInt64("M100", 10).Content; // 读取M100-M107组成的无符号大数据
            double[] double_M100_array = siemensTcpNet.ReadDouble("M100", 10).Content; // 读取M100-M107组成的双精度值

            #endregion
        }
 private void button_read_double_Click(object sender, EventArgs e)
 {
     // 读取double变量
     if (textBox12.Text == "1")
     {
         DemoUtils.ReadResultRender(siemensFWNet.ReadDouble(textBox3.Text), textBox3.Text, textBox4);
     }
     else
     {
         DemoUtils.ReadResultRender(siemensFWNet.ReadDouble(textBox3.Text, ushort.Parse(textBox12.Text)), textBox3.Text, textBox4);
     }
 }
Exemplo n.º 3
0
        public override IEnumerable <IOTData> GetData()
        {
            List <IOTData> iOTs = new List <IOTData>();

            foreach (SiemensFetchWriteResult result in DriveConfig.Results)
            {
                try
                {
                    string sResult;
                    switch (result.DataType.ToUpper())
                    {
                    case "BOOL":
                        sResult = siemensFWNet.ReadBool(result.DB).Content.ToString();
                        break;

                    case "STRING":
                        sResult = siemensFWNet.ReadString(result.DB, Convert.ToUInt16(result.Len)).Content;
                        break;

                    case "INT":
                        sResult = siemensFWNet.ReadInt32(result.DB).Content.ToString();
                        break;

                    case "FLOAT":
                        sResult = siemensFWNet.ReadFloat(result.DB).Content.ToString(result.Format);
                        break;

                    case "DOUBLE":
                        sResult = siemensFWNet.ReadDouble(result.DB).Content.ToString(result.Format);
                        break;

                    case "BYTE":
                        sResult = siemensFWNet.ReadByte(result.DB).Content.ToString();
                        break;

                    case "SHORT":
                        sResult = siemensFWNet.ReadInt16(result.DB).Content.ToString();
                        break;

                    case "USHORT":
                        sResult = siemensFWNet.ReadUInt16(result.DB).Content.ToString();
                        break;

                    case "UINT":
                        sResult = siemensFWNet.ReadUInt32(result.DB).Content.ToString();
                        break;

                    case "LONG":
                        sResult = siemensFWNet.ReadInt64(result.DB).Content.ToString();
                        break;

                    case "ULONG":
                        sResult = siemensFWNet.ReadUInt64(result.DB).Content.ToString();
                        break;

                    default:
                        sResult = siemensFWNet.ReadString(result.DB, 1).Content;
                        break;
                    }
                    iOTs.Add(new IOTData
                    {
                        DataCode  = result.Address,
                        DataValue = sResult,
                        DataName  = result.Name,
                        DriveCode = DriveConfig.DriveCode,
                        DriveType = DriveConfig.DriveType,
                        GTime     = DateTime.Now,
                        Unit      = result.Unit
                    });
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
            return(iOTs);
        }
 private void button_read_double_Click(object sender, EventArgs e)
 {
     // 读取double变量
     readResultRender(siemensFWNet.ReadDouble(textBox3.Text), textBox3.Text, textBox4);
 }