Ejemplo n.º 1
0
        public Parameter GetClone()
        {
            var clone = new Parameter()
            {
                Name = this.Name,
                ObisCode = this.ObisCode,
                TargetValue = this.TargetValue,
                TagId = this.TagId,
                IsActive = this.IsActive,
                IsAutoIncrement = this.IsAutoIncrement,
                IsPartOfMatrixCode = this.IsPartOfMatrixCode,
                IsWriteOnly = this.IsWriteOnly,
                IsReadOnly = this.IsReadOnly,
                IsNameplateOnly = this.IsNameplateOnly,
                IsRandomTargetValue = this.IsRandomTargetValue,
                ModifiedAt = new DateTime(1900, 1, 1),
                CreatedAt = DateTime.Now
            };

            return clone;
        }
Ejemplo n.º 2
0
 private static void RandomizeTargetValue(Parameter clone)
 {
     var rnd = new Random();
     clone.TargetValue = string.Format("{0}", rnd.Next(1, 9999));
 }
Ejemplo n.º 3
0
        private static void IncrementTargetValue(Parameter clone)
        {
            if (clone.TagId == ParameterTagId.ServerId)
            {
                var bytesStr = clone.TargetValue.Split('-');
                var bytes = bytesStr.Reverse().Take(4).Select(s => Convert.ToByte(s, 16)).ToArray();
                var val = BitConverter.ToInt32(bytes, 0);
                val++;
                bytes = BitConverter.GetBytes(val).Reverse().ToArray();
                bytesStr[bytesStr.Length - 1] = string.Format("{0:X2}", bytes[3]);
                bytesStr[bytesStr.Length - 2] = string.Format("{0:X2}", bytes[2]);
                bytesStr[bytesStr.Length - 3] = string.Format("{0:X2}", bytes[1]);
                bytesStr[bytesStr.Length - 4] = string.Format("{0:X2}", bytes[0]);

                clone.TargetValue = string.Join("-", bytesStr);
            }
            else
            {
                long tmp;
                if (long.TryParse(clone.TargetValue, out tmp))
                {
                    tmp++;
                    clone.TargetValue = string.Format("{0:D4}", tmp);
                }
            }
        }
        private static void ReadSignature(string comPort, Parameter p)
        {
            CheckInit();

            var sb = new StringBuilder();
            var success = false;

            try
            {
                // EdlLastAplusSignature
                var signedRegister = Proxy.ReadEnergyRegister(guid, GetPort(comPort), 0x100011100FF);
                sb.AppendFormat("OBIS: {0:X12}\n", signedRegister.ObisValue);
                sb.AppendFormat("VALUE: {0}\n", signedRegister.DataValue);
                sb.AppendFormat("UNIT: {0}\n", signedRegister.Unit);
                sb.AppendFormat("STATUS: {0}\n", signedRegister.StatusWord);
                sb.AppendFormat("TIME: {0}\n", signedRegister.ValueTime);
                sb.AppendFormat("SIG: {0}", HexUtil.ByteArrayToString(signedRegister.ValueSignature));

                success = true;
            }
            catch (Exception e)
            {
                sb.Append(e.Message);
            }

            if (!success)
            {
                try
                {
                    // EdlLastAminusSignature = 1099546296575,
                    var signedRegister = Proxy.ReadEnergyRegister(guid, GetPort(comPort), 0x100021100FF);
                    sb.Clear();
                    sb.AppendFormat("OBIS: {0:X12}\n", signedRegister.ObisValue);
                    sb.AppendFormat("VALUE: {0}\n", signedRegister.DataValue);
                    sb.AppendFormat("UNIT: {0}\n", signedRegister.Unit);
                    sb.AppendFormat("STATUS: {0}\n", signedRegister.StatusWord);
                    sb.AppendFormat("TIME: {0}\n", signedRegister.ValueTime);
                    sb.AppendFormat("SIG: {0}", HexUtil.ByteArrayToString(signedRegister.ValueSignature));

                    success = true;
                }
                catch (Exception e)
                {
                    sb.Append(e.Message);
                }
            }

            // enable EDL21 mode again
            try
            {
                Proxy.WriteIsOperationModeEdl40(guid, GetPort(comPort), false);
            }
            catch (Exception ex)
            {
                Log.ErrorException("Re-enabling of EDL21 mode failed.", ex);
            }

            p.RealValue = (success ? "SUCCESS: " : "FAILED: ") + sb.ToString();
        }