Exemple #1
0
        public ModbusAdapter()
        {
            TagsChanged = new Dictionary <string, bool>();
            TagsSending = new Dictionary <string, bool>();
            T tags = new T();

            ActionRead  = this.ParserRead;
            ActionWrite = this.ParserWrite;
            Type typ = typeof(T).GetNestedType("Registers") ?? typeof(T).BaseType.GetNestedType("Registers");

            foreach (FieldInfo Register in typ.GetFields(BindingFlags.Public | BindingFlags.Static))
            {
                try
                {
                    int Address = int.Parse(Register.GetValue(null).ToString());
                    Addresses.Add(Register.Name, Address);
                    FieldInfo tag = tags.GetType().GetField(Register.Name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
                    if (tag != null)
                    {
                        int len = tag.GetValue(tags) is Array ? (tag.GetValue(tags) as Array).Length : 1;
                        TagsSize.Add(tag.Name, len);
                        for (int i = 0; i < len; i++)
                        {
                            TagsSending.Add(Address + ":" + i, false);
                            TagsChanged.Add(Address + ":" + i, false);
                        }
                    }
                }
                catch (Exception e)
                {
                    System.Windows.MessageBox.Show(e.Message + ", " + Register.Name + ":" + int.Parse(Register.GetValue(null).ToString()));
                    return;
                }
            }


            if (typeof(T).GetNestedType("Precisions") != null)
            {
                foreach (FieldInfo Precision in typeof(T).GetNestedType("Precisions").GetFields(BindingFlags.Public | BindingFlags.Static))
                {
                    Object Value = Precision.GetValue(null);
                    if (Value != null)
                    {
                        if (Value is Array)
                        {
                            Array arr = Value as Array;
                            for (int i = 0; i < arr.Length; i++)
                            {
                                Precisions.Add(Precision.Name + ":" + i, arr.GetValue(i));
                            }
                        }
                        else
                        {
                            Precisions.Add(Precision.Name + ":0", Value);
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void Update(EvaluationContext context)
        {
            var v    = Value.GetValue(context);
            var test = TestValue.GetValue(context);

            //var mod = Mod.GetValue(context);
            switch ((Modes)Mode.GetValue(context))
            {
            case Modes.IsSmaller:
                IsTrue.Value = v < test;
                break;

            case Modes.IsEqual:
                IsTrue.Value = Math.Abs(v - test) < Precision.GetValue(context);
                break;

            case Modes.IsLarger:
                IsTrue.Value = v > test;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }