Beispiel #1
0
        static internal OperationData <bool> WriteDateTime(DeviceCompOn diff, QueryInfo info)
        {
            if (DataBusSetting.StubData)
            {
                return(StubUtil.StubOnWriteDateTime());
            }
            var res = info.Request.TryWriteDateDate(
                info.DataBus,
                info.Cs.Address,
                info.Cs.Psw,
                info.NextPoint.Zone,
                diff);

            return(new OperationData <bool>(res.IsGood, res));
        }
Beispiel #2
0
        /// <summary>Показание счетчика с момента запуска</summary>

        /*private OperationResult TryReadEnergyFromLaunch(IIODriverClient channel, ShortRequest request, out Energy response)
         * {
         *  return TryReadEnergy(channel, request, Codes.CODE_TOTAL, 0, 0, 0, out response);
         * }*/
        #endregion

        #region Энергия по времени

        /// <summary>Чтение 30 минутных срезов энергии</summary>
        /// <param name="channel">Канал</param>
        /// <param name="request">Запрос</param>
        /// <param name="timeSlices">Время среза должно быть точное и выравненне</param>
        public OperationResult TryReadSlicesEnergy(IIODriverClient channel, string psw, DeviceCompOn deviceTime, SlicesQuery request, out Energy response)
        {
            response = Energy.Default;
            //log.Trace.Write(1, (l) => l.Info("Emul: {0}", request.EmulError));
            if (!request.EmulError)
            {
                //log.Trace.Write(1, (l) => l.Info("DiffMsec: {0}, DiffMsecReal: {1}, DeviceTimeUtc: {2}, IsTimeSlices: {3}, TimeOneSidePathMsec: {4}, TimeSlices: {5}",
                //  deviceTime.DiffMsec, deviceTime.DiffMsecReal, deviceTime.GetDeviceTimeUtc(),
                //  deviceTime.IsItTime(request.GetTimeSlicesFrom30()), deviceTime.TimeOneSidePathMsec, request.GetTimeSlicesFrom30()));
                if (!deviceTime.IsItTime(request.GetTimeSlicesFrom30().AddSeconds(10)))
                {
                    return(new OperationResult(Quality.Bad, "Time has not yet come"));
                }
            }

            OperationResult result;

            try
            {
                byte[] arr = new byte[5];
                arr[0] = BitwiseUtils.DecToBCD(request.Day);
                arr[1] = BitwiseUtils.DecToBCD(request.Month);
                arr[2] = BitwiseUtils.DecToBCD((byte)(request.TimeSlices.Year - 2000));
                arr[3] = request.Index;
                arr[4] = 1;

                var send = CreateRequest(request.Address, Codes.CODE_READ_ENERGY_INTERVAL, psw, arr);
                result = WriteReadCheck(channel, nRepeatGlobal, send, out byte[] answer);

                Array.Resize <byte>(ref answer, 4);
                var seg   = new ByteArraySegment(answer, 0, answer.Length);
                var value = seg.ReadUInt32(0);
                if (value == 0xFFFFFF)
                {
                    response = new Energy(0, 0, 0, 0); //это значит что его нет в памяти и надо возвращать нули
                    return(OperationResult.Bad);
                }
                response = new Energy(value, 0, 0, 0);
                result   = OperationResult.Good;
            }
            catch (Exception e)
            {
                result = OperationResult.From(e);
            }
            return(result);
        }
Beispiel #3
0
        public OperationResult TryWriteDateDate(IIODriverClient channel, int address, string psw, TimeZoneMap map, DeviceCompOn diff)
        {
            // Установка даты и времени защищена основным паролем.

            OperationResult result = WaitRequest(channel);

            if (!result.IsGood)
            {
                return(result);
            }

            DateTimeZone dateTime = diff.GetServerToDeviceTime(map);

            byte[] arr = new byte[7];
            arr[0] = BitwiseUtils.DecToBCD((byte)dateTime.Second);
            arr[1] = BitwiseUtils.DecToBCD((byte)dateTime.Minute);
            arr[2] = BitwiseUtils.DecToBCD((byte)dateTime.Hour);
            arr[3] = (byte)dateTime.DayOfWeek;
            arr[4] = BitwiseUtils.DecToBCD((byte)dateTime.Day);
            arr[5] = BitwiseUtils.DecToBCD((byte)dateTime.Month);
            arr[6] = BitwiseUtils.DecToBCD((byte)(dateTime.Year - 2000));

            try
            {
                var send = CreateRequest(address, Codes.CODE_WRITE_DATETIME, psw, arr);
                result = WriteReadCheck(channel, nRepeatGlobal, send, out byte[] answer);
            }
            catch (Exception e)
            {
                result = OperationResult.From(e);
            }
            return(result);
        }