public void Write1(DateTime time, Int32[] ipids, decimal[] values) { for (int i = 0; i < ipids.Length; i++) { SkNowval nv = new SkNowval(); nv.Ipid = ipids[i]; nv.Value.Value = values[i]; nv.Value.Status = 1; nv.Value.Time = time; nval.Add(nv); } if (nval.Count >= 1000) { int errorCode = -1; while (errorCode != 0) { connection.SetNowValue(nval, out errorCode); //log.Write(errorCode + ""); if (errorCode != 0) { Thread.Sleep(20); } } nval.Clear(); } }
public void Write(DateTime time, Int32[] ipids, decimal[] values) { for (int i = 0; i < ipids.Length; i++) { SkNowval nv = new SkNowval(); nv.Ipid = ipids[i]; nv.Value.Value = values[i]; nv.Value.Status = 1; nv.Value.Time = time; if (buffer.ContainsKey(ipids[i])) { buffer[ipids[i]].Add(nv); } else { List <SkNowval> lst = new List <SkNowval>(); lst.Add(nv); buffer.Add(ipids[i], lst); } } if (buffer.Count > 1000) { for (; buffer.Count != 0;) { List <SkNowval> sl = new List <SkNowval>(); foreach (List <SkNowval> lst in buffer.Values) { int cnt = lst.Count > 100 ? 100 : lst.Count; sl.AddRange(lst.GetRange(0, cnt)); lst.RemoveRange(0, cnt); } int errorCode = -1; while (errorCode != 0) { errorCode = 0; connection.SetNowValue(sl, out errorCode); //log.Write(errorCode + ""); if (errorCode != 0) { Thread.Sleep(20); } } for (int i = 0; i < sl.Count; i++) { if (buffer.ContainsKey(sl[i].Ipid)) { if (buffer[sl[i].Ipid].Count == 0) { buffer.Remove(sl[i].Ipid); } } } sl.Clear(); } } }