コード例 #1
0
ファイル: S7NetDrive.cs プロジェクト: zzpgeorge/BetterIOT
        public override IEnumerable <IOTData> GetData()
        {
            List <IOTData> iOTs = new List <IOTData>();

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

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

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

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

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

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

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

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

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

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

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

                    case "DATETIME":
                        sResult = siemensTcpNet.ReadDateTime(result.DB).Content.ToString();
                        break;

                    default:
                        sResult = siemensTcpNet.ReadString(result.DB).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);
        }
コード例 #2
0
 private void Button7_Click(object sender, EventArgs e)
 {
     // 读取时间
     DemoUtils.ReadResultRender(siemensTcpNet.ReadDateTime(textBox3.Text), textBox3.Text, textBox4);
 }