Beispiel #1
0
        public override void Read(Plc _plc)
        {
            if (this.ReadHandler != null)
            {
                ReadEventArgs e = new ReadEventArgs();
                e.ReadID    = ID;
                e.StartTime = System.DateTime.Now;
                try
                {
                    foreach (var dic in Items)
                    {
                        var buffer = _plc.ReadBytes(dic.Value.DataType, dic.Value.DB, dic.Value.StartByteAdr, dic.Value.Count);
                        dic.Value.Value = FilterChar(System.Text.Encoding.GetEncoding("GB2312").GetString(buffer).Trim());
                        buffer          = null;
                    }
                    e.Result = true;
                }
                catch (Exception ex)
                {
                    e.Result   = false;
                    e.ErrorMsg = ex.Message;
                }
                e.EndTime = System.DateTime.Now;
                e.Data    = new Dictionary <string, object>();
                foreach (var dic in Items)
                {
                    e.Data.Add(dic.Key, dic.Value.Value);
                }

                this.ReadHandler(this, e);
            }
        }
Beispiel #2
0
        public override void Read(Plc _plc)
        {
            if (this.ReadHandler != null)
            {
                ReadEventArgs e = new ReadEventArgs();
                e.ReadID    = ID;
                e.StartTime = System.DateTime.Now;
                try
                {
                    _plc.ReadMultipleVars(Items.Values.ToList());
                    e.Result = true;
                }
                catch (Exception ex)
                {
                    e.Result   = false;
                    e.ErrorMsg = ex.Message;
                }
                e.EndTime = System.DateTime.Now;
                e.Data    = new Dictionary <string, object>();
                foreach (var dic in Items)
                {
                    e.Data.Add(dic.Key, dic.Value.Value);
                }

                this.ReadHandler(this, e);
            }
        }
Beispiel #3
0
 private static void Reader_ReadHandler(object sender, ReadEventArgs e)
 {
     Console.WriteLine(string.Format("*******本次耗时:{0}毫秒*******", (e.EndTime - e.StartTime).TotalMilliseconds));
     if (e.Result)
     {
         foreach (var item in e.Data)
         {
             if (item.Key.EndsWith(".CPH"))
             {
                 Console.WriteLine(string.Format("{0}={1}", item.Key, item.Value));
             }
             else
             {
                 Console.WriteLine(string.Format("{0}={1}", item.Key, item.Value));
             }
         }
     }
     else
     {
         Console.WriteLine(e.ErrorMsg);
     }
 }