/*public OperationResult TryReadAvPower3min(IIODriverClient channel, string psw, DeviceCompOn deviceTime, TimeZoneMap map, RequestIndex request, DateTimeZone cutTime, out AvPowerIndex response) * { * response = null; * var result = TryReadPower(channel, psw, request, Codes.CODE_3AVPWR_INX, out response); * if (result.IsGood) if (!response.Check(cutTime)) result = new OperationResult(Quality.Bad, SR.ERROR_CUT); * return result; * } * * OperationResult TryReadPower(IIODriverClient channel, string psw, RequestIndex request, byte action, out AvPowerIndex response) * { * OperationResult result = OperationResult.Bad; * response = null; * var send = CreateRequest(request.Address, action, psw, request.Index, 0, 0); * result = WriteReadCheck(channel, 1, send, out byte[] answer); * * if (!result.IsGood) return result; * var seg = new ByteArraySegment(answer, 0, answer.Length); * try * { * response = new AvPowerIndex * { * Power = new AvPower * { * Pplus = seg.ReadSingle(0), * Pminus = seg.ReadSingle(1), * Qplus = seg.ReadSingle(2), * Qminus = seg.ReadSingle(3), * }, * Index = seg.ReadUInt16(0 + (4 * sizeof(Single))) * }; * result = OperationResult.Good; * } * catch (Exception e) * { * result = OperationResult.From(e); * } * return result; * }*/ #endregion #region Энергия /// <summary>Прочитать показание счетчиков</summary> public OperationResult TryReadCounter( IIODriverClient channel, string psw, TypeInc typeInc, RequestIndex request, ETariff tariff, out Energy response) { response = null; ushort action; byte[] arr; OperationResult result = new OperationResult(Quality.BadNoRestore, "Превышение глубины опроса"); if (typeInc == TypeInc.Day) { if ((request.Index > Emera3Request.DepthDayCounter) || (request.Index > 45)) { return(result); } if (tariff == ETariff.NoTariff) { action = Codes.CODE_READ_ENERGY_DAY_SUM; arr = new byte[1]; arr[0] = request.Index; } else { action = Codes.CODE_READ_ENERGY_DAY_TARIFF; arr = new byte[2]; arr[0] = (byte)(tariff - 1); arr[1] = request.Index; } } else if (typeInc == TypeInc.Month) { if ((request.Index > Emera3Request.DepthMonthCounter) || (request.Index > 13)) { return(result); } if (tariff == ETariff.NoTariff) { action = Codes.CODE_READ_ENERGY_MONTH_SUM; arr = new byte[1]; arr[0] = request.Index; } else { action = Codes.CODE_READ_ENERGY_MONTH_TARIFF; arr = new byte[2]; arr[0] = (byte)(tariff - 1); arr[1] = request.Index; } } else { return(OperationResult.Bad); } var send = CreateRequest(request.Address, action, psw, arr); result = WriteReadCheck(channel, nRepeatGlobal, send, out byte[] answer); if (!result.IsGood) { return(result); } var seg = new ByteArraySegment(answer, 0, answer.Length); try { response = new Energy(seg.ReadUInt32(0), 0, 0, 0); result = OperationResult.Good; } catch (Exception e) { result = OperationResult.From(e); } return(result); }
/// <summary> /// Чтение приращений (показаний) /// </summary> /// <param name="fromTime"></param> /// <param name="typeQuery"></param> /// <param name="typeInc"></param> /// <param name="aplus"></param> /// <param name="aminus"></param> /// <param name="rplus"></param> /// <param name="rminus"></param> /// <param name="depth"></param> /// <param name="deepSyncTime"></param> /// <param name="tariff"> /// Добавлена поддержка чтения тарифов для показаний, т.к. эту величину нельзя расчитать. /// </param> static internal void ReadInc( QueryInfo info, DateTimeZone fromTime, TypeQuery typeQuery, TypeInc typeInc, TagDef aplus, TagDef aminus, TagDef rplus, TagDef rminus, int depth, DateTimeUtc deepSyncTime, ETariff tariff = ETariff.NoTariff) { //Если в гране нет данных то дальше этой даты записываем что нельзя востонавить bool fillBadNoRestore = false; int itemNum = 0; OperationResult oper = new OperationResult(Quality.Bad); var holes = info.GetHoles(typeInc, fromTime, depth, deepSyncTime, new[] { aplus }); var reversedHoles = holes.Reverse(); foreach (var item in reversedHoles) { itemNum++; Energy read = null; OperationResult res = OperationResult.Bad; if (fillBadNoRestore) { read = new Energy(0, 0, 0, 0); oper = new OperationResult(Quality.BadNoRestore); } else if (info.Session.BeginOperation()) { if (DataBusSetting.StubData) //STUBDATA-> { read = new Energy(StubUtil.Int32(500), StubUtil.Int32(600), StubUtil.Int32(700), StubUtil.Int32(800)); oper = new OperationResult(Quality.Good); } else { switch (typeQuery) { #region (case TypeQuery.SlicesEnergy:) case TypeQuery.SlicesEnergy: if (!info.IsHalfHourInterval) { oper = new OperationResult(Quality.Bad, "HalfHour Interval is incorrect!"); } else { // только для версий СЕ102 S7, R8, CE301M S31, R33 // версии CE102 S6, R5 не поддерживают архив получасов oper = info.Request.TryReadSlicesEnergy( info.DataBus, info.Cs.Psw, info.Session.TimeDevice, SlicesQuery.From(item, info.Cs.Address), out read); read.Calc(info.DeviceKoef); } break; #endregion #region (case TypeQuery.Counter:) case TypeQuery.Counter: oper = info.Request.TryReadCounter( info.DataBus, info.Cs.Psw, typeInc, RequestIndex.From(item, typeInc, info.Cs.Address, true), tariff, out read); read.Calc(info.DeviceKoef); break; #endregion /*#region (case TypeQuery.Power3min:) * case TypeQuery.Power3min: * AvPowerIndex pi; * oper = info.Request.TryReadAvPower3min( * info.DataBus, * info.Session.TimeDevice, * info.Session.Zone, * RequestIndex.From(item, typeInc, info.Cs.Address, false), * item, * out pi); * if (oper.IsGood) * read = pi.Power.ToEnergy(20); * break; #endregion*/ } //Может возникать ситуация когда на компе уже наступило время опроса а на счетчике нет и будет возвращен блок поврежден //TODO if ((itemNum < 3) && (oper.Quality == Quality.BadNoRestore)) oper.Quality = Quality.Bad; } /*if ((!oper.IsGood) && (oper.Code == 2)) * { * if (info.Session.OpenData.NewDevice != ChangeDeviceInfo.None) * info.LogWarn(SR.NOT_PARAM, info.DisplayName, aplus.AccountKind, aplus.Discrete, aplus.DiscreteValue); * info.Session.EndOperation(OperationResult.Good); * break; //Неизвестная функция не подерживаемая версией устройства * }*/ info.Session.EndOperation(oper); if (!oper.IsGood) { read = new Energy(0, 0, 0, 0); info.DataBus.DiscardInBuffer(); } if (oper.Quality == Quality.BadNoRestore) { fillBadNoRestore = true; //заполним все полохими не востанавливаемыми } } else { break; } info.Storage.WriteTagsValue( HW(oper.Quality, read.Aplus, item, aplus), HW(Quality.Bad, read.Aminus, item, aminus), HW(Quality.Bad, read.Rplus, item, rplus), HW(Quality.Bad, read.Rminus, item, rminus)); if (info.Log.Trace.IsOn(2)) { var sb = new StringBuilder(); sb.AppendFormat("Read from [{0}] {1} {2}", item, typeInc, oper.Quality); if (typeQuery != TypeQuery.SlicesEnergy) { sb.Append(" " + typeQuery); } if (!oper.IsGood) { sb.AppendFormat(". Error: {0}", oper.ErrorMsg); info.Log.Trace.Error(2, sb.ToString()); } else { sb.AppendFormat(". A+: {0}, A-: {1}, R+: {2}, R-: {3}", read.Aplus, read.Aminus, read.Rplus, read.Rminus); info.Log.Trace.Info(2, sb.ToString()); } } } }