public void write(DeviceStateInfoModel obj) { List <DeviceStateInfoModel> list = new List <DeviceStateInfoModel>(); if (File.Exists(Path.Combine(fileLogPath + dataFile))) { list = XmlOper.XmlDeserializeFromFile <List <DeviceStateInfoModel> >(Path.Combine(fileLogPath + dataFile), Encoding.UTF8); if (list == null) { list = new List <DeviceStateInfoModel>(); } } if (list.Count == 0) { list.Add(obj); XmlOper.XmlSerializeToFile(list, fileLogPath, dataFile, Encoding.UTF8); return; } var model = list.Where(w => w.DeviceNo == obj.DeviceNo).FirstOrDefault(); if (model != null) { model.AlarmsValue = obj.AlarmsValue; } else { list.Add(obj); } XmlOper.XmlSerializeToFile(list, fileLogPath, dataFile, Encoding.UTF8); }
/// <summary> /// 写报警记录,包括异常清除写入 /// </summary> /// <param name="type"></param> /// <param name="len"></param> /// <param name="temp"></param> /// <param name="GroupNo"></param> /// <param name="type">1皮带 2 烟柜 3 机械手</param> public void WriteErrWithCheck(string len, int GroupNo, String temp, int type) { String deviceNo = "" + len; string lastInfo = fileOper.ReadLastInfo(deviceNo).Trim(); string compStrs; if (temp == null || temp == "") { return; } List <OperationChar> lst = UnionBit.Union(lastInfo, temp, out compStrs); List <OperationChar> lstWhere = lst.Where(w => w.op != Oper.None).ToList(); bool isneedWrite = false; foreach (OperationChar item in lstWhere) { isneedWrite = false; if (type == 1) { if (item.bit == 13 || item.bit == 15 || (item.bit >= 1 && item.bit <= 6))//5 9 10 11 12 13 14 { isneedWrite = true; } } else if (type == 2) { if ((item.bit >= 9 && item.bit <= 14))//9 10 11 12 13 14 { isneedWrite = true; } } else if (type == 3) // 6 7 { if ((item.bit >= 14 && item.bit <= 15)) { isneedWrite = true; } } if (isneedWrite) { String errMsg = item.val == "0" ? string.Format("消除{0}", OnGetErr(item.bit, type)) : OnGetErr(item.bit, type); ErrListService.Add(deviceNo, GroupNo, 10, errMsg, item.val); DeviceStateInfoModel info = new DeviceStateInfoModel { DeviceNo = len, DeviceName = deviceNo, ErrInfo = errMsg }; if (AlarmsHandler != null) { AlarmsHandler(info); } } } fileOper.write(new DeviceStateInfoModel { DeviceNo = deviceNo, AlarmsValue = temp }); }